Skip to content

Commit

Permalink
[tools] update schema validator to use MessageUtil (envoyproxy#6834)
Browse files Browse the repository at this point in the history
Description: Switching to MessageUtils opens up some flexibility such as being able to load JSON or YAML (handled by loadFromFile), is v2-only, and lines up with the test-config conversion work I've been doing elsewhere to eliminate v1 API loading.
Risk Level: Low (offline tool)
Testing: I don't think this tool has any unit tests, verified manually with a config file.
Docs Changes: N/A - The docs actually link to v2 RouteConfiguration, so this technically fixes that...
Release Notes: I'm not sure if updating a tool warrants a release note, if so I'll be happy to include one.

Signed-off-by: Derek Argueta <dereka@pinterest.com>
  • Loading branch information
derekargueta authored and alyssawilk committed May 7, 2019
1 parent c848204 commit af6e1b6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
13 changes: 5 additions & 8 deletions test/tools/schema_validator/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ envoy_cc_test_library(
],
external_deps = ["tclap"],
deps = [
"//include/envoy/common:base_includes",
"//source/common/config:rds_json_lib",
"//source/common/json:json_loader_lib",
"//source/common/router:config_lib",
"//source/common/stats:stats_lib",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:printers_lib",
"//include/envoy/api:api_interface",
"//source/common/protobuf:utility_lib",
"//source/common/stats:isolated_store_lib",
"//test/test_common:utility_lib",
"@envoy_api//envoy/api/v2:rds_cc",
],
)
11 changes: 5 additions & 6 deletions test/tools/schema_validator/validator.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "test/tools/schema_validator/validator.h"

#include "common/router/config_impl.h"
#include "envoy/api/v2/rds.pb.h"
#include "envoy/api/v2/rds.pb.validate.h"

#include "test/test_common/printers.h"
#include "common/protobuf/utility.h"

#include "tclap/CmdLine.h"

Expand Down Expand Up @@ -46,16 +47,14 @@ Options::Options(int argc, char** argv) {
}

void Validator::validate(const std::string& json_path, Schema::Type schema_type) {
Json::ObjectSharedPtr loader = Json::Factory::loadFromFile(json_path, *api_);

switch (schema_type) {
case Schema::Type::Route: {
Runtime::MockLoader runtime;
Upstream::MockClusterManager cm;
// Construct a envoy::api::v2::RouteConfiguration to validate the Route configuration and
// ignore the output since nothing will consume it.
envoy::api::v2::RouteConfiguration route_config;
Config::RdsJson::translateRouteConfiguration(*loader, route_config);
MessageUtil::loadFromFile(json_path, route_config, *api_);
MessageUtil::validate(route_config);
break;
}
default:
Expand Down
6 changes: 3 additions & 3 deletions test/tools/schema_validator/validator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <string>

#include "common/json/json_loader.h"
#include "envoy/api/api.h"

#include "common/stats/isolated_store_impl.h"

#include "test/mocks/runtime/mocks.h"
#include "test/mocks/upstream/mocks.h"
#include "test/test_common/utility.h"

namespace Envoy {
Expand Down

0 comments on commit af6e1b6

Please sign in to comment.