Skip to content

Commit

Permalink
update unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: Joshua Marantz <[email protected]>
  • Loading branch information
jmarantz committed Aug 24, 2023
1 parent c8a6417 commit e97079d
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 128 deletions.
36 changes: 9 additions & 27 deletions test/common/json/json_streamer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,61 +35,43 @@ TEST_F(JsonStreamerTest, EmptyMap) {

TEST_F(JsonStreamerTest, MapOneNumber) {
Streamer::MapPtr map = streamer_.makeRootMap();
map->newEntries({{"a", "0"}});
map->addEntries({{"a", 0.0}});
streamer_.clear();
EXPECT_EQ(R"EOF({"a":0})EOF", buffer_.toString());
}

TEST_F(JsonStreamerTest, MapTwoNumbers) {
Streamer::MapPtr map = streamer_.makeRootMap();
map->newEntries({{"a", "0"}, {"b", "1"}});
map->addEntries({{"a", 0.0}, {"b", 1.0}});
streamer_.clear();
EXPECT_EQ(R"EOF({"a":0,"b":1})EOF", buffer_.toString());
}

TEST_F(JsonStreamerTest, MapOneString) {
Streamer::MapPtr map = streamer_.makeRootMap();
map->newEntries({{"a", Streamer::quote("b")}});
map->addEntries({{"a", "b"}});
streamer_.clear();
EXPECT_EQ(R"EOF({"a":"b"})EOF", buffer_.toString());
}

TEST_F(JsonStreamerTest, MapOneSanitized) {
Streamer::MapPtr map = streamer_.makeRootMap();
map->newKey("a", [&map]() { map->addSanitized("\b\001"); });
map->newKey("a");
map->addString("\b\001");
streamer_.clear();
EXPECT_EQ(R"EOF({"a":"\b\u0001"})EOF", buffer_.toString());
}

TEST_F(JsonStreamerTest, MapTwoSanitized) {
Streamer::MapPtr map = streamer_.makeRootMap();
map->newKey("a", [&map]() { map->addSanitized("\b\001"); });
map->newKey("b", [&map]() { map->addSanitized("\r\002"); });
map->newKey("a");
map->addString("\b\001");
map->newKey("b");
map->addString("\r\002");
streamer_.clear();
EXPECT_EQ(R"EOF({"a":"\b\u0001","b":"\r\u0002"})EOF", buffer_.toString());
}

TEST_F(JsonStreamerTest, MapOneDeferred) {
Streamer::MapPtr map = streamer_.makeRootMap();
Json::Streamer::Map::DeferredValuePtr deferred_value;
map->newKey("a", [&map, &deferred_value]() { deferred_value = map->deferValue(); });
map->newArray();
streamer_.clear();
EXPECT_EQ(R"EOF({"a":[]})EOF", buffer_.toString());
}

TEST_F(JsonStreamerTest, MapTwoDeferred) {
Streamer::MapPtr map = streamer_.makeRootMap();
Json::Streamer::Map::DeferredValuePtr deferred_value;
map->newKey("a", [&map, &deferred_value]() { deferred_value = map->deferValue(); });
map->newArray();
deferred_value.reset();
map->newKey("b", [&map, &deferred_value]() { deferred_value = map->deferValue(); });
map->newMap();
streamer_.clear();
EXPECT_EQ(R"EOF({"a":[],"b":{}})EOF", buffer_.toString());
}

// https://storage.googleapis.com/envoy-pr/1a4c83a/coverage/source/common/json/json_streamer.cc.gcov.html

} // namespace
Expand Down
52 changes: 26 additions & 26 deletions test/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -817,32 +817,32 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "integration_admin_test",
size = "large",
srcs = envoy_select_admin_functionality(
[
"integration_admin_test.cc",
"integration_admin_test.h",
],
),
tags = [
"cpu:3",
],
deps = [
":http_protocol_integration_lib",
"//envoy/http:header_map_interface",
"//source/common/stats:histogram_lib",
"//source/common/stats:stats_matcher_lib",
"//source/extensions/filters/http/buffer:config",
"//test/common/stats:stat_test_utility_lib",
"@envoy_api//envoy/admin/v3:pkg_cc_proto",
"@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/metrics/v3:pkg_cc_proto",
"@envoy_api//envoy/config/route/v3:pkg_cc_proto",
],
)
#envoy_cc_test(
# name = "integration_admin_test",
# size = "large",
# srcs = envoy_select_admin_functionality(
# [
# "integration_admin_test.cc",
# "integration_admin_test.h",
# ],
# ),
# tags = [
# "cpu:3",
# ],
# deps = [
# ":http_protocol_integration_lib",
# "//envoy/http:header_map_interface",
# "//source/common/stats:histogram_lib",
# "//source/common/stats:stats_matcher_lib",
# "//source/extensions/filters/http/buffer:config",
# "//test/common/stats:stat_test_utility_lib",
# "@envoy_api//envoy/admin/v3:pkg_cc_proto",
# "@envoy_api//envoy/config/bootstrap/v3:pkg_cc_proto",
# "@envoy_api//envoy/config/core/v3:pkg_cc_proto",
# "@envoy_api//envoy/config/metrics/v3:pkg_cc_proto",
# "@envoy_api//envoy/config/route/v3:pkg_cc_proto",
# ],
#)

envoy_proto_library(
name = "test_host_predicate_proto",
Expand Down
148 changes: 73 additions & 75 deletions test/server/admin/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_benchmark_binary",
"envoy_cc_test",
"envoy_cc_test_library",
"envoy_package",
"envoy_select_admin_functionality",
"envoy_select_admin_html",
)

licenses(["notice"]) # Apache 2
Expand Down Expand Up @@ -67,30 +65,30 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "admin_html_test",
srcs = envoy_select_admin_html(["admin_html_test.cc"]),
deps = [
":admin_instance_lib",
"//source/server/admin:admin_lib",
],
)

envoy_cc_test(
name = "stats_handler_test",
srcs = envoy_select_admin_functionality(["stats_handler_test.cc"]),
deps = [
":admin_instance_lib",
"//source/common/common:regex_lib",
"//source/common/stats:thread_local_store_lib",
"//source/common/thread_local:thread_local_lib",
"//source/server/admin:utils_lib",
"//test/mocks/server:admin_stream_mocks",
"//test/test_common:logging_lib",
"//test/test_common:real_threads_test_helper_lib",
"//test/test_common:utility_lib",
],
)
#envoy_cc_test(
# name = "admin_html_test",
# srcs = envoy_select_admin_html(["admin_html_test.cc"]),
# deps = [
# ":admin_instance_lib",
# "//source/server/admin:admin_lib",
# ],
#)

#envoy_cc_test(
# name = "stats_handler_test",
# srcs = envoy_select_admin_functionality(["stats_handler_test.cc"]),
# deps = [
# ":admin_instance_lib",
# "//source/common/common:regex_lib",
# "//source/common/stats:thread_local_store_lib",
# "//source/common/thread_local:thread_local_lib",
# "//source/server/admin:utils_lib",
# "//test/mocks/server:admin_stream_mocks",
# "//test/test_common:logging_lib",
# "//test/test_common:real_threads_test_helper_lib",
# "//test/test_common:utility_lib",
# ],
#)

envoy_cc_test(
name = "stats_params_test",
Expand All @@ -101,55 +99,55 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "stats_render_test",
srcs = envoy_select_admin_functionality(["stats_render_test.cc"]) + envoy_select_admin_html([
"stats_html_render_test.cc",
]),
deps = [
":stats_render_test_base",
"//source/server/admin:admin_lib",
],
)

envoy_cc_test_library(
name = "stats_render_test_base",
srcs = envoy_select_admin_functionality(["stats_render_test_base.cc"]),
hdrs = ["stats_render_test_base.h"],
deps = [
"//source/common/stats:thread_local_store_lib",
"//source/server/admin:stats_request_lib",
"//test/mocks/event:event_mocks",
"//test/mocks/stats:stats_mocks",
"//test/mocks/thread_local:thread_local_mocks",
"//test/test_common:utility_lib",
],
)

envoy_cc_test(
name = "stats_request_test",
srcs = envoy_select_admin_functionality(["stats_request_test.cc"]),
deps = [
"//source/common/stats:thread_local_store_lib",
"//source/server/admin:stats_request_lib",
"//test/mocks/event:event_mocks",
"//test/mocks/stats:stats_mocks",
"//test/mocks/thread_local:thread_local_mocks",
"//test/test_common:utility_lib",
],
)

envoy_cc_benchmark_binary(
name = "stats_handler_speed_test",
srcs = envoy_select_admin_functionality(["stats_handler_speed_test.cc"]),
deps = [
"//source/common/buffer:buffer_lib",
"//source/common/http:header_map_lib",
"//source/common/stats:thread_local_store_lib",
"//source/server/admin:admin_lib",
"//test/common/stats:real_thread_test_base",
],
)
#envoy_cc_test(
# name = "stats_render_test",
# srcs = envoy_select_admin_functionality(["stats_render_test.cc"]) + envoy_select_admin_html([
# "stats_html_render_test.cc",
# ]),
# deps = [
# ":stats_render_test_base",
# "//source/server/admin:admin_lib",
# ],
#)
#
#envoy_cc_test_library(
# name = "stats_render_test_base",
# srcs = envoy_select_admin_functionality(["stats_render_test_base.cc"]),
# hdrs = ["stats_render_test_base.h"],
# deps = [
# "//source/common/stats:thread_local_store_lib",
# "//source/server/admin:stats_request_lib",
# "//test/mocks/event:event_mocks",
# "//test/mocks/stats:stats_mocks",
# "//test/mocks/thread_local:thread_local_mocks",
# "//test/test_common:utility_lib",
# ],
#)
#
#envoy_cc_test(
# name = "stats_request_test",
# srcs = envoy_select_admin_functionality(["stats_request_test.cc"]),
# deps = [
# "//source/common/stats:thread_local_store_lib",
# "//source/server/admin:stats_request_lib",
# "//test/mocks/event:event_mocks",
# "//test/mocks/stats:stats_mocks",
# "//test/mocks/thread_local:thread_local_mocks",
# "//test/test_common:utility_lib",
# ],
#)
#
#envoy_cc_benchmark_binary(
# name = "stats_handler_speed_test",
# srcs = envoy_select_admin_functionality(["stats_handler_speed_test.cc"]),
# deps = [
# "//source/common/buffer:buffer_lib",
# "//source/common/http:header_map_lib",
# "//source/common/stats:thread_local_store_lib",
# "//source/server/admin:admin_lib",
# "//test/common/stats:real_thread_test_base",
# ],
#)

envoy_cc_test(
name = "utils_test",
Expand Down

0 comments on commit e97079d

Please sign in to comment.