-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add unit test for quota config. #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -870,6 +870,80 @@ TEST(Config, TestCorsDisabled) { | |
| ASSERT_EQ(nullptr, method1); | ||
| } | ||
|
|
||
| TEST(Config, TestInvalidMetricRules) { | ||
| MockApiManagerEnvironmentWithLog env; | ||
| // There is no http.rule or api.method to match the selector. | ||
| static const char config_text[] = R"( | ||
| name: "Service.Name" | ||
| quota { | ||
| metric_rules { | ||
| selector: "GetShelves" | ||
| metric_costs { | ||
| key: "test.googleapis.com/operation/read_book" | ||
| value: 100 | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
|
|
||
| std::unique_ptr<Config> config = Config::Create(&env, config_text, ""); | ||
| EXPECT_EQ(nullptr, config); | ||
| } | ||
|
|
||
| TEST(Config, TestMetricRules) { | ||
| MockApiManagerEnvironmentWithLog env; | ||
| static const char config_text[] = R"( | ||
| name: "Service.Name" | ||
| http { | ||
| rules { | ||
| selector: "DeleteShelf" | ||
| delete: "/shelves" | ||
| } | ||
| rules { | ||
| selector: "GetShelves" | ||
| get: "/shelves" | ||
| } | ||
| } | ||
| quota { | ||
| metric_rules { | ||
| selector: "GetShelves" | ||
| metric_costs { | ||
| key: "test.googleapis.com/operation/get_shelves" | ||
| value: 100 | ||
| } | ||
| } | ||
| metric_rules { | ||
| selector: "DeleteShelf" | ||
| metric_costs { | ||
| key: "test.googleapis.com/operation/delete_shelves" | ||
| value: 200 | ||
| } | ||
| } | ||
| } | ||
| )"; | ||
|
|
||
| std::unique_ptr<Config> config = Config::Create(&env, config_text, ""); | ||
| ASSERT_TRUE(config); | ||
|
|
||
| auto method1 = config->GetMethodInfo("GET", "/shelves"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To keep the code consistent with Envoy, I suggest avoiding over usage of auto method. In the Envoy codebase, we use explicit types most of the time |
||
| ASSERT_NE(nullptr, method1); | ||
|
|
||
| auto metric_cost_vector = method1->metric_cost_vector(); | ||
| ASSERT_EQ(1, metric_cost_vector.size()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but we DO want to test 2 metrics case. You can either convert the vector to a "set", then compare the "set". or sort the vector first, |
||
| ASSERT_EQ("test.googleapis.com/operation/get_shelves", | ||
| metric_cost_vector[0].first); | ||
| ASSERT_EQ(100, metric_cost_vector[0].second); | ||
|
|
||
| auto method2 = config->GetMethodInfo("DELETE", "/shelves"); | ||
| ASSERT_NE(nullptr, method1); | ||
|
|
||
| metric_cost_vector = method2->metric_cost_vector(); | ||
| ASSERT_EQ(1, metric_cost_vector.size()); | ||
| ASSERT_EQ("test.googleapis.com/operation/delete_shelves", | ||
| metric_cost_vector[0].first); | ||
| ASSERT_EQ(200, metric_cost_vector[0].second); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| } // namespace api_manager | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment to state why this is invalid
// There is no http.rule or api.method to match the selector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.