From: Zofia Abramowska Date: Mon, 3 Aug 2020 10:41:33 +0000 (+0200) Subject: Redo cyad commands dispatcher unit tests X-Git-Tag: submit/tizen/20210324.154641~23 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aa55fac3b784de958a96861193e5390e1550f841;p=platform%2Fcore%2Fsecurity%2Fcynara.git Redo cyad commands dispatcher unit tests * Minor refactorin * Categorize into positive/negative test cases Change-Id: Ib449c1b76863d84cda543db752d965a1b5abbf05 --- diff --git a/test/cyad/commands_dispatcher.cpp b/test/cyad/commands_dispatcher.cpp index ef178c67..cc3935f8 100644 --- a/test/cyad/commands_dispatcher.cpp +++ b/test/cyad/commands_dispatcher.cpp @@ -45,30 +45,41 @@ #include #include "CyadCommandlineDispatcherTest.h" +#include "TestDataCollection.h" #include "helpers.h" +using namespace TestDataCollection; + /** * @brief Dispatcher should not touch admin API on help or error * @test Scenario: * - Prepare some parsing results not requiring API calls * - Check if no API calls were made */ -TEST_F(CyadCommandlineDispatcherTest, noApi) { +TEST_F(CyadCommandlineDispatcherTest, helpPositive) { + using ::testing::_; + using ::testing::Return; + + Cynara::CommandsDispatcher dispatcher(m_io, m_adminApi, m_errorApi); + + Cynara::ErrorCyadCommand errorResult("Fake error"); + + dispatcher.execute(errorResult); +} + +TEST_F(CyadCommandlineDispatcherTest, errorNegative) { using ::testing::_; using ::testing::Return; Cynara::CommandsDispatcher dispatcher(m_io, m_adminApi, m_errorApi); - Cynara::CyadCommand result; - Cynara::HelpCyadCommand helpResult; Cynara::ErrorCyadCommand errorResult("Fake error"); - dispatcher.execute(result); - dispatcher.execute(helpResult); dispatcher.execute(errorResult); } -TEST_F(CyadCommandlineDispatcherTest, deleteBucket) { + +TEST_F(CyadCommandlineDispatcherTest, deleteBucketPositive) { using ::testing::_; using ::testing::Return; using ::testing::StrEq; @@ -84,7 +95,7 @@ TEST_F(CyadCommandlineDispatcherTest, deleteBucket) { dispatcher.execute(result); } -TEST_F(CyadCommandlineDispatcherTest, setBucket) { +TEST_F(CyadCommandlineDispatcherTest, setBucketPositive) { using ::testing::_; using ::testing::Return; using ::testing::StrEq; @@ -96,24 +107,26 @@ TEST_F(CyadCommandlineDispatcherTest, setBucket) { addDescriptions({ { 42, "hitchhiker" } }); - Cynara::CommandsDispatcher dispatcher(m_io, m_adminApi, m_errorApi); - typedef std::string RawPolicyType; typedef std::string Metadata; typedef std::tuple BucketData; + typedef std::vector Buckets; const Buckets buckets = { - BucketData("test-bucket-1", CYNARA_ADMIN_ALLOW, "ALLOW", ""), - BucketData("test-bucket-2", CYNARA_ADMIN_DENY, "DENY", ""), - BucketData("test-bucket-3", CYNARA_ADMIN_BUCKET, "BUCKET", "other-bucket"), - BucketData("test-bucket-2", CYNARA_ADMIN_NONE, "NONE", ""), - BucketData("test-bucket-4", 42, "hitchhiker", "douglas-noel-adams") }; - - for (const auto &bucket : buckets) { - const auto &bucketId = std::get<0>(bucket); - const auto &policyType = std::get<1>(bucket); - const auto &rawPolicyType = std::get<2>(bucket); - const auto &metadata = std::get<3>(bucket); + {"test-bucket-1", CYNARA_ADMIN_ALLOW, "ALLOW", ""}, + {"test-bucket-2", CYNARA_ADMIN_DENY, "DENY", ""}, + {"test-bucket-3", CYNARA_ADMIN_BUCKET, "BUCKET", "other-bucket"}, + {"test-bucket-2", CYNARA_ADMIN_NONE, "NONE", ""}, + {"test-bucket-4", 42, "hitchhiker", "douglas-noel-adams"} + }; + + Cynara::CommandsDispatcher dispatcher(m_io, m_adminApi, m_errorApi); + + for (auto &bucket : buckets) { + auto &bucketId = std::get<0>(bucket); + auto &policyType = std::get<1>(bucket); + auto &rawPolicyType = std::get<2>(bucket); + auto &metadata = std::get<3>(bucket); SCOPED_TRACE(bucketId); @@ -134,7 +147,7 @@ TEST_F(CyadCommandlineDispatcherTest, setBucket) { } } -TEST_F(CyadCommandlineDispatcherTest, setPolicy) { +TEST_F(CyadCommandlineDispatcherTest, setPolicyPositive) { using ::testing::_; using ::testing::Return; @@ -153,7 +166,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPolicy) { dispatcher.execute(result); } -TEST_F(CyadCommandlineDispatcherTest, setPolicyWithMetadata) { +TEST_F(CyadCommandlineDispatcherTest, setPolicyWithMetadataPositive) { using ::testing::_; using ::testing::Return; @@ -172,7 +185,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPolicyWithMetadata) { dispatcher.execute(result); } -TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk1) { +TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk1Positive) { using ::testing::_; using ::testing::Return; @@ -197,7 +210,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk1) { } // same as setPoliciesBulk1 but with additional endl at the end of file -TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk2) { +TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkEndNewLinePositive) { using ::testing::_; using ::testing::Return; @@ -222,7 +235,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk2) { } // same as setPoliciesBulk1 but with additional empty lines -TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk3) { +TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkEmptyLinesPositive) { using ::testing::_; using ::testing::Return; @@ -249,7 +262,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk3) { dispatcher.execute(result); } -TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkInputError) { +TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkInputErrorNegative) { using ::testing::_; using ::testing::Return; @@ -264,7 +277,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkInputError) { ASSERT_FALSE(m_io.cerrRaw().str().empty()); } -TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkFileError) { +TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkFileErrorNegative) { using ::testing::_; using ::testing::Return; @@ -279,7 +292,7 @@ TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkFileError) { ASSERT_FALSE(m_io.cerrRaw().str().empty()); } -TEST_F(CyadCommandlineDispatcherTest, erase) { +TEST_F(CyadCommandlineDispatcherTest, erasePositive) { using ::testing::_; using ::testing::Return; using ::testing::StrEq; @@ -295,7 +308,7 @@ TEST_F(CyadCommandlineDispatcherTest, erase) { dispatcher.execute(command); } -TEST_F(CyadCommandlineDispatcherTest, check) { +TEST_F(CyadCommandlineDispatcherTest, checkPositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull; @@ -318,7 +331,7 @@ TEST_F(CyadCommandlineDispatcherTest, check) { ASSERT_EQ("42;\n", m_io.coutRaw().str()); } -TEST_F(CyadCommandlineDispatcherTest, checkWithMetadata) { +TEST_F(CyadCommandlineDispatcherTest, checkWithMetadataPositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull; @@ -342,7 +355,7 @@ TEST_F(CyadCommandlineDispatcherTest, checkWithMetadata) { ASSERT_EQ("42;adams\n", m_io.coutRaw().str()); } -TEST_F(CyadCommandlineDispatcherTest, checkWithError) { +TEST_F(CyadCommandlineDispatcherTest, checkReturnErrorNegative) { using ::testing::_; using ::testing::DoAll; using ::testing::HasSubstr; @@ -373,7 +386,7 @@ TEST_F(CyadCommandlineDispatcherTest, checkWithError) { ASSERT_THAT(m_io.cerrRaw().str(), HasSubstr("Test error message")); } -TEST_F(CyadCommandlineDispatcherTest, listPoliciesNone) { +TEST_F(CyadCommandlineDispatcherTest, listPoliciesNonePositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull; @@ -398,7 +411,7 @@ TEST_F(CyadCommandlineDispatcherTest, listPoliciesNone) { ASSERT_EQ("", m_io.coutRaw().str()); } -TEST_F(CyadCommandlineDispatcherTest, listPoliciesTwo) { +TEST_F(CyadCommandlineDispatcherTest, listPoliciesTwoPositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull; @@ -426,7 +439,7 @@ TEST_F(CyadCommandlineDispatcherTest, listPoliciesTwo) { m_io.coutRaw().str()); } -TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypes) { +TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesPositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull; @@ -457,7 +470,7 @@ TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypes) { m_io.coutRaw().str()); } -TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesHumanize) { +TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesHumanizePositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull; @@ -488,7 +501,7 @@ TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesHumanize) { m_io.coutRaw().str()); } -TEST_F(CyadCommandlineDispatcherTest, listPoliciesDesc) { +TEST_F(CyadCommandlineDispatcherTest, listPoliciesDescPositive) { using ::testing::_; using ::testing::DoAll; using ::testing::NotNull;