This repository was archived by the owner on Aug 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Api server test for dispatch operator #123
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
def8a69
Stub local API server test
dhrupadb 51e6e09
Restore deleted store_unittest.cc.
igorpeshansky 22f448e
Add appropriate includes and object dependencies.
igorpeshansky 2aaceb7
Fix parallel builds.
igorpeshansky b07b899
Pulled out constructor to pass in handlers
ACEmilG 7010ae9
Support for testing dispatch operator
ACEmilG 599affd
Back out changes on store_unittest.cc
ACEmilG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #include "../src/api_server.h" | ||
| #include "../src/configuration.h" | ||
| #include "../src/store.h" | ||
| #include "gtest/gtest.h" | ||
|
|
||
| namespace google { | ||
|
|
||
| class ApiServerTest : public ::testing::Test { | ||
| protected: | ||
| static void CallDispatcher( | ||
| MetadataApiServer* server, | ||
| const MetadataApiServer::HttpServer::request& request, | ||
| std::shared_ptr<MetadataApiServer::HttpServer::connection> conn) { | ||
| server->dispatcher_(request, conn); | ||
| } | ||
| }; | ||
|
|
||
| TEST_F(ApiServerTest, BasicDispacher) { | ||
| Configuration config(std::istringstream("")); | ||
| MetadataStore store(config); | ||
| bool handler_called; | ||
| MetadataApiServer::Handler handler = [&handler_called]( | ||
| const MetadataApiServer::HttpServer::request& request, | ||
| std::shared_ptr<MetadataApiServer::HttpServer::connection> conn) { | ||
| handler_called = true; | ||
| }; | ||
| MetadataApiServer::Handler badHandler = [&handler_called]( | ||
| const MetadataApiServer::HttpServer::request& request, | ||
| std::shared_ptr<MetadataApiServer::HttpServer::connection> conn) { | ||
| handler_called = false; | ||
| }; | ||
| MetadataApiServer::HandlerMap handlers({ | ||
| {{"GET", "/testPath/"}, handler}, | ||
| {{"GET", "/badPath/"}, badHandler} | ||
| }); | ||
| MetadataApiServer server(config, store, 0, "TestHost", 1234, handlers); | ||
| MetadataApiServer::HttpServer::request request; | ||
| request.method = "GET"; | ||
| request.destination = "/testPath/"; | ||
| CallDispatcher(&server, request, nullptr); | ||
| EXPECT_TRUE(handler_called); | ||
| } | ||
|
|
||
| TEST_F(ApiServerTest, DispatcherMethodCheck) { | ||
| Configuration config(std::istringstream("")); | ||
| MetadataStore store(config); | ||
| bool handler_called; | ||
| MetadataApiServer::Handler handler = [&handler_called]( | ||
| const MetadataApiServer::HttpServer::request& request, | ||
| std::shared_ptr<MetadataApiServer::HttpServer::connection> conn) { | ||
| handler_called = true; | ||
| }; | ||
| MetadataApiServer::HandlerMap handlers({{{"GET", "/testPath/"}, handler}}); | ||
| MetadataApiServer server(config, store, 0, "TestHost", 1234, handlers); | ||
| MetadataApiServer::HttpServer::request request; | ||
| request.method = "POST"; | ||
| request.destination = "/testPath/"; | ||
| CallDispatcher(&server, request, nullptr); | ||
| EXPECT_FALSE(handler_called); | ||
| } | ||
|
|
||
| TEST_F(ApiServerTest, DispatcherSubstringCheck) { | ||
| Configuration config(std::istringstream("")); | ||
| MetadataStore store(config); | ||
| bool handler_called; | ||
| MetadataApiServer::Handler handler = [&handler_called]( | ||
| const MetadataApiServer::HttpServer::request& request, | ||
| std::shared_ptr<MetadataApiServer::HttpServer::connection> conn) { | ||
| handler_called = true; | ||
| }; | ||
| MetadataApiServer::HandlerMap handlers({{{"GET", "/testPath/"}, handler}}); | ||
| MetadataApiServer server(config, store, 0, "TestHost", 1234, handlers); | ||
| MetadataApiServer::HttpServer::request request; | ||
|
|
||
| request.method = "GET"; | ||
| request.destination = "/testPathFoo/"; | ||
| CallDispatcher(&server, request, nullptr); | ||
| EXPECT_FALSE(handler_called); | ||
| request.destination = "/test/"; | ||
| CallDispatcher(&server, request, nullptr); | ||
| EXPECT_FALSE(handler_called); | ||
| request.destination = "/testFooPath/"; | ||
| CallDispatcher(&server, request, nullptr); | ||
| EXPECT_FALSE(handler_called); | ||
| } | ||
|
|
||
| } // namespace google |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You didn't have to make this change. First, you can test the
Dispatcherclass separately, and theHandleMonitoredResourcecallback separately (that's why the latter was pulled out in the first place). Second, the new code looks a lot uglier because of the explicit specs for themapandpairtypes. I would back out this whole commit.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.
Looking things over now, I agree. Ill close this pull request and open a new one testing Dispatcher directly
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.
Hmm. I meant this commit, not this PR. You could have reused the PR for the dispatch tests (or the
HandleMonitoredResourcetest, which you still can — just reopen the PR).