-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add config test for HeaderToMetadata filter (#7506)
Adds coverage for source/extensions/filters/http/header_to_metadata_config.cc Risk Level: Low Testing: Included Docs Changes: N/A Release Notes: N/A Signed-off-by: Derek Argueta <dereka@pinterest.com>
- Loading branch information
1 parent
e3973ec
commit 79b071c
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
test/extensions/filters/http/header_to_metadata/config_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <string> | ||
|
||
#include "envoy/config/filter/http/header_to_metadata/v2/header_to_metadata.pb.validate.h" | ||
|
||
#include "extensions/filters/http/header_to_metadata/config.h" | ||
|
||
#include "test/mocks/server/mocks.h" | ||
#include "test/test_common/utility.h" | ||
|
||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace HttpFilters { | ||
namespace HeaderToMetadataFilter { | ||
|
||
using HeaderToMetadataProtoConfig = envoy::config::filter::http::header_to_metadata::v2::Config; | ||
|
||
TEST(HeaderToMetadataFilterConfigTest, InvalidEmptyHeader) { | ||
const std::string yaml = R"EOF( | ||
request_rules: | ||
- header: "" | ||
)EOF"; | ||
|
||
HeaderToMetadataProtoConfig proto_config; | ||
EXPECT_THROW(TestUtility::loadFromYamlAndValidate(yaml, proto_config), ProtoValidationException); | ||
} | ||
|
||
TEST(HeaderToMetadataFilterConfigTest, InvalidEmptyKey) { | ||
const std::string yaml = R"EOF( | ||
request_rules: | ||
- header: x-version | ||
on_header_present: | ||
metadata_namespace: envoy.lb | ||
key: "" | ||
type: STRING | ||
)EOF"; | ||
|
||
HeaderToMetadataProtoConfig proto_config; | ||
EXPECT_THROW(TestUtility::loadFromYamlAndValidate(yaml, proto_config), ProtoValidationException); | ||
} | ||
|
||
TEST(HeaderToMetadataFilterConfigTest, SimpleConfig) { | ||
const std::string yaml = R"EOF( | ||
request_rules: | ||
- header: x-version | ||
on_header_present: | ||
metadata_namespace: envoy.lb | ||
key: version | ||
type: STRING | ||
on_header_missing: | ||
metadata_namespace: envoy.lb | ||
key: default | ||
value: 'true' | ||
type: STRING | ||
)EOF"; | ||
|
||
HeaderToMetadataProtoConfig proto_config; | ||
TestUtility::loadFromYamlAndValidate(yaml, proto_config); | ||
|
||
testing::NiceMock<Server::Configuration::MockFactoryContext> context; | ||
HeaderToMetadataConfig factory; | ||
|
||
Http::FilterFactoryCb cb = factory.createFilterFactoryFromProto(proto_config, "stats", context); | ||
Http::MockFilterChainFactoryCallbacks filter_callbacks; | ||
EXPECT_CALL(filter_callbacks, addStreamFilter(_)); | ||
cb(filter_callbacks); | ||
} | ||
|
||
} // namespace HeaderToMetadataFilter | ||
} // namespace HttpFilters | ||
} // namespace Extensions | ||
} // namespace Envoy |