diff --git a/test/tools/router_check/router.cc b/test/tools/router_check/router.cc index 5eeadc7a1bb1..fbd9eaed7031 100644 --- a/test/tools/router_check/router.cc +++ b/test/tools/router_check/router.cc @@ -224,13 +224,13 @@ bool RouterCheckTool::compareCluster(ToolConfig& tool_config, const std::string& bool RouterCheckTool::compareCluster( ToolConfig& tool_config, const envoy::RouterCheckToolSchema::ValidationAssert& expected) { - if (expected.cluster_name().empty()) { + if (!expected.has_cluster_name()) { return true; } if (tool_config.route_ == nullptr) { - return compareResults("", expected.cluster_name(), "cluster_name"); + return compareResults("", expected.cluster_name().value(), "cluster_name"); } - return compareCluster(tool_config, expected.cluster_name()); + return compareCluster(tool_config, expected.cluster_name().value()); } bool RouterCheckTool::compareVirtualCluster(ToolConfig& tool_config, const std::string& expected) { @@ -251,13 +251,13 @@ bool RouterCheckTool::compareVirtualCluster(ToolConfig& tool_config, const std:: bool RouterCheckTool::compareVirtualCluster( ToolConfig& tool_config, const envoy::RouterCheckToolSchema::ValidationAssert& expected) { - if (expected.virtual_cluster_name().empty()) { + if (!expected.has_virtual_cluster_name()) { return true; } if (tool_config.route_ == nullptr) { - return compareResults("", expected.virtual_cluster_name(), "virtual_cluster_name"); + return compareResults("", expected.virtual_cluster_name().value(), "virtual_cluster_name"); } - return compareVirtualCluster(tool_config, expected.virtual_cluster_name()); + return compareVirtualCluster(tool_config, expected.virtual_cluster_name().value()); } bool RouterCheckTool::compareVirtualHost(ToolConfig& tool_config, const std::string& expected) { @@ -275,13 +275,13 @@ bool RouterCheckTool::compareVirtualHost(ToolConfig& tool_config, const std::str bool RouterCheckTool::compareVirtualHost( ToolConfig& tool_config, const envoy::RouterCheckToolSchema::ValidationAssert& expected) { - if (expected.virtual_host_name().empty()) { + if (!expected.has_virtual_host_name()) { return true; } if (tool_config.route_ == nullptr) { - return compareResults("", expected.virtual_host_name(), "virtual_host_name"); + return compareResults("", expected.virtual_host_name().value(), "virtual_host_name"); } - return compareVirtualHost(tool_config, expected.virtual_host_name()); + return compareVirtualHost(tool_config, expected.virtual_host_name().value()); } bool RouterCheckTool::compareRewritePath(ToolConfig& tool_config, const std::string& expected) { @@ -306,13 +306,13 @@ bool RouterCheckTool::compareRewritePath(ToolConfig& tool_config, const std::str bool RouterCheckTool::compareRewritePath( ToolConfig& tool_config, const envoy::RouterCheckToolSchema::ValidationAssert& expected) { - if (expected.path_rewrite().empty()) { + if (!expected.has_path_rewrite()) { return true; } if (tool_config.route_ == nullptr) { - return compareResults("", expected.path_rewrite(), "path_rewrite"); + return compareResults("", expected.path_rewrite().value(), "path_rewrite"); } - return compareRewritePath(tool_config, expected.path_rewrite()); + return compareRewritePath(tool_config, expected.path_rewrite().value()); } bool RouterCheckTool::compareRewriteHost(ToolConfig& tool_config, const std::string& expected) { @@ -337,13 +337,13 @@ bool RouterCheckTool::compareRewriteHost(ToolConfig& tool_config, const std::str bool RouterCheckTool::compareRewriteHost( ToolConfig& tool_config, const envoy::RouterCheckToolSchema::ValidationAssert& expected) { - if (expected.host_rewrite().empty()) { + if (!expected.has_host_rewrite()) { return true; } if (tool_config.route_ == nullptr) { - return compareResults("", expected.host_rewrite(), "host_rewrite"); + return compareResults("", expected.host_rewrite().value(), "host_rewrite"); } - return compareRewriteHost(tool_config, expected.host_rewrite()); + return compareRewriteHost(tool_config, expected.host_rewrite().value()); } bool RouterCheckTool::compareRedirectPath(ToolConfig& tool_config, const std::string& expected) { @@ -361,13 +361,13 @@ bool RouterCheckTool::compareRedirectPath(ToolConfig& tool_config, const std::st bool RouterCheckTool::compareRedirectPath( ToolConfig& tool_config, const envoy::RouterCheckToolSchema::ValidationAssert& expected) { - if (expected.path_redirect().empty()) { + if (!expected.has_path_redirect()) { return true; } if (tool_config.route_ == nullptr) { - return compareResults("", expected.path_redirect(), "path_redirect"); + return compareResults("", expected.path_redirect().value(), "path_redirect"); } - return compareRedirectPath(tool_config, expected.path_redirect()); + return compareRedirectPath(tool_config, expected.path_redirect().value()); } bool RouterCheckTool::compareHeaderField( diff --git a/test/tools/router_check/test/config/ComprehensiveRoutes.golden.proto.json b/test/tools/router_check/test/config/ComprehensiveRoutes.golden.proto.json new file mode 100644 index 000000000000..ebc21381c347 --- /dev/null +++ b/test/tools/router_check/test/config/ComprehensiveRoutes.golden.proto.json @@ -0,0 +1,63 @@ +{ + "tests": [ + { + "test_name": "Test 1", + "input": { + "authority": "www.lyft.com", + "path": "/new_endpoint", + "method": "GET" + }, + "validate": { + "cluster_name": "www2", + "virtual_cluster_name": "other", + "virtual_host_name": "www2_host", + "path_rewrite": "/api/new_endpoint", + "host_rewrite": "www.lyft.com", + "path_redirect": "" + } + }, + { + "test_name": "Test 2", + "input": { + "authority": "www.lyft.com", + "path": "/", + "method": "GET" + }, + "validate": { + "cluster_name": "root_www2", + "virtual_cluster_name": "other", + "virtual_host_name": "www2_host", + "path_rewrite": "/", + "host_rewrite": "www.lyft.com", + "path_redirect": "" + } + }, + { + "test_name": "Test 3", + "input": { + "authority": "www.lyft.com", + "path": "/foobar", + "method": "GET" + }, + "validate": { + "cluster_name": "www2", + "virtual_cluster_name": "other", + "virtual_host_name": "www2_host", + "path_rewrite": "/foobar", + "host_rewrite": "www.lyft.com", + "path_redirect": "" + } + }, + { + "test_name": "Test 4", + "input": { + "authority": "www.lyft.com", + "path": "/users/123", + "method": "PUT" + }, + "validate": { + "virtual_cluster_name": "update_user" + } + } + ] +} diff --git a/test/tools/router_check/test/config/ComprehensiveRoutes.yaml b/test/tools/router_check/test/config/ComprehensiveRoutes.yaml index 0613410256ca..6efad99a099e 100644 --- a/test/tools/router_check/test/config/ComprehensiveRoutes.yaml +++ b/test/tools/router_check/test/config/ComprehensiveRoutes.yaml @@ -17,6 +17,11 @@ virtual_hosts: route: cluster: www2 virtual_clusters: - - pattern: ^/users/\d+$ - method: PUT + - headers: + - name: :path + safe_regex_match: + google_re2: {} + regex: ^/users/\d+$ + - name: :method + exact_match: PUT name: update_user diff --git a/test/tools/router_check/test/config/Weighted.golden.proto.pb_text b/test/tools/router_check/test/config/Weighted.golden.proto.pb_text index c2ab5d18c377..fa7dedcb27c5 100644 --- a/test/tools/router_check/test/config/Weighted.golden.proto.pb_text +++ b/test/tools/router_check/test/config/Weighted.golden.proto.pb_text @@ -8,7 +8,7 @@ tests { method: "GET" } validate: { - path_redirect: "" + path_redirect: { value: "" } } } @@ -21,6 +21,6 @@ tests { random_value: 115 } validate: { - cluster_name: "cluster1" + cluster_name: { value: "cluster1" } } } \ No newline at end of file diff --git a/test/tools/router_check/test/route_tests.sh b/test/tools/router_check/test/route_tests.sh index 0b06cb7425bf..1e85bea3f598 100755 --- a/test/tools/router_check/test/route_tests.sh +++ b/test/tools/router_check/test/route_tests.sh @@ -24,6 +24,12 @@ if [[ "${COVERAGE_OUTPUT}" != *"Current route coverage: "* ]] ; then exit 1 fi +COMP_COVERAGE_CMD="${PATH_BIN} -c ${PATH_CONFIG}/ComprehensiveRoutes.yaml -t ${PATH_CONFIG}/ComprehensiveRoutes.golden.proto.json --details --useproto -f " +COVERAGE_OUTPUT=$($COMP_COVERAGE_CMD "100" "--covall" 2>&1) || echo "${COVERAGE_OUTPUT:-no-output}" +if [[ "${COVERAGE_OUTPUT}" != *"Current route coverage: 100%"* ]] ; then + exit 1 +fi + COMP_COVERAGE_CMD="${PATH_BIN} ${PATH_CONFIG}/ComprehensiveRoutes.yaml ${PATH_CONFIG}/ComprehensiveRoutes.golden.json --details -f " COVERAGE_OUTPUT=$($COMP_COVERAGE_CMD "100" "--covall" 2>&1) || echo "${COVERAGE_OUTPUT:-no-output}" if [[ "${COVERAGE_OUTPUT}" != *"Current route coverage: 100%"* ]] ; then diff --git a/test/tools/router_check/validation.proto b/test/tools/router_check/validation.proto index 9c86153cd3e9..4ff3ab35f434 100644 --- a/test/tools/router_check/validation.proto +++ b/test/tools/router_check/validation.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package envoy.RouterCheckToolSchema; import "envoy/api/v2/core/base.proto"; +import "google/protobuf/wrappers.proto"; import "validate/validate.proto"; // [#protodoc-title: RouterCheckTool Validation] @@ -78,22 +79,22 @@ message ValidationInput { // For example, to test that no cluster match is expected use {“cluster_name”: “”}. message ValidationAssert { // Match the cluster name. - string cluster_name = 1; + google.protobuf.StringValue cluster_name = 1; // Match the virtual cluster name. - string virtual_cluster_name = 2; + google.protobuf.StringValue virtual_cluster_name = 2; // Match the virtual host name. - string virtual_host_name = 3; + google.protobuf.StringValue virtual_host_name = 3; // Match the host header field after rewrite. - string host_rewrite = 4; + google.protobuf.StringValue host_rewrite = 4; // Match the path header field after rewrite. - string path_rewrite = 5; + google.protobuf.StringValue path_rewrite = 5; // Match the returned redirect path. - string path_redirect = 6; + google.protobuf.StringValue path_redirect = 6; // Match the listed header fields. // Examples header fields include the “:path”, “cookie”, and “date” fields.