Repository: envoyproxy/envoy
File: test/integration/ads_integration_test.cc (C++)

Code before:
  // Verify that listener_0 still works.
  send_request_and_verify("http0", Http::TestRequestHeaderMapImpl{{":method", "GET"},
                                                                  {":path", "/foo"},
                                                                  {":scheme", "http"},
                                                                  {":authority", "foo.com"}});

  // Send VHDS update to change the domain and path to bar.com and verify that requests to foo.com
  // now fail while requests to bar.com pass.
  sendDiscoveryResponse<envoy::config::route::v3::VirtualHost>(
      Config::TestTypeUrl::get().VirtualHost, {},
      {buildVirtualHost("route_config_0/foo", "bar.com", "/bar", "cluster_0")}, {}, "2");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().VirtualHost, "", {}, {}, {}));
  send_request_and_verify(
      "http0",
      Http::TestRequestHeaderMapImpl{
          {":method", "GET"}, {":path", "/foo"}, {":scheme", "http"}, {":authority", "foo.com"}},
      true);
  send_request_and_verify("http0", Http::TestRequestHeaderMapImpl{{":method", "GET"},
                                                                  {":path", "/bar"},
                                                                  {":scheme", "http"},
                                                                  {":authority", "bar.com"}});
}

// Tests that when a new listener arrives referencing an existing route config, it doesn't request
// for new VHost resources and instead uses the local copy.
TEST_P(AdsIntegrationTest, NewListenerUsesLocalVHost) {
  if (sotw_or_delta_ != Grpc::SotwOrDelta::Delta &&
      sotw_or_delta_ != Grpc::SotwOrDelta::UnifiedDelta) {
    GTEST_SKIP_("This test is for delta only");
  }
  initialize();

  // Send initial configuration that sets up 1 listeners with the following vhosts:
  // listener_0 -> route_config_0/foo
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}, true));
  sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TestTypeUrl::get().Cluster, {},
                                                             {buildCluster("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().ClusterLoadAssignment, "", {},
                                      {"cluster_0"}, {}));
  sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
      Config::TestTypeUrl::get().ClusterLoadAssignment, {},
      {buildClusterLoadAssignment("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}));

  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Listener, "", {}, {}, {}));
  sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
      Config::TestTypeUrl::get().Listener, {}, {buildListener("listener_0", "route_config_0")}, {},
      "1");

  EXPECT_TRUE(
      compareDiscoveryRequest(Config::TestTypeUrl::get().ClusterLoadAssignment, "", {}, {}, {}));

Review comment (suggestion):
In this test the listeners use the same route and not the same virtual-host. I think it should be kept. Please rename and clarify in the comments.
We'll add the multiple-routes using the same virtual-host ADS later (I assume that test will not pass).

Code after:
  // Verify that listener_0 still works.
  send_request_and_verify("http0", Http::TestRequestHeaderMapImpl{{":method", "GET"},
                                                                  {":path", "/foo"},
                                                                  {":scheme", "http"},
                                                                  {":authority", "foo.com"}});

  // Send VHDS update to change the domain and path to bar.com and verify that requests to foo.com
  // now fail while requests to bar.com pass.
  sendDiscoveryResponse<envoy::config::route::v3::VirtualHost>(
      Config::TestTypeUrl::get().VirtualHost, {},
      {buildVirtualHost("route_config_0/foo", "bar.com", "/bar", "cluster_0")}, {}, "2");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().VirtualHost, "", {}, {}, {}));
  send_request_and_verify(
      "http0",
      Http::TestRequestHeaderMapImpl{
          {":method", "GET"}, {":path", "/foo"}, {":scheme", "http"}, {":authority", "foo.com"}},
      true);
  send_request_and_verify("http0", Http::TestRequestHeaderMapImpl{{":method", "GET"},
                                                                  {":path", "/bar"},
                                                                  {":scheme", "http"},
                                                                  {":authority", "bar.com"}});
}

// Tests that when a new listener arrives referencing an existing route config, it doesn't request
// for new route config resources and instead uses the local copy.
TEST_P(AdsIntegrationTest, NewListenerUsesLocalRouteConfig) {
  if (sotw_or_delta_ != Grpc::SotwOrDelta::Delta &&
      sotw_or_delta_ != Grpc::SotwOrDelta::UnifiedDelta) {
    GTEST_SKIP_("This test is for delta only");
  }
  initialize();

  // Send initial configuration that sets up 1 listeners with the following vhosts:
  // listener_0 -> route_config_0/foo
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}, true));
  sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TestTypeUrl::get().Cluster, {},
                                                             {buildCluster("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().ClusterLoadAssignment, "", {},
                                      {"cluster_0"}, {}));
  sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
      Config::TestTypeUrl::get().ClusterLoadAssignment, {},
      {buildClusterLoadAssignment("cluster_0")}, {}, "1");
  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Cluster, "", {}, {}, {}));

  EXPECT_TRUE(compareDiscoveryRequest(Config::TestTypeUrl::get().Listener, "", {}, {}, {}));
  sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
      Config::TestTypeUrl::get().Listener, {}, {buildListener("listener_0", "route_config_0")}, {},
      "1");

  EXPECT_TRUE(
      compareDiscoveryRequest(Config::TestTypeUrl::get().ClusterLoadAssignment, "", {}, {}, {}));