From ef1ca5c8e0b9c09b1bbf758b00d5fe9c1c27b734 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Sun, 23 Apr 2017 19:28:24 -0400 Subject: [PATCH 1/2] test: fix config_schemas_test and runtime_impl_test to support site specific (e.g. google) import. * Encapsulate Python binary test helpers to ensure we have have all dependencies mapped correctly into the runfiles. This becomes more important for config_test, which is not handled in this patch, where we need to also include external dependencies (jinja2), hence the addition of an unused external_deps attribute in envoy_py_test_binary. * Make sure the runtime test filesystem is writable before symlinking in it. --- bazel/envoy_build_system.bzl | 10 ++++++++++ test/common/json/BUILD | 9 +-------- test/common/json/config_schemas_test.cc | 2 +- test/common/json/config_schemas_test_data/BUILD | 11 +++++++++++ test/common/runtime/filesystem_setup.sh | 1 + 5 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 test/common/json/config_schemas_test_data/BUILD diff --git a/bazel/envoy_build_system.bzl b/bazel/envoy_build_system.bzl index c8c57941f795a..f144842b14649 100644 --- a/bazel/envoy_build_system.bzl +++ b/bazel/envoy_build_system.bzl @@ -207,6 +207,16 @@ def envoy_cc_test_library(name, linkstatic = 1, ) +# Envoy Python test binaries should be specified with this function. +def envoy_py_test_binary(name, + external_deps = [], + **kargs): + # TODO(htuch): Add support for external_deps, e.g. jinja2 for config_test. + native.py_binary( + name = name, + **kargs + ) + # Envoy C++ mock targets should be specified with this function. def envoy_cc_mock(name, **kargs): envoy_cc_test_library(name = name, **kargs) diff --git a/test/common/json/BUILD b/test/common/json/BUILD index bc9952fda832f..4cf5c2b7d30cc 100644 --- a/test/common/json/BUILD +++ b/test/common/json/BUILD @@ -2,18 +2,11 @@ package(default_visibility = ["//visibility:public"]) load("//bazel:envoy_build_system.bzl", "envoy_cc_test") -filegroup( - name = "config_schema_test_generator", - srcs = glob([ - "config_schemas_test_data/*.py", - ]), -) - envoy_cc_test( name = "config_schemas_test", srcs = ["config_schemas_test.cc"], data = [ - "//test/common/json:config_schema_test_generator", + "//test/common/json/config_schemas_test_data:generate_test_data", ], deps = [ "//source/common/json:config_schemas_lib", diff --git a/test/common/json/config_schemas_test.cc b/test/common/json/config_schemas_test.cc index 1c4c211bf0a6d..6c0d3d94c46a8 100644 --- a/test/common/json/config_schemas_test.cc +++ b/test/common/json/config_schemas_test.cc @@ -17,7 +17,7 @@ namespace Json { std::vector generateTestInputs() { TestEnvironment::exec({TestEnvironment::runfilesPath( - "test/common/json/config_schemas_test_data/generate_test_data.py")}); + "test/common/json/config_schemas_test_data/generate_test_data")}); std::string test_path = TestEnvironment::temporaryDirectory() + "/config_schemas_test"; return TestUtility::listFiles(test_path, false); diff --git a/test/common/json/config_schemas_test_data/BUILD b/test/common/json/config_schemas_test_data/BUILD new file mode 100644 index 0000000000000..1665e3fff4020 --- /dev/null +++ b/test/common/json/config_schemas_test_data/BUILD @@ -0,0 +1,11 @@ +package(default_visibility = ["//visibility:public"]) + +load("//bazel:envoy_build_system.bzl", "envoy_py_test_binary") + +envoy_py_test_binary( + name = "generate_test_data", + srcs = [ + "generate_test_data.py", + "util.py", + ], +) diff --git a/test/common/runtime/filesystem_setup.sh b/test/common/runtime/filesystem_setup.sh index bc285c67f4792..a14db0e1ed2dd 100755 --- a/test/common/runtime/filesystem_setup.sh +++ b/test/common/runtime/filesystem_setup.sh @@ -4,5 +4,6 @@ set -e cd ${TEST_SRCDIR}/${TEST_WORKSPACE} cp -rfL --parents test/common/runtime/test_data ${TEST_TMPDIR} +chmod -R u+rwX ${TEST_TMPDIR}/test/common/runtime/test_data ln -sf ${TEST_TMPDIR}/test/common/runtime/test_data/root ${TEST_TMPDIR}/test/common/runtime/test_data/current ln -sf ${TEST_TMPDIR}/test/common/runtime/test_data/root/envoy/subdir ${TEST_TMPDIR}/test/common/runtime/test_data/root/envoy/badlink From 53d7d27b29d5b1fe5a53af2d24d0858202d74500 Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Mon, 24 Apr 2017 05:39:15 -0400 Subject: [PATCH 2/2] Fix missing test issue and check number of tests loaded explicitly. --- test/common/json/config_schemas_test.cc | 4 +++- test/common/json/config_schemas_test_data/BUILD | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/common/json/config_schemas_test.cc b/test/common/json/config_schemas_test.cc index 6c0d3d94c46a8..ddfb5c7d389ed 100644 --- a/test/common/json/config_schemas_test.cc +++ b/test/common/json/config_schemas_test.cc @@ -20,7 +20,9 @@ std::vector generateTestInputs() { "test/common/json/config_schemas_test_data/generate_test_data")}); std::string test_path = TestEnvironment::temporaryDirectory() + "/config_schemas_test"; - return TestUtility::listFiles(test_path, false); + auto file_list = TestUtility::listFiles(test_path, false); + EXPECT_EQ(17, file_list.size()); + return file_list; } class ConfigSchemasTest : public ::testing::TestWithParam {}; diff --git a/test/common/json/config_schemas_test_data/BUILD b/test/common/json/config_schemas_test_data/BUILD index 1665e3fff4020..bc850f5e1e888 100644 --- a/test/common/json/config_schemas_test_data/BUILD +++ b/test/common/json/config_schemas_test_data/BUILD @@ -7,5 +7,5 @@ envoy_py_test_binary( srcs = [ "generate_test_data.py", "util.py", - ], + ] + glob(["test_*.py"]), )