Skip to content

Commit

Permalink
test: allowing bootstrap config in integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed May 16, 2023
1 parent e45360d commit fa09dcb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 22 deletions.
10 changes: 5 additions & 5 deletions mobile/test/common/integration/base_client_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ Platform::LogLevel getPlatformLogLevelFromOptions() {
// Use the Envoy mobile default config as much as possible in this test.
// There are some config modifiers below which do result in deltas.
// Note: This function is only used to build the Engine if `override_builder_config_` is true.
std::string defaultConfig() {
envoy::config::bootstrap::v3::Bootstrap defaultConfig() {
Platform::EngineBuilder builder;
std::unique_ptr<envoy::config::bootstrap::v3::Bootstrap> bootstrap = builder.generateBootstrap();
return MessageUtil::getYamlStringFromMessage(*bootstrap);
envoy::config::bootstrap::v3::Bootstrap to_return = *bootstrap;
return to_return;
}

BaseClientIntegrationTest::BaseClientIntegrationTest(Network::Address::IpVersion ip_version,
const std::string& bootstrap_config)
: BaseIntegrationTest(ip_version, bootstrap_config) {
BaseClientIntegrationTest::BaseClientIntegrationTest(Network::Address::IpVersion ip_version)
: BaseIntegrationTest(BaseIntegrationTest::defaultAddressFunction(ip_version), ip_version, defaultConfig()) {
skip_tag_extraction_rule_check_ = true;
full_dispatcher_ = api_->allocateDispatcher("fake_envoy_mobile");
use_lds_ = false;
Expand Down
5 changes: 2 additions & 3 deletions mobile/test/common/integration/base_client_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Http::ResponseHeaderMapPtr toResponseHeaders(envoy_headers headers);

// Creates a default bootstrap config from the EngineBuilder.
// Only used to build the Engine if `override_builder_config_` is set to true.
std::string defaultConfig();
envoy::config::bootstrap::v3::Bootstrap defaultConfig();

// A base class for Envoy Mobile client integration tests which interact with Envoy through the
// Http::Client class.
Expand All @@ -38,8 +38,7 @@ std::string defaultConfig();
// into a test lib.
class BaseClientIntegrationTest : public BaseIntegrationTest {
public:
BaseClientIntegrationTest(Network::Address::IpVersion ip_version,
const std::string& bootstrap_config = defaultConfig());
BaseClientIntegrationTest(Network::Address::IpVersion ip_version);
virtual ~BaseClientIntegrationTest() = default;
// Note: This class does not inherit from testing::Test and so this TearDown() method
// does not override testing::Test::TearDown(). As a result, it will not be called
Expand Down
17 changes: 13 additions & 4 deletions test/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#include "gtest/gtest.h"

namespace Envoy {
namespace {
envoy::config::bootstrap::v3::Bootstrap&
basicBootstrap(envoy::config::bootstrap::v3::Bootstrap& bootstrap, std::string& config) {
TestUtility::loadFromYaml(config, bootstrap);
return bootstrap;
}
} // namespace

std::string ConfigHelper::baseConfigNoListeners() {
return fmt::format(R"EOF(
Expand Down Expand Up @@ -721,11 +728,13 @@ envoy::config::endpoint::v3::Endpoint ConfigHelper::buildEndpoint(const std::str
return endpoint;
}

ConfigHelper::ConfigHelper(const Network::Address::IpVersion version, Api::Api& api,
const std::string& config) {
ConfigHelper::ConfigHelper(const Network::Address::IpVersion version, Api::Api&, std::string config)
: ConfigHelper(version, basicBootstrap(bootstrap_, config)) {}

ConfigHelper::ConfigHelper(const Network::Address::IpVersion version,
envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
RELEASE_ASSERT(!finalized_, "");
std::string filename = TestEnvironment::writeStringToFileForTest("basic_config.yaml", config);
TestUtility::loadFromFile(filename, bootstrap_, api);
bootstrap_ = bootstrap;

// Fix up all the socket addresses with the correct version.
auto* admin = bootstrap_.mutable_admin();
Expand Down
8 changes: 6 additions & 2 deletions test/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,17 @@ class ConfigHelper {
absl::optional<uint32_t> max_verify_depth_{absl::nullopt};
};

// Sets up config with the provided bootstrap.
ConfigHelper(const Network::Address::IpVersion version,
envoy::config::bootstrap::v3::Bootstrap& bootstrap);

// Set up basic config, using the specified IpVersion for all connections: listeners, upstream,
// and admin connections.
//
// By default, this runs with an L7 proxy config, but config can be set to TCP_PROXY_CONFIG
// to test L4 proxying.
ConfigHelper(const Network::Address::IpVersion version, Api::Api& api,
const std::string& config = httpProxyConfig(false, false));
ConfigHelper(const Network::Address::IpVersion version, Api::Api&,
std::string config = httpProxyConfig(false, false));

static void
initializeTls(const ServerSslOptions& options,
Expand Down
30 changes: 22 additions & 8 deletions test/integration/base_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
#include "gtest/gtest.h"

namespace Envoy {
envoy::config::bootstrap::v3::Bootstrap configToBootstrap(const std::string& config) {
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(config, bootstrap);
return bootstrap;
}

using ::testing::_;
using ::testing::AssertionFailure;
using ::testing::AssertionResult;
Expand All @@ -40,13 +46,13 @@ using ::testing::ReturnRef;

BaseIntegrationTest::BaseIntegrationTest(const InstanceConstSharedPtrFn& upstream_address_fn,
Network::Address::IpVersion version,
const std::string& config)
envoy::config::bootstrap::v3::Bootstrap bootstrap)
: api_(Api::createApiForTest(stats_store_, time_system_)),
mock_buffer_factory_(new NiceMock<MockBufferFactory>),
dispatcher_(api_->allocateDispatcher("test_thread",
Buffer::WatermarkFactoryPtr{mock_buffer_factory_})),
version_(version), upstream_address_fn_(upstream_address_fn),
config_helper_(version, *api_, config),
config_helper_(version, bootstrap),
default_log_level_(TestEnvironment::getOptions().logLevel()) {
Envoy::Server::validateProtoDescriptors();
// This is a hack, but there are situations where we disconnect fake upstream connections and
Expand All @@ -73,14 +79,22 @@ BaseIntegrationTest::BaseIntegrationTest(const InstanceConstSharedPtrFn& upstrea
#endif
}

BaseIntegrationTest::BaseIntegrationTest(const InstanceConstSharedPtrFn& upstream_address_fn,
Network::Address::IpVersion version,
const std::string& config)
: BaseIntegrationTest(upstream_address_fn, version, configToBootstrap(config)) {}

const BaseIntegrationTest::InstanceConstSharedPtrFn
BaseIntegrationTest::defaultAddressFunction(Network::Address::IpVersion version) {
return [version](int) {
return Network::Utility::parseInternetAddress(Network::Test::getLoopbackAddressString(version),
0);
};
}

BaseIntegrationTest::BaseIntegrationTest(Network::Address::IpVersion version,
const std::string& config)
: BaseIntegrationTest(
[version](int) {
return Network::Utility::parseInternetAddress(
Network::Test::getLoopbackAddressString(version), 0);
},
version, config) {}
: BaseIntegrationTest(defaultAddressFunction(version), version, config) {}

Network::ClientConnectionPtr BaseIntegrationTest::makeClientConnection(uint32_t port) {
return makeClientConnectionWithOptions(port, nullptr);
Expand Down
4 changes: 4 additions & 0 deletions test/integration/base_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ struct ApiFilesystemConfig {
class BaseIntegrationTest : protected Logger::Loggable<Logger::Id::testing> {
public:
using InstanceConstSharedPtrFn = std::function<Network::Address::InstanceConstSharedPtr(int)>;
static const InstanceConstSharedPtrFn defaultAddressFunction(Network::Address::IpVersion version);

BaseIntegrationTest(const InstanceConstSharedPtrFn& upstream_address_fn,
Network::Address::IpVersion version,
envoy::config::bootstrap::v3::Bootstrap bootstrap);
// Creates a test fixture with an upstream bound to INADDR_ANY on an unspecified port using the
// provided IP |version|.
BaseIntegrationTest(Network::Address::IpVersion version,
Expand Down

0 comments on commit fa09dcb

Please sign in to comment.