From 6f6b869a67fc020ae7f1aaf45cba6410415dbaec Mon Sep 17 00:00:00 2001 From: Bryan Call Date: Thu, 21 Nov 2019 11:37:46 +0800 Subject: [PATCH] Fixed next hop tests for out of tree builds --- proxy/http/remap/Makefile.am | 3 +++ .../remap/unit-tests/test_NextHopConsistentHash.cc | 6 +++--- proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc | 8 ++++---- .../remap/unit-tests/test_NextHopStrategyFactory.cc | 11 +++++++---- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/proxy/http/remap/Makefile.am b/proxy/http/remap/Makefile.am index 89be4da59a8..c569801ecf4 100644 --- a/proxy/http/remap/Makefile.am +++ b/proxy/http/remap/Makefile.am @@ -125,6 +125,7 @@ test_RemapPluginInfo_SOURCES = \ test_NextHopStrategyFactory_CPPFLAGS = \ $(AM_CPPFLAGS) \ -D_NH_UNIT_TESTS_ \ + -DTS_SRC_DIR=\"$(abs_top_srcdir)/proxy/http/remap/\" \ -I$(abs_top_srcdir)/tests/include \ $(TS_INCLUDES) \ @YAMLCPP_INCLUDES@ @@ -154,6 +155,7 @@ test_NextHopStrategyFactory_SOURCES = \ test_NextHopRoundRobin_CPPFLAGS = \ $(AM_CPPFLAGS) \ -D_NH_UNIT_TESTS_ \ + -DTS_SRC_DIR=\"$(abs_top_srcdir)/proxy/http/remap/\" \ -I$(abs_top_srcdir)/tests/include \ $(TS_INCLUDES) \ @YAMLCPP_INCLUDES@ @@ -183,6 +185,7 @@ test_NextHopRoundRobin_SOURCES = \ test_NextHopConsistentHash_CPPFLAGS = \ $(AM_CPPFLAGS) \ -D_NH_UNIT_TESTS_ \ + -DTS_SRC_DIR=\"$(abs_top_srcdir)/proxy/http/remap/\" \ -I$(abs_top_srcdir)/tests/include \ $(TS_INCLUDES) \ @YAMLCPP_INCLUDES@ diff --git a/proxy/http/remap/unit-tests/test_NextHopConsistentHash.cc b/proxy/http/remap/unit-tests/test_NextHopConsistentHash.cc index 172e85cf094..1deb619d57a 100644 --- a/proxy/http/remap/unit-tests/test_NextHopConsistentHash.cc +++ b/proxy/http/remap/unit-tests/test_NextHopConsistentHash.cc @@ -51,7 +51,7 @@ SCENARIO("Testing NextHopConsistentHash class, using policy 'consistent_hash'", { // load the configuration strtegies. std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/consistent-hash-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/consistent-hash-tests.yaml"); strategy = nhf.strategyInstance("consistent-hash-1"); WHEN("the config is loaded.") @@ -187,7 +187,7 @@ SCENARIO("Testing NextHopConsistentHash class (all firstcalls), using policy 'co GIVEN("Loading the consistent-hash-tests.yaml config for 'consistent_hash' tests.") { std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/consistent-hash-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/consistent-hash-tests.yaml"); strategy = nhf.strategyInstance("consistent-hash-1"); WHEN("the config is loaded.") @@ -286,7 +286,7 @@ SCENARIO("Testing NextHopConsistentHash class (alternating rings), using policy GIVEN("Loading the consistent-hash-tests.yaml config for 'consistent_hash' tests.") { std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/consistent-hash-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/consistent-hash-tests.yaml"); strategy = nhf.strategyInstance("consistent-hash-2"); WHEN("the config is loaded.") diff --git a/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc b/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc index 104efc0f09e..1b097d07293 100644 --- a/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc +++ b/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc @@ -41,7 +41,7 @@ SCENARIO("Testing NextHopRoundRobin class, using policy 'rr-strict'", "[NextHopR GIVEN("Loading the round-robin-tests.yaml config for round robin 'rr-strict' tests.") { std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/round-robin-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/round-robin-tests.yaml"); strategy = nhf.strategyInstance("rr-strict-exhaust-ring"); WHEN("the config is loaded.") @@ -143,7 +143,7 @@ SCENARIO("Testing NextHopRoundRobin class, using policy 'first-live'", "[NextHop GIVEN("Loading the round-robin-tests.yaml config for round robin 'first-live' tests.") { std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/round-robin-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/round-robin-tests.yaml"); strategy = nhf.strategyInstance("first-live"); WHEN("the config is loaded.") @@ -199,7 +199,7 @@ SCENARIO("Testing NextHopRoundRobin class, using policy 'rr-ip'", "[NextHopRound GIVEN("Loading the round-robin-tests.yaml config for round robin 'rr-ip' tests.") { std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/round-robin-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/round-robin-tests.yaml"); strategy = nhf.strategyInstance("rr-ip"); sockaddr_in sa1, sa2; sa1.sin_port = 10000; @@ -257,7 +257,7 @@ SCENARIO("Testing NextHopRoundRobin class, using policy 'latched'", "[NextHopRou GIVEN("Loading the round-robin-tests.yaml config for round robin 'latched' tests.") { std::shared_ptr strategy; - NextHopStrategyFactory nhf("unit-tests/round-robin-tests.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/round-robin-tests.yaml"); strategy = nhf.strategyInstance("latched"); WHEN("the config is loaded.") diff --git a/proxy/http/remap/unit-tests/test_NextHopStrategyFactory.cc b/proxy/http/remap/unit-tests/test_NextHopStrategyFactory.cc index 2bfc2601754..de9a71f8aa8 100644 --- a/proxy/http/remap/unit-tests/test_NextHopStrategyFactory.cc +++ b/proxy/http/remap/unit-tests/test_NextHopStrategyFactory.cc @@ -43,7 +43,10 @@ SCENARIO("factory tests loading yaml configs", "[loadConfig]") { GIVEN("Loading the strategy.yaml with included 'hosts.yaml'.") { - NextHopStrategyFactory nhf("unit-tests/strategy.yaml"); +#ifdef TS_SRC_DIR + REQUIRE(chdir(TS_SRC_DIR) == 0); +#endif + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/strategy.yaml"); WHEN("the two files are loaded.") { @@ -216,7 +219,7 @@ SCENARIO("factory tests loading yaml configs", "[loadConfig]") GIVEN("loading a yaml config, simple-strategy.yaml ") { - NextHopStrategyFactory nhf("unit-tests/simple-strategy.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/simple-strategy.yaml"); WHEN("loading the single file") { @@ -357,7 +360,7 @@ SCENARIO("factory tests loading yaml configs", "[loadConfig]") GIVEN("loading a yaml config combining hosts and strategies into one file, combined.yaml") { - NextHopStrategyFactory nhf("unit-tests/combined.yaml"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/combined.yaml"); WHEN("loading the single file") { @@ -779,7 +782,7 @@ SCENARIO("factory tests loading yaml configs from a directory", "[loadConfig]") { GIVEN("Loading the strategies using a directory of 'yaml' files") { - NextHopStrategyFactory nhf("unit-tests/strategies-dir"); + NextHopStrategyFactory nhf(TS_SRC_DIR "unit-tests/strategies-dir"); WHEN("the two files are loaded.") {