Repository: envoyproxy/envoy
File: test/extensions/dynamic_modules/http/integration_test.cc (C++)

Code before:
    EXPECT_EQ(TestUtility::readSampleCount(test_server_->server().dispatcher(),
                                           *request_entrypoint_header_values),
              2);
    EXPECT_EQ(static_cast<int>(TestUtility::readSampleSum(test_server_->server().dispatcher(),
                                                          *request_entrypoint_header_values)),
              3 + 13);

    Http::TestResponseHeaderMapImpl response_headers = default_response_headers_;
    response_headers.addCopy(Http::LowerCaseString("header_to_count"), "5");
    response_headers.addCopy(Http::LowerCaseString("header_to_set"), "1000");
    upstream_request_->encodeHeaders(response_headers, true);
    ASSERT_TRUE(response->waitForEndStream());
    EXPECT_TRUE(response->complete());
  }
}

std::string terminal_filter_config;

class DynamicModulesTerminalIntegrationTest
    : public testing::TestWithParam<Network::Address::IpVersion>,
      public HttpIntegrationTest {
public:
  DynamicModulesTerminalIntegrationTest()
      : HttpIntegrationTest(Http::CodecType::HTTP2, GetParam(), terminal_filter_config) {};

  static void SetUpTestSuite() { // NOLINT(readability-identifier-naming)
    terminal_filter_config = absl::StrCat(ConfigHelper::baseConfig(), R"EOF(
    filter_chains:
      filters:
        name: envoy.filters.network.http_connection_manager
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          http_filters:
          - name: http_integration_test
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.filters.http.dynamic_modules.v3.DynamicModuleFilter
              dynamic_module_config:
                name: http_integration_test
                terminal_filter: true
              filter_name: streaming_terminal_filter
          route_config:
            virtual_hosts:
            - domains:
              - '*'
              name: local_proxy_route
          stat_prefix: ingress_http
      )EOF");
  }

  void SetUp() override { HttpIntegrationTest::initialize(); }
};

Review comment (suggestion):
I followed the pattern of EchoIntegrationTest for a terminal filter but let me know if there are any better patterns for setting up a config for a filter chain with no upstream.

Code after:
    EXPECT_EQ(TestUtility::readSampleCount(test_server_->server().dispatcher(),
                                           *request_entrypoint_header_values),
              2);
    EXPECT_EQ(static_cast<int>(TestUtility::readSampleSum(test_server_->server().dispatcher(),
                                                          *request_entrypoint_header_values)),
              3 + 13);

    Http::TestResponseHeaderMapImpl response_headers = default_response_headers_;
    response_headers.addCopy(Http::LowerCaseString("header_to_count"), "5");
    response_headers.addCopy(Http::LowerCaseString("header_to_set"), "1000");
    upstream_request_->encodeHeaders(response_headers, true);
    ASSERT_TRUE(response->waitForEndStream());
    EXPECT_TRUE(response->complete());
  }
}

std::string terminal_filter_config;

class DynamicModulesTerminalIntegrationTest
    : public testing::TestWithParam<Network::Address::IpVersion>,
      public HttpIntegrationTest {
public:
  DynamicModulesTerminalIntegrationTest()
      : HttpIntegrationTest(Http::CodecType::HTTP2, GetParam(), terminal_filter_config) {};

  static void SetUpTestSuite() { // NOLINT(readability-identifier-naming)
    terminal_filter_config = absl::StrCat(ConfigHelper::baseConfig(), R"EOF(
    filter_chains:
      filters:
        name: envoy.filters.network.http_connection_manager
        typed_config:
          '@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          http_filters:
          - name: http_integration_test
            typed_config:
              '@type': type.googleapis.com/envoy.extensions.filters.http.dynamic_modules.v3.DynamicModuleFilter
              dynamic_module_config:
                name: http_integration_test
              filter_name: streaming_terminal_filter
              terminal_filter: true
          route_config:
            virtual_hosts:
            - domains:
              - '*'
              name: local_proxy_route
          stat_prefix: ingress_http
      )EOF");
  }

  void SetUp() override { HttpIntegrationTest::initialize(); }
};