summaryrefslogtreecommitdiffstats
path: root/src/shrpx_worker_test.cc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/shrpx_worker_test.cc305
1 files changed, 173 insertions, 132 deletions
diff --git a/src/shrpx_worker_test.cc b/src/shrpx_worker_test.cc
index 7c5c329..4b4b7a6 100644
--- a/src/shrpx_worker_test.cc
+++ b/src/shrpx_worker_test.cc
@@ -30,7 +30,7 @@
#include <cstdlib>
-#include <CUnit/CUnit.h>
+#include "munitxx.h"
#include "shrpx_worker.h"
#include "shrpx_connect_blocker.h"
@@ -38,6 +38,17 @@
namespace shrpx {
+namespace {
+const MunitTest tests[]{
+ munit_void_test(test_shrpx_worker_match_downstream_addr_group),
+ munit_test_end(),
+};
+} // namespace
+
+const MunitSuite worker_suite{
+ "/worker", tests, NULL, 1, MUNIT_SUITE_OPTION_NONE,
+};
+
void test_shrpx_worker_match_downstream_addr_group(void) {
auto groups = std::vector<std::shared_ptr<DownstreamAddrGroup>>();
for (auto &s : {"nghttp2.org/", "nghttp2.org/alpha/bravo/",
@@ -62,131 +73,155 @@ void test_shrpx_worker_match_downstream_addr_group(void) {
router.add_route(StringRef{g->pattern}, i);
}
- CU_ASSERT(0 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(0, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/"), groups, 255, balloc));
// port is removed
- CU_ASSERT(0 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org:8080"),
- StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(0, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org:8080"),
+ StringRef::from_lit("/"), groups, 255, balloc));
// host is case-insensitive
- CU_ASSERT(4 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("WWW.nghttp2.org"),
- StringRef::from_lit("/alpha"), groups, 255, balloc));
+ assert_size(4, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("WWW.nghttp2.org"),
+ StringRef::from_lit("/alpha"), groups, 255, balloc));
- CU_ASSERT(1 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/bravo/"), groups, 255,
- balloc));
+ assert_size(1, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/bravo/"), groups, 255, balloc));
// /alpha/bravo also matches /alpha/bravo/
- CU_ASSERT(1 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/bravo"), groups, 255, balloc));
+ assert_size(1, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/bravo"), groups, 255, balloc));
// path part is case-sensitive
- CU_ASSERT(0 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/Alpha/bravo"), groups, 255, balloc));
-
- CU_ASSERT(1 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/bravo/charlie"), groups, 255,
- balloc));
-
- CU_ASSERT(2 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/charlie"), groups, 255,
- balloc));
+ assert_size(0, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/Alpha/bravo"), groups, 255, balloc));
+
+ assert_size(1, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/bravo/charlie"), groups, 255,
+ balloc));
+
+ assert_size(2, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/charlie"), groups, 255, balloc));
// pattern which does not end with '/' must match its entirely. So
// this matches to group 0, not group 2.
- CU_ASSERT(0 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/charlie/"), groups, 255,
- balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("example.org"),
- StringRef::from_lit("/"), groups, 255, balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit(""),
- StringRef::from_lit("/"), groups, 255, balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit(""),
- StringRef::from_lit("alpha"), groups, 255, balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("foo/bar"),
- StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(0, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/charlie/"), groups, 255, balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("example.org"),
+ StringRef::from_lit("/"), groups, 255, balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(routerconf, StringRef::from_lit(""),
+ StringRef::from_lit("/"), groups, 255,
+ balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(routerconf, StringRef::from_lit(""),
+ StringRef::from_lit("alpha"), groups,
+ 255, balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("foo/bar"),
+ StringRef::from_lit("/"), groups, 255, balloc));
// If path is StringRef::from_lit("*", only match with host + "/").
- CU_ASSERT(0 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("*"), groups, 255, balloc));
-
- CU_ASSERT(5 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("[::1]"),
- StringRef::from_lit("/"), groups, 255, balloc));
- CU_ASSERT(5 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("[::1]:8080"),
- StringRef::from_lit("/"), groups, 255, balloc));
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("[::1"),
- StringRef::from_lit("/"), groups, 255, balloc));
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("[::1]8000"),
- StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(0, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("*"), groups, 255, balloc));
+
+ assert_size(5, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("[::1]"),
+ StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(5, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("[::1]:8080"),
+ StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("[::1"),
+ StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("[::1]8000"),
+ StringRef::from_lit("/"), groups, 255, balloc));
// Check the case where adding route extends tree
- CU_ASSERT(6 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/bravo/delta"), groups, 255,
- balloc));
-
- CU_ASSERT(1 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/alpha/bravo/delta/"), groups, 255,
- balloc));
+ assert_size(6, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/bravo/delta"), groups, 255,
+ balloc));
+
+ assert_size(1, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/alpha/bravo/delta/"), groups, 255,
+ balloc));
// Check the case where query is done in a single node
- CU_ASSERT(7 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("example.com"),
- StringRef::from_lit("/alpha/bravo"), groups, 255, balloc));
+ assert_size(7, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("example.com"),
+ StringRef::from_lit("/alpha/bravo"), groups, 255, balloc));
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("example.com"),
- StringRef::from_lit("/alpha/bravo/"), groups, 255,
- balloc));
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("example.com"),
+ StringRef::from_lit("/alpha/bravo/"), groups, 255, balloc));
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("example.com"),
- StringRef::from_lit("/alpha"), groups, 255, balloc));
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("example.com"),
+ StringRef::from_lit("/alpha"), groups, 255, balloc));
// Check the case where quey is done in a single node
- CU_ASSERT(8 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("192.168.0.1"),
- StringRef::from_lit("/alpha"), groups, 255, balloc));
-
- CU_ASSERT(8 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("192.168.0.1"),
- StringRef::from_lit("/alpha/"), groups, 255, balloc));
-
- CU_ASSERT(8 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("192.168.0.1"),
- StringRef::from_lit("/alpha/bravo"), groups, 255, balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("192.168.0.1"),
- StringRef::from_lit("/alph"), groups, 255, balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("192.168.0.1"),
- StringRef::from_lit("/"), groups, 255, balloc));
+ assert_size(8, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("192.168.0.1"),
+ StringRef::from_lit("/alpha"), groups, 255, balloc));
+
+ assert_size(8, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("192.168.0.1"),
+ StringRef::from_lit("/alpha/"), groups, 255, balloc));
+
+ assert_size(8, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("192.168.0.1"),
+ StringRef::from_lit("/alpha/bravo"), groups, 255, balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("192.168.0.1"),
+ StringRef::from_lit("/alph"), groups, 255, balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("192.168.0.1"),
+ StringRef::from_lit("/"), groups, 255, balloc));
// Test for wildcard hosts
auto g1 = std::make_shared<DownstreamAddrGroup>();
@@ -214,34 +249,40 @@ void test_shrpx_worker_match_downstream_addr_group(void) {
wcrouter.add_route(StringRef::from_lit("lacol."), 2);
wp.back().router.add_route(StringRef::from_lit("/"), 13);
- CU_ASSERT(11 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("git.nghttp2.org"),
- StringRef::from_lit("/echo"), groups, 255, balloc));
-
- CU_ASSERT(10 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("0git.nghttp2.org"),
- StringRef::from_lit("/echo"), groups, 255, balloc));
-
- CU_ASSERT(11 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("it.nghttp2.org"),
- StringRef::from_lit("/echo"), groups, 255, balloc));
-
- CU_ASSERT(255 == match_downstream_addr_group(
- routerconf, StringRef::from_lit(".nghttp2.org"),
- StringRef::from_lit("/echo/foxtrot"), groups, 255,
- balloc));
-
- CU_ASSERT(9 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("alpha.nghttp2.org"),
- StringRef::from_lit("/golf"), groups, 255, balloc));
-
- CU_ASSERT(0 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("nghttp2.org"),
- StringRef::from_lit("/echo"), groups, 255, balloc));
-
- CU_ASSERT(13 == match_downstream_addr_group(
- routerconf, StringRef::from_lit("test.local"),
- StringRef{}, groups, 255, balloc));
+ assert_size(11, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("git.nghttp2.org"),
+ StringRef::from_lit("/echo"), groups, 255, balloc));
+
+ assert_size(10, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("0git.nghttp2.org"),
+ StringRef::from_lit("/echo"), groups, 255, balloc));
+
+ assert_size(11, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("it.nghttp2.org"),
+ StringRef::from_lit("/echo"), groups, 255, balloc));
+
+ assert_size(255, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit(".nghttp2.org"),
+ StringRef::from_lit("/echo/foxtrot"), groups, 255, balloc));
+
+ assert_size(9, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("alpha.nghttp2.org"),
+ StringRef::from_lit("/golf"), groups, 255, balloc));
+
+ assert_size(0, ==,
+ match_downstream_addr_group(
+ routerconf, StringRef::from_lit("nghttp2.org"),
+ StringRef::from_lit("/echo"), groups, 255, balloc));
+
+ assert_size(13, ==,
+ match_downstream_addr_group(routerconf,
+ StringRef::from_lit("test.local"),
+ StringRef{}, groups, 255, balloc));
}
} // namespace shrpx