[gprpp] Add ValidationErrors::message retrieval (#32761)

For cases where an absl::Status is unnecessary.
pull/32632/head^2
AJ Heller 2 years ago committed by GitHub
parent 569d0076b3
commit b94d55bd20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 1
      src/core/BUILD
  3. 1
      src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc
  4. 5
      src/core/ext/xds/xds_cluster.cc
  5. 5
      src/core/ext/xds/xds_endpoint.cc
  6. 10
      src/core/ext/xds/xds_listener.cc
  7. 3
      src/core/ext/xds/xds_route_config.cc
  8. 11
      src/core/lib/gprpp/validation_errors.cc
  9. 11
      src/core/lib/gprpp/validation_errors.h
  10. 9
      src/core/lib/json/json_object_loader.h
  11. 6
      src/core/lib/service_config/service_config_impl.cc
  12. 31
      test/core/gprpp/validation_errors_test.cc
  13. 15
      test/core/json/json_object_loader_test.cc
  14. 56
      test/core/xds/xds_common_types_test.cc
  15. 117
      test/core/xds/xds_http_filters_test.cc
  16. 5
      test/core/xds/xds_lb_policy_registry_test.cc
  17. 21
      test/cpp/ext/gcp/observability_config_test.cc
  18. 30
      test/cpp/ext/gcp/observability_logging_sink_test.cc

@ -2719,6 +2719,7 @@ grpc_cc_library(
"//src/core:lib/service_config/service_config_impl.h",
],
external_deps = [
"absl/status",
"absl/status:statusor",
"absl/strings",
"absl/types:optional",

@ -3348,6 +3348,7 @@ grpc_cc_library(
hdrs = ["lib/json/json_object_loader.h"],
external_deps = [
"absl/meta:type_traits",
"absl/status",
"absl/status:statusor",
"absl/strings",
"absl/types:optional",

@ -1026,6 +1026,7 @@ class OutlierDetectionLbFactory : public LoadBalancingPolicyFactory {
}
if (!errors.ok()) {
return errors.status(
absl::StatusCode::kInvalidArgument,
"errors validating outlier_detection LB policy config");
}
return MakeRefCounted<OutlierDetectionLbConfig>(outlier_detection_config,

@ -656,7 +656,10 @@ absl::StatusOr<XdsClusterResource> CdsResourceParse(
}
}
// Return result.
if (!errors.ok()) return errors.status("errors validating Cluster resource");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"errors validating Cluster resource");
}
return cds_update;
}

@ -432,7 +432,10 @@ absl::StatusOr<XdsEndpointResource> EdsResourceParse(
}
}
// Return result.
if (!errors.ok()) return errors.status("errors parsing EDS resource");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"errors parsing EDS resource");
}
return eds_resource;
}

@ -502,7 +502,10 @@ absl::StatusOr<XdsListenerResource> LdsResourceParseClient(
lds_update.listener = HttpConnectionManagerParse(
/*is_client=*/true, context, std::move(*extension), &errors);
}
if (!errors.ok()) return errors.status("errors validating ApiListener");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"errors validating ApiListener");
}
return std::move(lds_update);
}
@ -1046,7 +1049,10 @@ absl::StatusOr<XdsListenerResource> LdsResourceParseServer(
}
}
// Return result.
if (!errors.ok()) return errors.status("errors validating server Listener");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"errors validating server Listener");
}
XdsListenerResource lds_update;
lds_update.listener = std::move(tcp_listener);
return lds_update;

@ -1125,7 +1125,8 @@ XdsResourceType::DecodeResult XdsRouteConfigResourceType::Decode(
auto rds_update = XdsRouteConfigResource::Parse(context, resource, &errors);
if (!errors.ok()) {
absl::Status status =
errors.status("errors validating RouteConfiguration resource");
errors.status(absl::StatusCode::kInvalidArgument,
"errors validating RouteConfiguration resource");
if (GRPC_TRACE_FLAG_ENABLED(*context.tracer)) {
gpr_log(GPR_ERROR, "[xds_client %p] invalid RouteConfiguration %s: %s",
context.client, result.name->c_str(), status.ToString().c_str());

@ -42,8 +42,14 @@ bool ValidationErrors::FieldHasErrors() const {
return field_errors_.find(absl::StrJoin(fields_, "")) != field_errors_.end();
}
absl::Status ValidationErrors::status(absl::string_view prefix) const {
absl::Status ValidationErrors::status(absl::StatusCode code,
absl::string_view prefix) const {
if (field_errors_.empty()) return absl::OkStatus();
return absl::Status(code, message(prefix));
}
std::string ValidationErrors::message(absl::string_view prefix) const {
if (field_errors_.empty()) return "";
std::vector<std::string> errors;
for (const auto& p : field_errors_) {
if (p.second.size() > 1) {
@ -54,8 +60,7 @@ absl::Status ValidationErrors::status(absl::string_view prefix) const {
absl::StrCat("field:", p.first, " error:", p.second[0]));
}
}
return absl::InvalidArgumentError(
absl::StrCat(prefix, ": [", absl::StrJoin(errors, "; "), "]"));
return absl::StrCat(prefix, ": [", absl::StrJoin(errors, "; "), "]");
}
} // namespace grpc_core

@ -58,7 +58,8 @@ namespace grpc_core {
// }
// }
// }
// return errors.status("errors validating foo.bar");
// return errors.status(absl::StatusCode::kInvalidArgument,
// "errors validating foo.bar");
// }
class ValidationErrors {
public:
@ -100,7 +101,13 @@ class ValidationErrors {
bool FieldHasErrors() const GPR_ATTRIBUTE_NOINLINE;
// Returns the resulting status of parsing.
absl::Status status(absl::string_view prefix) const;
// If there are no errors, this will return an Ok status instead of using the
// prefix argument.
absl::Status status(absl::StatusCode code, absl::string_view prefix) const;
// Returns the resulting error message
// If there are no errors, this will return an empty string.
std::string message(absl::string_view prefix) const;
// Returns true if there are no errors.
bool ok() const { return field_errors_.empty(); }

@ -26,6 +26,7 @@
#include <vector>
#include "absl/meta/type_traits.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
@ -589,7 +590,9 @@ absl::StatusOr<T> LoadFromJson(
ValidationErrors errors;
T result{};
json_detail::LoaderForType<T>()->LoadInto(json, args, &result, &errors);
if (!errors.ok()) return errors.status(error_prefix);
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument, error_prefix);
}
return std::move(result);
}
@ -600,7 +603,9 @@ absl::StatusOr<RefCountedPtr<T>> LoadRefCountedFromJson(
ValidationErrors errors;
auto result = MakeRefCounted<T>();
json_detail::LoaderForType<T>()->LoadInto(json, args, result.get(), &errors);
if (!errors.ok()) return errors.status(error_prefix);
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument, error_prefix);
}
return std::move(result);
}

@ -23,6 +23,7 @@
#include <string>
#include <utility>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/types/optional.h"
@ -87,7 +88,10 @@ absl::StatusOr<RefCountedPtr<ServiceConfig>> ServiceConfigImpl::Create(
if (!json.ok()) return json.status();
ValidationErrors errors;
auto service_config = Create(args, *json, json_string, &errors);
if (!errors.ok()) return errors.status("errors validating service config");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"errors validating service config");
}
return service_config;
}

@ -34,7 +34,8 @@ TEST(ValidationErrors, NoErrors) {
}
EXPECT_TRUE(errors.ok());
EXPECT_EQ(errors.size(), 0);
absl::Status status = errors.status("errors validating config");
absl::Status status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating config");
EXPECT_TRUE(status.ok()) << status;
}
@ -49,7 +50,8 @@ TEST(ValidationErrors, OneError) {
}
EXPECT_FALSE(errors.ok());
EXPECT_EQ(errors.size(), 1);
absl::Status status = errors.status("errors validating config");
absl::Status status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -69,7 +71,8 @@ TEST(ValidationErrors, MultipleErrorsForSameField) {
}
EXPECT_FALSE(errors.ok());
EXPECT_EQ(errors.size(), 1);
absl::Status status = errors.status("errors validating config");
absl::Status status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating config: [field:foo.bar errors:["
@ -89,7 +92,8 @@ TEST(ValidationErrors, ErrorsForMultipleFields) {
}
EXPECT_FALSE(errors.ok());
EXPECT_EQ(errors.size(), 2);
absl::Status status = errors.status("errors validating config");
absl::Status status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating config: ["
@ -97,6 +101,25 @@ TEST(ValidationErrors, ErrorsForMultipleFields) {
<< status;
}
TEST(ValidationErrors, MessageMatchesStatusMessage) {
ValidationErrors errors;
{
ValidationErrors::ScopedField field(&errors, "foo");
{
ValidationErrors::ScopedField field(&errors, ".bar");
errors.AddError("value smells funny");
}
errors.AddError("too hot");
}
EXPECT_FALSE(errors.ok());
EXPECT_EQ(errors.size(), 2);
absl::Status status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating config");
std::string message = errors.message("errors validating config");
EXPECT_EQ(status.message(), message)
<< status << " does not match " << message;
}
} // namespace
} // namespace testing
} // namespace grpc_core

@ -1095,7 +1095,8 @@ TEST(JsonObjectLoader, LoadFromJsonWithValidationErrors) {
ValidationErrors errors;
TestStruct test_struct =
LoadFromJson<TestStruct>(*json, JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
EXPECT_EQ(test_struct.a, 1);
}
// Invalid.
@ -1105,7 +1106,8 @@ TEST(JsonObjectLoader, LoadFromJsonWithValidationErrors) {
ASSERT_TRUE(json.ok()) << json.status();
ValidationErrors errors;
LoadFromJson<TestStruct>(*json, JsonArgs(), &errors);
absl::Status status = errors.status("errors validating JSON");
absl::Status status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating JSON");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating JSON: [field:a error:failed to parse number]")
@ -1122,7 +1124,8 @@ TEST(JsonObjectLoader, LoadJsonObjectField) {
ValidationErrors errors;
auto value = LoadJsonObjectField<int32_t>(json->object(), JsonArgs(), "int",
&errors);
ASSERT_TRUE(value.has_value()) << errors.status("unexpected errors");
ASSERT_TRUE(value.has_value()) << errors.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
EXPECT_EQ(*value, 1);
EXPECT_TRUE(errors.ok());
}
@ -1141,7 +1144,8 @@ TEST(JsonObjectLoader, LoadJsonObjectField) {
auto value = LoadJsonObjectField<int32_t>(json->object(), JsonArgs(),
"not_present", &errors);
EXPECT_FALSE(value.has_value());
auto status = errors.status("errors validating JSON");
auto status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating JSON");
EXPECT_THAT(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating JSON: ["
@ -1154,7 +1158,8 @@ TEST(JsonObjectLoader, LoadJsonObjectField) {
auto value = LoadJsonObjectField<std::string>(json->object(), JsonArgs(),
"int", &errors);
EXPECT_FALSE(value.has_value());
auto status = errors.status("errors validating JSON");
auto status = errors.status(absl::StatusCode::kInvalidArgument,
"errors validating JSON");
EXPECT_THAT(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating JSON: [field:int error:is not a string]")

@ -128,7 +128,8 @@ TEST_F(DurationTest, Basic) {
google_protobuf_Duration_set_nanos(duration_proto, 2000000);
ValidationErrors errors;
Duration duration = ParseDuration(duration_proto, &errors);
EXPECT_TRUE(errors.ok()) << errors.status("unexpected errors");
EXPECT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
EXPECT_EQ(duration, Duration::Milliseconds(1002));
}
@ -139,7 +140,8 @@ TEST_F(DurationTest, NegativeNumbers) {
google_protobuf_Duration_set_nanos(duration_proto, -2);
ValidationErrors errors;
ParseDuration(duration_proto, &errors);
absl::Status status = errors.status("validation failed");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation failed");
EXPECT_EQ(status.message(),
"validation failed: ["
"field:nanos error:value must be in the range [0, 999999999]; "
@ -154,7 +156,8 @@ TEST_F(DurationTest, ValuesTooHigh) {
google_protobuf_Duration_set_nanos(duration_proto, 1000000000);
ValidationErrors errors;
ParseDuration(duration_proto, &errors);
absl::Status status = errors.status("validation failed");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation failed");
EXPECT_EQ(status.message(),
"validation failed: ["
"field:nanos error:value must be in the range [0, 999999999]; "
@ -196,7 +199,10 @@ class CommonTlsConfigTest : public XdsCommonTypesTest {
ValidationErrors errors;
CommonTlsContext common_tls_context =
CommonTlsContext::Parse(decode_context_, upb_proto, &errors);
if (!errors.ok()) return errors.status("validation failed");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"validation failed");
}
return common_tls_context;
}
};
@ -545,7 +551,8 @@ TEST_F(ExtractXdsExtensionTest, Basic) {
google_protobuf_Any_set_value(any_proto, StdStringToUpbString(kValue));
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(extension.has_value());
EXPECT_EQ(extension->type, "MyType");
ASSERT_TRUE(absl::holds_alternative<absl::string_view>(extension->value));
@ -566,7 +573,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStruct) {
StdStringToUpbString(serialized_typed_struct));
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(extension.has_value());
EXPECT_EQ(extension->type, "MyType");
ASSERT_TRUE(absl::holds_alternative<Json>(extension->value));
@ -587,7 +595,8 @@ TEST_F(ExtractXdsExtensionTest, UdpaTypedStruct) {
StdStringToUpbString(serialized_typed_struct));
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(extension.has_value());
EXPECT_EQ(extension->type, "MyType");
ASSERT_TRUE(absl::holds_alternative<Json>(extension->value));
@ -606,7 +615,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructWithoutValue) {
StdStringToUpbString(serialized_typed_struct));
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(extension.has_value());
EXPECT_EQ(extension->type, "MyType");
ASSERT_TRUE(absl::holds_alternative<Json>(extension->value));
@ -663,7 +673,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructJsonConversion) {
StdStringToUpbString(serialized_typed_struct));
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(extension.has_value());
EXPECT_EQ(extension->type, "envoy.ExtensionType");
ASSERT_TRUE(absl::holds_alternative<Json>(extension->value));
@ -682,7 +693,8 @@ TEST_F(ExtractXdsExtensionTest, FieldMissing) {
ValidationErrors::ScopedField field(&errors, "any");
auto extension = ExtractXdsExtension(decode_context_, nullptr, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: [field:any error:field not present]")
@ -694,7 +706,8 @@ TEST_F(ExtractXdsExtensionTest, TypeUrlMissing) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: [field:type_url error:field not present]")
@ -715,7 +728,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructTypeUrlMissing) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["
@ -731,7 +745,8 @@ TEST_F(ExtractXdsExtensionTest, TypeUrlNoSlash) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["
@ -754,7 +769,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructTypeUrlNoSlash) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["
@ -770,7 +786,8 @@ TEST_F(ExtractXdsExtensionTest, TypeUrlNothingAfterSlash) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["
@ -793,7 +810,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructTypeUrlNothingAfterSlash) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["
@ -813,7 +831,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructParseFailure) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["
@ -836,7 +855,8 @@ TEST_F(ExtractXdsExtensionTest, TypedStructWithInvalidProtobufStruct) {
ValidationErrors errors;
auto extension = ExtractXdsExtension(decode_context_, any_proto, &errors);
ASSERT_FALSE(errors.ok());
absl::Status status = errors.status("validation errors");
absl::Status status =
errors.status(absl::StatusCode::kInvalidArgument, "validation errors");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"validation errors: ["

@ -180,7 +180,8 @@ TEST_F(XdsRouterFilterTest, GenerateFilterConfig) {
XdsExtension extension = MakeXdsExtension(Router());
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->ConfigProtoName());
EXPECT_EQ(config->config, Json()) << JsonDump(config->config);
@ -191,7 +192,8 @@ TEST_F(XdsRouterFilterTest, GenerateFilterConfigTypedStruct) {
extension.value = Json();
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -207,7 +209,8 @@ TEST_F(XdsRouterFilterTest, GenerateFilterConfigUnparseable) {
extension.value = absl::string_view(serialized_resource);
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -221,7 +224,8 @@ TEST_F(XdsRouterFilterTest, GenerateFilterConfigOverride) {
XdsExtension extension = MakeXdsExtension(Router());
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -308,7 +312,8 @@ INSTANTIATE_TEST_SUITE_P(XdsFaultFilter, XdsFaultInjectionFilterConfigTest,
TEST_P(XdsFaultInjectionFilterConfigTest, EmptyConfig) {
XdsExtension extension = MakeXdsExtension(HTTPFault());
auto config = GenerateConfig(std::move(extension));
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->ConfigProtoName());
EXPECT_EQ(config->config, Json(Json::Object())) << JsonDump(config->config);
@ -327,7 +332,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, BasicConfig) {
fault.mutable_max_active_faults()->set_value(10);
XdsExtension extension = MakeXdsExtension(fault);
auto config = GenerateConfig(std::move(extension));
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->ConfigProtoName());
EXPECT_EQ(JsonDump(config->config),
@ -346,7 +352,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, HttpAbortCode) {
abort->set_http_status(404);
XdsExtension extension = MakeXdsExtension(fault);
auto config = GenerateConfig(std::move(extension));
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->ConfigProtoName());
EXPECT_EQ(JsonDump(config->config), "{\"abortCode\":\"UNIMPLEMENTED\"}");
@ -358,7 +365,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, HeaderAbortAndDelay) {
fault.mutable_delay()->mutable_header_delay();
XdsExtension extension = MakeXdsExtension(fault);
auto config = GenerateConfig(std::move(extension));
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->ConfigProtoName());
EXPECT_EQ(
@ -375,7 +383,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, InvalidGrpcStatusCode) {
fault.mutable_abort()->set_grpc_status(17);
XdsExtension extension = MakeXdsExtension(fault);
auto config = GenerateConfig(std::move(extension));
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -390,7 +399,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, InvalidDuration) {
fault.mutable_delay()->mutable_fixed_delay()->set_seconds(315576000001);
XdsExtension extension = MakeXdsExtension(fault);
auto config = GenerateConfig(std::move(extension));
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -404,7 +414,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, TypedStruct) {
XdsExtension extension = MakeXdsExtension(HTTPFault());
extension.value = Json();
auto config = GenerateConfig(std::move(extension));
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -418,7 +429,8 @@ TEST_P(XdsFaultInjectionFilterConfigTest, Unparseable) {
std::string serialized_resource("\0", 1);
extension.value = absl::string_view(serialized_resource);
auto config = GenerateConfig(std::move(extension));
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -464,7 +476,8 @@ TEST_F(XdsRbacFilterTest, GenerateFilterConfig) {
XdsExtension extension = MakeXdsExtension(RBAC());
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->ConfigProtoName());
EXPECT_EQ(config->config, Json(Json::Object())) << JsonDump(config->config);
@ -475,7 +488,8 @@ TEST_F(XdsRbacFilterTest, GenerateFilterConfigTypedStruct) {
extension.value = Json();
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -491,7 +505,8 @@ TEST_F(XdsRbacFilterTest, GenerateFilterConfigUnparseable) {
extension.value = absl::string_view(serialized_resource);
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -505,7 +520,8 @@ TEST_F(XdsRbacFilterTest, GenerateFilterConfigOverride) {
XdsExtension extension = MakeXdsExtension(RBACPerRoute());
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->OverrideConfigProtoName());
EXPECT_EQ(config->config, Json(Json::Object())) << JsonDump(config->config);
@ -516,7 +532,8 @@ TEST_F(XdsRbacFilterTest, GenerateFilterConfigOverrideTypedStruct) {
extension.value = Json();
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -531,7 +548,8 @@ TEST_F(XdsRbacFilterTest, GenerateFilterConfigOverrideUnparseable) {
extension.value = absl::string_view(serialized_resource);
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -572,7 +590,8 @@ INSTANTIATE_TEST_SUITE_P(XdsRbacFilter, XdsRbacFilterConfigTest,
TEST_P(XdsRbacFilterConfigTest, EmptyConfig) {
auto config = GenerateConfig(RBAC());
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name,
GetParam() ? filter_->OverrideConfigProtoName()
@ -658,7 +677,8 @@ TEST_P(XdsRbacFilterConfigTest, AllPermissionTypes) {
// or
policy.add_permissions()->mutable_or_rules()->add_rules()->set_any(true);
auto config = GenerateConfig(rbac);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name,
GetParam() ? filter_->OverrideConfigProtoName()
@ -784,7 +804,8 @@ TEST_P(XdsRbacFilterConfigTest, AllPrincipalTypes) {
// or
policy.add_principals()->mutable_or_ids()->add_ids()->set_any(true);
auto config = GenerateConfig(rbac);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name,
GetParam() ? filter_->OverrideConfigProtoName()
@ -834,7 +855,8 @@ TEST_P(XdsRbacFilterConfigTest, InvalidFieldsInPolicy) {
policy.mutable_condition();
policy.mutable_checked_condition();
auto config = GenerateConfig(rbac);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
absl::StrCat("errors validating filter config: ["
@ -863,7 +885,8 @@ TEST_P(XdsRbacFilterConfigTest, InvalidHeaderMatchers) {
header = policy.add_principals()->mutable_header();
header->set_name("header_name");
auto config = GenerateConfig(rbac);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -891,7 +914,8 @@ TEST_P(XdsRbacFilterConfigTest, InvalidStringMatchers) {
policy.add_permissions()->mutable_url_path()->mutable_path();
policy.add_principals()->mutable_url_path();
auto config = GenerateConfig(rbac);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -915,7 +939,8 @@ TEST_P(XdsRbacFilterConfigTest, InvalidPermissionAndPrincipal) {
policy.add_permissions();
policy.add_principals();
auto config = GenerateConfig(rbac);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
absl::StrCat("errors validating filter config: ["
@ -984,7 +1009,8 @@ TEST_F(XdsStatefulSessionFilterTest, OverrideConfigDisabled) {
XdsExtension extension = MakeXdsExtension(stateful_session_per_route);
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name, filter_->OverrideConfigProtoName());
EXPECT_EQ(config->config, Json(Json::Object{})) << JsonDump(config->config);
@ -1015,7 +1041,8 @@ TEST_F(XdsStatefulSessionFilterTest, GenerateFilterConfigTypedStruct) {
extension.value = Json();
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1032,7 +1059,8 @@ TEST_F(XdsStatefulSessionFilterTest, GenerateFilterConfigUnparseable) {
extension.value = absl::string_view(serialized_resource);
auto config = filter_->GenerateFilterConfig(decode_context_,
std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1048,7 +1076,8 @@ TEST_F(XdsStatefulSessionFilterTest, GenerateFilterConfigOverrideTypedStruct) {
extension.value = Json();
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -1065,7 +1094,8 @@ TEST_F(XdsStatefulSessionFilterTest, GenerateFilterConfigOverrideUnparseable) {
extension.value = absl::string_view(serialized_resource);
auto config = filter_->GenerateFilterConfigOverride(
decode_context_, std::move(extension), &errors_);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(status.message(),
"errors validating filter config: ["
@ -1115,7 +1145,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, MinimalConfig) {
stateful_session.mutable_session_state()->mutable_typed_config()->PackFrom(
cookie_state);
auto config = GenerateConfig(stateful_session);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name,
GetParam() ? filter_->OverrideConfigProtoName()
@ -1134,7 +1165,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, PathAndTtl) {
stateful_session.mutable_session_state()->mutable_typed_config()->PackFrom(
cookie_state);
auto config = GenerateConfig(stateful_session);
ASSERT_TRUE(errors_.ok()) << errors_.status("unexpected errors");
ASSERT_TRUE(errors_.ok()) << errors_.status(
absl::StatusCode::kInvalidArgument, "unexpected errors");
ASSERT_TRUE(config.has_value());
EXPECT_EQ(config->config_proto_type_name,
GetParam() ? filter_->OverrideConfigProtoName()
@ -1149,7 +1181,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, PathAndTtl) {
TEST_P(XdsStatefulSessionFilterConfigTest, SessionStateUnset) {
auto config = GenerateConfig(StatefulSession());
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1163,7 +1196,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, CookieNotPresent) {
stateful_session.mutable_session_state()->mutable_typed_config()->PackFrom(
CookieBasedSessionState());
auto config = GenerateConfig(stateful_session);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1182,7 +1216,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, CookieNameNotPresent) {
stateful_session.mutable_session_state()->mutable_typed_config()->PackFrom(
cookie_state);
auto config = GenerateConfig(stateful_session);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1203,7 +1238,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, InvalidTtl) {
stateful_session.mutable_session_state()->mutable_typed_config()->PackFrom(
cookie_state);
auto config = GenerateConfig(stateful_session);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1220,7 +1256,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, UnknownSessionStateType) {
stateful_session.mutable_session_state()->mutable_typed_config()->PackFrom(
Router());
auto config = GenerateConfig(stateful_session);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1240,7 +1277,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, TypedStructSessionState) {
typed_struct.set_type_url(typed_config->type_url());
typed_config->PackFrom(typed_struct);
auto config = GenerateConfig(stateful_session);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),
@ -1260,7 +1298,8 @@ TEST_P(XdsStatefulSessionFilterConfigTest, UnparseableSessionState) {
stateful_session.mutable_session_state()->mutable_typed_config()->set_value(
std::string("\0", 1));
auto config = GenerateConfig(stateful_session);
absl::Status status = errors_.status("errors validating filter config");
absl::Status status = errors_.status(absl::StatusCode::kInvalidArgument,
"errors validating filter config");
ASSERT_EQ(status.code(), absl::StatusCode::kInvalidArgument);
EXPECT_EQ(
status.message(),

@ -84,7 +84,10 @@ absl::StatusOr<std::string> ConvertXdsPolicy(
ValidationErrors::ScopedField field(&errors, ".load_balancing_policy");
auto config = XdsLbPolicyRegistry().ConvertXdsLbPolicyConfig(
context, upb_policy, &errors);
if (!errors.ok()) return errors.status("validation errors");
if (!errors.ok()) {
return errors.status(absl::StatusCode::kInvalidArgument,
"validation errors");
}
EXPECT_EQ(config.size(), 1);
return JsonDump(Json{config[0]});
}

@ -68,7 +68,8 @@ TEST(GcpObservabilityConfigJsonParsingTest, Basic) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(config.cloud_logging.has_value());
ASSERT_EQ(config.cloud_logging->client_rpc_events.size(), 2);
EXPECT_THAT(config.cloud_logging->client_rpc_events[0].qualified_methods,
@ -109,7 +110,8 @@ TEST(GcpObservabilityConfigJsonParsingTest, Defaults) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
EXPECT_FALSE(config.cloud_logging.has_value());
EXPECT_FALSE(config.cloud_monitoring.has_value());
EXPECT_FALSE(config.cloud_trace.has_value());
@ -132,7 +134,8 @@ TEST(GcpObservabilityConfigJsonParsingTest, LoggingConfigMethodIllegalSlashes) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
EXPECT_THAT(errors.status("Parsing error").ToString(),
EXPECT_THAT(errors.status(absl::StatusCode::kInvalidArgument, "Parsing error")
.ToString(),
::testing::AllOf(
::testing::HasSubstr(
"field:cloud_logging.client_rpc_events[0].methods[0]"
@ -158,7 +161,8 @@ TEST(GcpObservabilityConfigJsonParsingTest, LoggingConfigEmptyMethod) {
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
EXPECT_THAT(
errors.status("Parsing error").ToString(),
errors.status(absl::StatusCode::kInvalidArgument, "Parsing error")
.ToString(),
::testing::HasSubstr("field:cloud_logging.client_rpc_events[0].methods[0]"
" error:Empty configuration"));
}
@ -183,7 +187,8 @@ TEST(GcpObservabilityConfigJsonParsingTest, LoggingConfigWildcardEntries) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(config.cloud_logging.has_value());
ASSERT_EQ(config.cloud_logging->client_rpc_events.size(), 1);
EXPECT_THAT(config.cloud_logging->client_rpc_events[0].qualified_methods,
@ -215,7 +220,8 @@ TEST(GcpObservabilityConfigJsonParsingTest,
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
EXPECT_THAT(
errors.status("Parsing error").ToString(),
errors.status(absl::StatusCode::kInvalidArgument, "Parsing error")
.ToString(),
::testing::AllOf(
::testing::HasSubstr(
"field:cloud_logging.client_rpc_events[0].methods[0]"
@ -239,7 +245,8 @@ TEST(GcpObservabilityConfigJsonParsingTest, SamplingRateDefaults) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ASSERT_TRUE(config.cloud_trace.has_value());
EXPECT_FLOAT_EQ(config.cloud_trace->sampling_rate, 0.05);
}

@ -42,7 +42,8 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigEmpty) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_FALSE(sink.FindMatch(true, "foo", "bar").ShouldLog());
@ -67,7 +68,8 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigClientWildCardEntries) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_EQ(sink.FindMatch(true, "foo", "bar"),
@ -93,7 +95,8 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigBadPath) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
EXPECT_FALSE(sink.FindMatch(true, "foo", "").ShouldLog());
}
@ -116,7 +119,8 @@ TEST(GcpObservabilityLoggingSinkTest,
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_EQ(sink.FindMatch(true, "service", "bar"),
@ -145,7 +149,8 @@ TEST(GcpObservabilityLoggingSinkTest,
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_EQ(sink.FindMatch(true, "foo", "bar"),
@ -179,7 +184,8 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigClientMultipleEventEntries) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_EQ(sink.FindMatch(true, "foo", "bar"),
@ -207,7 +213,8 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigServerWildCardEntries) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_FALSE(sink.FindMatch(true, "foo", "bar").ShouldLog());
@ -234,7 +241,8 @@ TEST(GcpObservabilityLoggingSinkTest,
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_FALSE(sink.FindMatch(true, "service", "bar").ShouldLog());
@ -263,7 +271,8 @@ TEST(GcpObservabilityLoggingSinkTest,
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_FALSE(sink.FindMatch(true, "foo", "bar").ShouldLog());
@ -297,7 +306,8 @@ TEST(GcpObservabilityLoggingSinkTest, LoggingConfigServerMultipleEventEntries) {
grpc_core::ValidationErrors errors;
auto config = grpc_core::LoadFromJson<GcpObservabilityConfig>(
*json, grpc_core::JsonArgs(), &errors);
ASSERT_TRUE(errors.ok()) << errors.status("unexpected errors");
ASSERT_TRUE(errors.ok()) << errors.status(absl::StatusCode::kInvalidArgument,
"unexpected errors");
ObservabilityLoggingSink sink(config.cloud_logging.value(), "test", {});
// client test
EXPECT_FALSE(sink.FindMatch(true, "foo", "bar").ShouldLog());

Loading…
Cancel
Save