Fix xds_bootstrap_test to actually run and fix bugs in it.

pull/20606/head
Mark D. Roth 5 years ago
parent 9a276c07fa
commit 621ea6534d
  1. 4
      src/core/ext/filters/client_channel/xds/xds_bootstrap.cc
  2. 3
      test/core/client_channel/BUILD
  3. 50
      test/core/client_channel/xds_bootstrap_test.cc

@ -124,7 +124,7 @@ grpc_error* XdsBootstrap::ParseXdsServer(grpc_json* json) {
} else if (strcmp(child->key, "channel_creds") == 0) {
if (child->type != GRPC_JSON_ARRAY) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"\"channel_creds\" field is not a array"));
"\"channel_creds\" field is not an array"));
}
if (seen_channel_creds) {
error_list.push_back(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
@ -205,7 +205,6 @@ grpc_error* XdsBootstrap::ParseChannelCreds(grpc_json* json, size_t idx) {
gpr_free(msg);
for (size_t i = 0; i < error_list.size(); ++i) {
error = grpc_error_add_child(error, error_list[i]);
GRPC_ERROR_UNREF(error_list[i]);
}
return error;
}
@ -418,7 +417,6 @@ grpc_error* XdsBootstrap::ParseMetadataValue(grpc_json* json, size_t idx,
gpr_free(msg);
for (size_t i = 0; i < error_list.size(); ++i) {
error = grpc_error_add_child(error, error_list[i]);
GRPC_ERROR_UNREF(error_list[i]);
}
}
break;

@ -109,7 +109,4 @@ grpc_cc_test(
"//:grpc",
"//test/core/util:grpc_test_util",
],
# TODO(nnoble): Remove this once https://github.com/grpc/grpc/issues/20541
# is resolved.
tags = ["no_windows"],
)

@ -88,17 +88,13 @@ TEST(XdsBootstrapTest, Basic) {
EXPECT_THAT(
bootstrap.node()->metadata,
::testing::ElementsAre(
::testing::Pair(::testing::StrEq("null"),
::testing::AllOf(::testing::Field(
&XdsBootstrap::MetadataValue::type,
XdsBootstrap::MetadataValue::Type::MD_NULL))),
::testing::Pair(
::testing::StrEq("string"),
::testing::StrEq("bool"),
::testing::AllOf(
::testing::Field(&XdsBootstrap::MetadataValue::type,
XdsBootstrap::MetadataValue::Type::STRING),
::testing::Field(&XdsBootstrap::MetadataValue::string_value,
::testing::StrEq("quux")))),
XdsBootstrap::MetadataValue::Type::BOOL),
::testing::Field(&XdsBootstrap::MetadataValue::bool_value,
true))),
::testing::Pair(
::testing::StrEq("double"),
::testing::AllOf(
@ -107,12 +103,20 @@ TEST(XdsBootstrapTest, Basic) {
::testing::Field(&XdsBootstrap::MetadataValue::double_value,
123.4))),
::testing::Pair(
::testing::StrEq("bool"),
::testing::StrEq("list"),
::testing::Field(&XdsBootstrap::MetadataValue::type,
XdsBootstrap::MetadataValue::Type::LIST)),
::testing::Pair(::testing::StrEq("null"),
::testing::AllOf(::testing::Field(
&XdsBootstrap::MetadataValue::type,
XdsBootstrap::MetadataValue::Type::MD_NULL))),
::testing::Pair(
::testing::StrEq("string"),
::testing::AllOf(
::testing::Field(&XdsBootstrap::MetadataValue::type,
XdsBootstrap::MetadataValue::Type::BOOL),
::testing::Field(&XdsBootstrap::MetadataValue::bool_value,
true))),
XdsBootstrap::MetadataValue::Type::STRING),
::testing::Field(&XdsBootstrap::MetadataValue::string_value,
::testing::StrEq("quux")))),
::testing::Pair(
::testing::StrEq("struct"),
::testing::AllOf(
@ -128,11 +132,7 @@ TEST(XdsBootstrapTest, Basic) {
XdsBootstrap::MetadataValue::Type::DOUBLE),
::testing::Field(
&XdsBootstrap::MetadataValue::double_value,
0))))))),
::testing::Pair(
::testing::StrEq("list"),
::testing::Field(&XdsBootstrap::MetadataValue::type,
XdsBootstrap::MetadataValue::Type::LIST))));
0)))))))));
// TODO(roth): Once our InlinedVector<> implementation supports
// iteration, replace this by using ElementsAre() in the statement above.
auto it = bootstrap.node()->metadata.find("list");
@ -232,8 +232,8 @@ TEST(XdsBootstrapTest, BadXdsServerContents) {
"\"server_uri\" field is not a string(.*)"
"duplicate \"server_uri\" field(.*)"
"\"channel_creds\" field is not an array(.*)"
"duplicate \"channel_creds\" field(.*)"
"\"channel_creds\" field is not an array"));
"\"channel_creds\" field is not an array(.*)"
"duplicate \"channel_creds\" field(.*)"));
VerifyRegexMatch(error, e);
}
@ -258,7 +258,8 @@ TEST(XdsBootstrapTest, BadChannelCredsContents) {
ASSERT_TRUE(error != GRPC_ERROR_NONE);
std::regex e(
std::string("errors parsing \"xds_server\" object(.*)"
"errors parsing \"channel_creds\" object(.*)"
"errors parsing \"channel_creds\" array(.*)"
"errors parsing index 0(.*)"
"\"type\" field is not a string(.*)"
"duplicate \"type\" field(.*)"
"\"config\" field is not an object(.*)"
@ -324,9 +325,12 @@ TEST(XdsBootstrapTest, BadNode) {
} // namespace grpc_core
int main(int argc, char** argv) {
// Regexes don't work in gcc4.8 and below, so just skip testing in those cases
#if defined(__GNUC__) && \
((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__) <= 8))
// Regexes don't work in old libstdc++ versions, so just skip testing in those
// cases
#if defined(__GLIBCXX__) && (__GLIBCXX__ <= 20150623)
gpr_log(GPR_ERROR,
"Skipping xds_bootstrap_test since std::regex is not supported on "
"this system.");
return 0;
#endif
grpc::testing::TestEnvironment env(argc, argv);

Loading…
Cancel
Save