Skip to content

Commit

Permalink
coverage: improve coverage for compressor filter (envoyproxy#11438)
Browse files Browse the repository at this point in the history
coverage: improve coverage for compressor filter
Risk Level: Low
Testing: generated coverage report locally

Signed-off-by: Dmitry Rozhkov <[email protected]>
  • Loading branch information
rojkov authored Jun 5, 2020
1 parent f0464a4 commit 8161b91
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 1 deletion.
21 changes: 21 additions & 0 deletions test/extensions/filters/http/compressor/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_package",
"envoy_proto_library",
)
load(
"//test/extensions:extensions_build_system.bzl",
Expand Down Expand Up @@ -41,3 +42,23 @@ envoy_extension_cc_test(
"//test/test_common:utility_lib",
],
)

envoy_proto_library(
name = "mock_config",
srcs = ["mock_compressor_library.proto"],
)

envoy_extension_cc_test(
name = "config_test",
srcs = [
"config_test.cc",
],
extension_name = "envoy.filters.http.compressor",
deps = [
":mock_config_cc_proto",
"//source/extensions/filters/http/compressor:config",
"//test/mocks/runtime:runtime_mocks",
"//test/mocks/server:server_mocks",
"//test/test_common:utility_lib",
],
)
46 changes: 46 additions & 0 deletions test/extensions/filters/http/compressor/config_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "extensions/filters/http/compressor/config.h"

#include "test/mocks/server/mocks.h"

#include "gtest/gtest.h"

namespace Envoy {
namespace Extensions {
namespace HttpFilters {
namespace Compressor {
namespace {

using testing::NiceMock;

TEST(CompressorFilterFactoryTests, MissingCompressorLibraryConfig) {
const envoy::extensions::filters::http::compressor::v3::Compressor proto_config;
CompressorFilterFactory factory;
NiceMock<Server::Configuration::MockFactoryContext> context;
EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context),
EnvoyException,
"Compressor filter doesn't have compressor_library defined");
}

TEST(CompressorFilterFactoryTests, UnregisteredCompressorLibraryConfig) {
const std::string yaml_string = R"EOF(
compressor_library:
name: fake_compressor
typed_config:
"@type": type.googleapis.com/test.mock_compressor_library.Unregistered
)EOF";

envoy::extensions::filters::http::compressor::v3::Compressor proto_config;
TestUtility::loadFromYaml(yaml_string, proto_config);
CompressorFilterFactory factory;
NiceMock<Server::Configuration::MockFactoryContext> context;
EXPECT_THROW_WITH_MESSAGE(factory.createFilterFactoryFromProto(proto_config, "stats", context),
EnvoyException,
"Didn't find a registered implementation for type: "
"'test.mock_compressor_library.Unregistered'");
}

} // namespace
} // namespace Compressor
} // namespace HttpFilters
} // namespace Extensions
} // namespace Envoy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";

package test.mock_compressor_library;

message Unregistered {
}
1 change: 0 additions & 1 deletion test/per_file_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ declare -a KNOWN_LOW_COVERAGE=(
"source/extensions/filters/http/cache/simple_http_cache:84.5"
"source/extensions/filters/http/csrf:96.6"
"source/extensions/filters/http/ip_tagging:92.0"
"source/extensions/filters/http/compressor:84.4"
"source/extensions/filters/http/header_to_metadata:95.0"
"source/extensions/filters/http/grpc_json_transcoder:93.3"
"source/extensions/filters/http/aws_request_signing:93.3"
Expand Down

0 comments on commit 8161b91

Please sign in to comment.