Skip to content

Commit 64d6ac9

Browse files
authored
Merge pull request #28 from kh-chang/path-matcher-util
Replace std::set with std::unordered_set in path matcher utility
2 parents ba83152 + 9965c80 commit 64d6ac9

File tree

2 files changed

+62
-43
lines changed

2 files changed

+62
-43
lines changed

src/include/grpc_transcoding/path_matcher_utility.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,22 @@ class PathMatcherUtility {
2828
template <class Method>
2929
static bool RegisterByHttpRule(
3030
PathMatcherBuilder<Method> &pmb, const google::api::HttpRule &http_rule,
31-
const std::set<std::string> &system_query_parameter_names,
31+
const std::unordered_set<std::string> &system_query_parameter_names,
3232
const Method &method);
3333

3434
template <class Method>
3535
static bool RegisterByHttpRule(PathMatcherBuilder<Method> &pmb,
3636
const google::api::HttpRule &http_rule,
3737
const Method &method) {
38-
return RegisterByHttpRule(pmb, http_rule, {}, method);
38+
return RegisterByHttpRule(pmb, http_rule, std::unordered_set<std::string>(),
39+
method);
3940
}
4041
};
4142

4243
template <class Method>
4344
bool PathMatcherUtility::RegisterByHttpRule(
4445
PathMatcherBuilder<Method> &pmb, const google::api::HttpRule &http_rule,
45-
const std::set<std::string> &system_query_parameter_names,
46+
const std::unordered_set<std::string> &system_query_parameter_names,
4647
const Method &method) {
4748
bool ok = true;
4849
switch (http_rule.pattern_case()) {

test/path_matcher_utility_test.cc

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ class PathMatcherBuilder<const TestMethod*> {
3737
public:
3838
MOCK_METHOD5(Register,
3939
bool(const std::string&, const std::string&, const std::string&,
40-
const std::set<std::string>&, const TestMethod*));
40+
const std::unordered_set<std::string>&, const TestMethod*));
4141
};
42-
}
43-
}
44-
}
42+
} // namespace transcoding
43+
} // namespace grpc
44+
} // namespace google
4545

4646
class PathMatcherUtilityTest : public ::testing::Test {
4747
public:
@@ -63,13 +63,15 @@ TEST_F(PathMatcherUtilityTest, RegisterGet) {
6363
HttpRule http_rule;
6464
http_rule.set_get("/path");
6565
http_rule.set_body("body");
66-
EXPECT_CALL(pmb, Register(Eq("GET"), Eq("/path"), Eq("body"),
67-
Eq(std::set<std::string>()), Eq(&method1_)))
66+
EXPECT_CALL(pmb,
67+
Register(Eq("GET"), Eq("/path"), Eq("body"),
68+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
6869
.WillOnce(Return(true));
6970
ASSERT_TRUE(
7071
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
71-
EXPECT_CALL(pmb, Register(Eq("GET"), Eq("/path"), Eq("body"),
72-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
72+
EXPECT_CALL(
73+
pmb, Register(Eq("GET"), Eq("/path"), Eq("body"),
74+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
7375
.WillOnce(Return(false));
7476
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
7577
&method2_));
@@ -79,13 +81,15 @@ TEST_F(PathMatcherUtilityTest, RegisterPut) {
7981
HttpRule http_rule;
8082
http_rule.set_put("/path");
8183
http_rule.set_body("body");
82-
EXPECT_CALL(pmb, Register(Eq("PUT"), Eq("/path"), Eq("body"),
83-
Eq(std::set<std::string>()), Eq(&method1_)))
84+
EXPECT_CALL(pmb,
85+
Register(Eq("PUT"), Eq("/path"), Eq("body"),
86+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
8487
.WillOnce(Return(true));
8588
ASSERT_TRUE(
8689
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
87-
EXPECT_CALL(pmb, Register(Eq("PUT"), Eq("/path"), Eq("body"),
88-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
90+
EXPECT_CALL(
91+
pmb, Register(Eq("PUT"), Eq("/path"), Eq("body"),
92+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
8993
.WillOnce(Return(false));
9094
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
9195
&method2_));
@@ -95,13 +99,15 @@ TEST_F(PathMatcherUtilityTest, RegisterPost) {
9599
HttpRule http_rule;
96100
http_rule.set_post("/path");
97101
http_rule.set_body("body");
98-
EXPECT_CALL(pmb, Register(Eq("POST"), Eq("/path"), Eq("body"),
99-
Eq(std::set<std::string>()), Eq(&method1_)))
102+
EXPECT_CALL(pmb,
103+
Register(Eq("POST"), Eq("/path"), Eq("body"),
104+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
100105
.WillOnce(Return(true));
101106
ASSERT_TRUE(
102107
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
103-
EXPECT_CALL(pmb, Register(Eq("POST"), Eq("/path"), Eq("body"),
104-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
108+
EXPECT_CALL(
109+
pmb, Register(Eq("POST"), Eq("/path"), Eq("body"),
110+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
105111
.WillOnce(Return(false));
106112
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
107113
&method2_));
@@ -111,13 +117,15 @@ TEST_F(PathMatcherUtilityTest, RegisterDelete) {
111117
HttpRule http_rule;
112118
http_rule.set_delete_("/path");
113119
http_rule.set_body("body");
114-
EXPECT_CALL(pmb, Register(Eq("DELETE"), Eq("/path"), Eq("body"),
115-
Eq(std::set<std::string>()), Eq(&method1_)))
120+
EXPECT_CALL(pmb,
121+
Register(Eq("DELETE"), Eq("/path"), Eq("body"),
122+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
116123
.WillOnce(Return(true));
117124
ASSERT_TRUE(
118125
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
119-
EXPECT_CALL(pmb, Register(Eq("DELETE"), Eq("/path"), Eq("body"),
120-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
126+
EXPECT_CALL(
127+
pmb, Register(Eq("DELETE"), Eq("/path"), Eq("body"),
128+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
121129
.WillOnce(Return(false));
122130
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
123131
&method2_));
@@ -127,13 +135,15 @@ TEST_F(PathMatcherUtilityTest, RegisterPatch) {
127135
HttpRule http_rule;
128136
http_rule.set_patch("/path");
129137
http_rule.set_body("body");
130-
EXPECT_CALL(pmb, Register(Eq("PATCH"), Eq("/path"), Eq("body"),
131-
Eq(std::set<std::string>()), Eq(&method1_)))
138+
EXPECT_CALL(pmb,
139+
Register(Eq("PATCH"), Eq("/path"), Eq("body"),
140+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
132141
.WillOnce(Return(true));
133142
ASSERT_TRUE(
134143
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
135-
EXPECT_CALL(pmb, Register(Eq("PATCH"), Eq("/path"), Eq("body"),
136-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
144+
EXPECT_CALL(
145+
pmb, Register(Eq("PATCH"), Eq("/path"), Eq("body"),
146+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
137147
.WillOnce(Return(false));
138148
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
139149
&method2_));
@@ -144,13 +154,15 @@ TEST_F(PathMatcherUtilityTest, RegisterCustom) {
144154
http_rule.mutable_custom()->set_kind("OPTIONS");
145155
http_rule.mutable_custom()->set_path("/custom_path");
146156
http_rule.set_body("body");
147-
EXPECT_CALL(pmb, Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body"),
148-
Eq(std::set<std::string>()), Eq(&method1_)))
157+
EXPECT_CALL(pmb,
158+
Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body"),
159+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
149160
.WillOnce(Return(true));
150161
ASSERT_TRUE(
151162
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
152-
EXPECT_CALL(pmb, Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body"),
153-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
163+
EXPECT_CALL(
164+
pmb, Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body"),
165+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
154166
.WillOnce(Return(false));
155167
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
156168
&method2_));
@@ -173,26 +185,32 @@ TEST_F(PathMatcherUtilityTest, RegisterAdditionalBindings) {
173185
HttpRule& custom_http_rule3 = *http_rule.add_additional_bindings();
174186
custom_http_rule3.set_put("/put_path");
175187

176-
EXPECT_CALL(pmb, Register(Eq("GET"), Eq("/path"), Eq("body"),
177-
Eq(std::set<std::string>()), Eq(&method1_)))
188+
EXPECT_CALL(pmb,
189+
Register(Eq("GET"), Eq("/path"), Eq("body"),
190+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
178191
.WillOnce(Return(true));
179-
EXPECT_CALL(pmb, Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body1"),
180-
Eq(std::set<std::string>()), Eq(&method1_)))
192+
EXPECT_CALL(pmb,
193+
Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body1"),
194+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
181195
.WillOnce(Return(true));
182-
EXPECT_CALL(pmb, Register(Eq("HEAD"), Eq("/path"), Eq(""),
183-
Eq(std::set<std::string>()), Eq(&method1_)))
196+
EXPECT_CALL(pmb,
197+
Register(Eq("HEAD"), Eq("/path"), Eq(""),
198+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
184199
.WillOnce(Return(true));
185-
EXPECT_CALL(pmb, Register(Eq("PUT"), Eq("/put_path"), Eq(""),
186-
Eq(std::set<std::string>()), Eq(&method1_)))
200+
EXPECT_CALL(pmb,
201+
Register(Eq("PUT"), Eq("/put_path"), Eq(""),
202+
Eq(std::unordered_set<std::string>()), Eq(&method1_)))
187203
.WillOnce(Return(true));
188204
ASSERT_TRUE(
189205
PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, &method1_));
190206

191-
EXPECT_CALL(pmb, Register(Eq("GET"), Eq("/path"), Eq("body"),
192-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
207+
EXPECT_CALL(
208+
pmb, Register(Eq("GET"), Eq("/path"), Eq("body"),
209+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
193210
.WillOnce(Return(true));
194-
EXPECT_CALL(pmb, Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body1"),
195-
Eq(std::set<std::string>{"key"}), Eq(&method2_)))
211+
EXPECT_CALL(
212+
pmb, Register(Eq("OPTIONS"), Eq("/custom_path"), Eq("body1"),
213+
Eq(std::unordered_set<std::string>{"key"}), Eq(&method2_)))
196214
.WillOnce(Return(false));
197215
ASSERT_FALSE(PathMatcherUtility::RegisterByHttpRule(pmb, http_rule, {"key"},
198216
&method2_));

0 commit comments

Comments
 (0)