Skip to content

Commit

Permalink
HttpClient takes a baseUrl string
Browse files Browse the repository at this point in the history
  • Loading branch information
malakai97 committed Nov 8, 2023
1 parent 9e06e3f commit baf4b94
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apache/client/include/lauth/api_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace mlibrary::lauth {
class ApiClient {
public:
ApiClient() : client(std::make_unique<HttpClient>()) {};
ApiClient() : client(std::make_unique<HttpClient>("http://localhost:9000")) {};
ApiClient(std::unique_ptr<HttpClient>&& client) : client(std::move(client)) {};
ApiClient(const ApiClient&) = delete;
ApiClient& operator=(const ApiClient&) = delete;
Expand Down
7 changes: 5 additions & 2 deletions apache/client/include/lauth/http_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
namespace mlibrary::lauth {
class HttpClient {
public:
HttpClient(std::string host = "", uint16_t port = 0);
HttpClient(const std::string& baseUrl) : baseUrl(baseUrl) {};
virtual ~HttpClient() = default;

virtual bool isAllowed(Request req);

protected:
const std::string baseUrl;
};
}

Expand Down
3 changes: 0 additions & 3 deletions apache/client/src/lauth/http_client.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "lauth/http_client.hpp"

namespace mlibrary::lauth {
HttpClient::HttpClient(std::string host, uint16_t port) {

}

bool HttpClient::isAllowed(Request req) {
return (req.user == "authorized");
Expand Down
10 changes: 4 additions & 6 deletions apache/client/test/lauth/http_client_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ using testing::_;

using namespace mlibrary::lauth;

const std::string api_url = "http://localhost:9000";

TEST(HttpClientTest, mock_service_response_with_is_allowed) {
std::string host = "";
uint16_t port = 0;
HttpClient client(host, port);
HttpClient client(api_url);

Request req;
req.user = "authorized";
Expand All @@ -23,9 +23,7 @@ TEST(HttpClientTest, mock_service_response_with_is_allowed) {
}

TEST(HttpClientTest, mock_service_response_with_is_not_allowed) {
std::string host = "";
uint16_t port = 0;
HttpClient client(host, port);
HttpClient client(api_url);

Request req;
req.user = "authorized";
Expand Down
1 change: 1 addition & 0 deletions apache/client/test/lauth/mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MockApiClient : public ApiClient {

class MockHttpClient : public HttpClient {
public:
MockHttpClient() : HttpClient("http://localhost:9000") {};
MOCK_METHOD(bool, isAllowed, (Request), (override));
};

Expand Down

0 comments on commit baf4b94

Please sign in to comment.