diff options
author | yang-g <yangg@google.com> | 2016-02-19 00:04:22 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2016-02-19 00:04:22 -0800 |
commit | 17197ddc714d5268a6b1fca678ac8b94ed74f3bd (patch) | |
tree | 0d46505693ba974291f60c352a1c52f123132a5e /test | |
parent | 5152cd29f8541d7600b7ddc3d9db188ad59ea673 (diff) |
Revert "make an enum"
This reverts commit 5152cd29f8541d7600b7ddc3d9db188ad59ea673.
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp/end2end/end2end_test.cc | 62 | ||||
-rw-r--r-- | test/cpp/util/test_credentials_provider.cc | 28 | ||||
-rw-r--r-- | test/cpp/util/test_credentials_provider.h | 13 |
3 files changed, 34 insertions, 69 deletions
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 2169afb816..df9aae7436 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -191,14 +191,14 @@ class TestServiceImplDupPkg class TestScenario { public: - TestScenario(bool proxy, TestCredentialsType type) - : use_proxy(proxy), credentials_type(type) {} + TestScenario(bool proxy, const grpc::string& creds_type) + : use_proxy(proxy), credentials_type(creds_type) {} void Log() const { gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy, - TestCredentialsTypeToString(credentials_type).c_str()); + credentials_type.c_str()); } bool use_proxy; - TestCredentialsType credentials_type; + const grpc::string credentials_type; }; class End2endTest : public ::testing::TestWithParam<TestScenario> { @@ -223,7 +223,7 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> { // Setup server ServerBuilder builder; auto server_creds = GetServerCredentials(GetParam().credentials_type); - if (GetParam().credentials_type != INSECURE_CREDENTIALS) { + if (GetParam().credentials_type != kInsecureCredentialsType) { server_creds->SetAuthMetadataProcessor(processor); } builder.AddListeningPort(server_address_.str(), server_creds); @@ -933,7 +933,7 @@ TEST_P(End2endTest, ChannelState) { // Takes 10s. TEST_P(End2endTest, ChannelStateTimeout) { - if (GetParam().credentials_type != INSECURE_CREDENTIALS) { + if (GetParam().credentials_type != kInsecureCredentialsType) { return; } int port = grpc_pick_unused_port_or_die(); @@ -1142,7 +1142,7 @@ class SecureEnd2endTest : public End2endTest { protected: SecureEnd2endTest() { GPR_ASSERT(!GetParam().use_proxy); - GPR_ASSERT(GetParam().credentials_type != INSECURE_CREDENTIALS); + GPR_ASSERT(GetParam().credentials_type != kInsecureCredentialsType); } }; @@ -1365,43 +1365,25 @@ TEST_P(SecureEnd2endTest, ClientAuthContext) { EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2])); } -std::vector<TestScenario> CreateTestScenarios(bool use_proxy, - bool test_insecure, - bool test_secure) { - std::vector<TestScenario> scenarios; - for (int i = INSECURE_CREDENTIALS; i < MAX_CREDENTIALS_TYPE; i++) { - if (i == INSECURE_CREDENTIALS && !test_insecure) { - continue; - } - if (i != INSECURE_CREDENTIALS && !test_secure) { - continue; - } - if (use_proxy) { - scenarios.push_back( - TestScenario(true, static_cast<TestCredentialsType>(i))); - } - scenarios.push_back( - TestScenario(false, static_cast<TestCredentialsType>(i))); - } - GPR_ASSERT(!scenarios.empty()); - return scenarios; -} - -INSTANTIATE_TEST_CASE_P(End2end, End2endTest, - ::testing::ValuesIn(CreateTestScenarios(false, true, - true))); +INSTANTIATE_TEST_CASE_P( + End2end, End2endTest, + ::testing::Values(TestScenario(false, kInsecureCredentialsType), + TestScenario(false, kTlsCredentialsType))); -INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest, - ::testing::ValuesIn(CreateTestScenarios(false, true, - false))); +INSTANTIATE_TEST_CASE_P( + End2endServerTryCancel, End2endServerTryCancelTest, + ::testing::Values(TestScenario(false, kInsecureCredentialsType))); -INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest, - ::testing::ValuesIn(CreateTestScenarios(true, true, - true))); +INSTANTIATE_TEST_CASE_P( + ProxyEnd2end, ProxyEnd2endTest, + ::testing::Values(TestScenario(false, kInsecureCredentialsType), + TestScenario(false, kTlsCredentialsType), + TestScenario(true, kInsecureCredentialsType), + TestScenario(true, kTlsCredentialsType))); INSTANTIATE_TEST_CASE_P(SecureEnd2end, SecureEnd2endTest, - ::testing::ValuesIn(CreateTestScenarios(false, false, - true))); + ::testing::Values(TestScenario(false, + kTlsCredentialsType))); } // namespace } // namespace testing diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc index 9746ca692a..f8380cdb65 100644 --- a/test/cpp/util/test_credentials_provider.cc +++ b/test/cpp/util/test_credentials_provider.cc @@ -40,24 +40,24 @@ namespace grpc { namespace testing { std::shared_ptr<ChannelCredentials> GetChannelCredentials( - TestCredentialsType type, ChannelArguments* args) { - if (type == INSECURE_CREDENTIALS) { + const grpc::string& type, ChannelArguments* args) { + if (type == kInsecureCredentialsType) { return InsecureChannelCredentials(); - } else if (type == TLS_CREDENTIALS) { + } else if (type == kTlsCredentialsType) { SslCredentialsOptions ssl_opts = {test_root_cert, "", ""}; args->SetSslTargetNameOverride("foo.test.google.fr"); return SslCredentials(ssl_opts); } else { - gpr_log(GPR_ERROR, "Unsupported credentials type %d.", type); + gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); } return nullptr; } std::shared_ptr<ServerCredentials> GetServerCredentials( - TestCredentialsType type) { - if (type == INSECURE_CREDENTIALS) { + const grpc::string& type) { + if (type == kInsecureCredentialsType) { return InsecureServerCredentials(); - } else if (type == TLS_CREDENTIALS) { + } else if (type == kTlsCredentialsType) { SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, test_server1_cert}; SslServerCredentialsOptions ssl_opts; @@ -65,22 +65,10 @@ std::shared_ptr<ServerCredentials> GetServerCredentials( ssl_opts.pem_key_cert_pairs.push_back(pkcp); return SslServerCredentials(ssl_opts); } else { - gpr_log(GPR_ERROR, "Unsupported credentials type %d.", type); + gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); } return nullptr; } -grpc::string TestCredentialsTypeToString(TestCredentialsType type) { - switch (type) { - case INSECURE_CREDENTIALS: - return "INSECURE_CREDENTIALS"; - case TLS_CREDENTIALS: - return "TLS_CREDENTIALS"; - default: - break; - } - return "UNKNOWN"; -} - } // namespace testing } // namespace grpc diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h index 005254a652..4f25e3be66 100644 --- a/test/cpp/util/test_credentials_provider.h +++ b/test/cpp/util/test_credentials_provider.h @@ -43,22 +43,17 @@ namespace grpc { namespace testing { -enum TestCredentialsType { - INSECURE_CREDENTIALS = 0, - TLS_CREDENTIALS, - MAX_CREDENTIALS_TYPE -}; +const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS"; +const char kTlsCredentialsType[] = "TLS_CREDENTIALS"; // Provide channel credentials according to the given type. Alter the channel // arguments if needed. std::shared_ptr<ChannelCredentials> GetChannelCredentials( - TestCredentialsType type, ChannelArguments* args); + const grpc::string& type, ChannelArguments* args); // Provide server credentials according to the given type. std::shared_ptr<ServerCredentials> GetServerCredentials( - TestCredentialsType type); - -grpc::string TestCredentialsTypeToString(TestCredentialsType type); + const grpc::string& type); } // namespace testing } // namespace grpc |