#include <cyad/CommandsDispatcher.h>
#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;
dispatcher.execute(result);
}
-TEST_F(CyadCommandlineDispatcherTest, setBucket) {
+TEST_F(CyadCommandlineDispatcherTest, setBucketPositive) {
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
addDescriptions({ { 42, "hitchhiker" } });
- Cynara::CommandsDispatcher dispatcher(m_io, m_adminApi, m_errorApi);
-
typedef std::string RawPolicyType;
typedef std::string Metadata;
typedef std::tuple<PolicyBucketId, PolicyType, RawPolicyType, Metadata> BucketData;
+
typedef std::vector<BucketData> 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);
}
}
-TEST_F(CyadCommandlineDispatcherTest, setPolicy) {
+TEST_F(CyadCommandlineDispatcherTest, setPolicyPositive) {
using ::testing::_;
using ::testing::Return;
dispatcher.execute(result);
}
-TEST_F(CyadCommandlineDispatcherTest, setPolicyWithMetadata) {
+TEST_F(CyadCommandlineDispatcherTest, setPolicyWithMetadataPositive) {
using ::testing::_;
using ::testing::Return;
dispatcher.execute(result);
}
-TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk1) {
+TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk1Positive) {
using ::testing::_;
using ::testing::Return;
}
// 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;
}
// same as setPoliciesBulk1 but with additional empty lines
-TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulk3) {
+TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkEmptyLinesPositive) {
using ::testing::_;
using ::testing::Return;
dispatcher.execute(result);
}
-TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkInputError) {
+TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkInputErrorNegative) {
using ::testing::_;
using ::testing::Return;
ASSERT_FALSE(m_io.cerrRaw().str().empty());
}
-TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkFileError) {
+TEST_F(CyadCommandlineDispatcherTest, setPoliciesBulkFileErrorNegative) {
using ::testing::_;
using ::testing::Return;
ASSERT_FALSE(m_io.cerrRaw().str().empty());
}
-TEST_F(CyadCommandlineDispatcherTest, erase) {
+TEST_F(CyadCommandlineDispatcherTest, erasePositive) {
using ::testing::_;
using ::testing::Return;
using ::testing::StrEq;
dispatcher.execute(command);
}
-TEST_F(CyadCommandlineDispatcherTest, check) {
+TEST_F(CyadCommandlineDispatcherTest, checkPositive) {
using ::testing::_;
using ::testing::DoAll;
using ::testing::NotNull;
ASSERT_EQ("42;\n", m_io.coutRaw().str());
}
-TEST_F(CyadCommandlineDispatcherTest, checkWithMetadata) {
+TEST_F(CyadCommandlineDispatcherTest, checkWithMetadataPositive) {
using ::testing::_;
using ::testing::DoAll;
using ::testing::NotNull;
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;
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;
ASSERT_EQ("", m_io.coutRaw().str());
}
-TEST_F(CyadCommandlineDispatcherTest, listPoliciesTwo) {
+TEST_F(CyadCommandlineDispatcherTest, listPoliciesTwoPositive) {
using ::testing::_;
using ::testing::DoAll;
using ::testing::NotNull;
m_io.coutRaw().str());
}
-TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypes) {
+TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesPositive) {
using ::testing::_;
using ::testing::DoAll;
using ::testing::NotNull;
m_io.coutRaw().str());
}
-TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesHumanize) {
+TEST_F(CyadCommandlineDispatcherTest, listPoliciesAllSimpleTypesHumanizePositive) {
using ::testing::_;
using ::testing::DoAll;
using ::testing::NotNull;
m_io.coutRaw().str());
}
-TEST_F(CyadCommandlineDispatcherTest, listPoliciesDesc) {
+TEST_F(CyadCommandlineDispatcherTest, listPoliciesDescPositive) {
using ::testing::_;
using ::testing::DoAll;
using ::testing::NotNull;