This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
http.test.cc
63 lines (45 loc) · 1.73 KB
/
http.test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <curl/curl.h>
#include "janus/http.h"
using testing::HasSubstr;
namespace Janus {
class HttpTest : public testing::Test {
};
TEST_F(HttpTest, shouldForwardHttpCodes) {
auto http = std::make_shared<HttpImpl>("https://httpbin");
auto response = http->get("/post");
EXPECT_EQ(response->status(), 405);
}
TEST_F(HttpTest, shouldForwardACurlError) {
auto http = std::make_shared<HttpImpl>("yolo:https://fake");
auto response = http->get("/post");
EXPECT_EQ(response->status(), CURLE_UNSUPPORTED_PROTOCOL);
}
TEST_F(HttpTest, shouldPerformAGetRequest) {
auto http = std::make_shared<HttpImpl>("https://httpbin");
auto response = http->get("/get");
EXPECT_EQ(response->status(), 200);
EXPECT_THAT(response->body(), HasSubstr("https://httpbin/get"));
EXPECT_THAT(response->body(), HasSubstr("Janus Native HTTP Client"));
}
TEST_F(HttpTest, shouldPerformAPostRequest) {
auto http = std::make_shared<HttpImpl>("https://httpbin");
auto response = http->post("/post");
EXPECT_EQ(response->status(), 200);
EXPECT_THAT(response->body(), HasSubstr("https://httpbin/post"));
EXPECT_THAT(response->body(), HasSubstr("Janus Native HTTP Client"));
}
TEST_F(HttpTest, shouldSendJsonDataViaPost) {
auto http = std::make_shared<HttpImpl>("https://httpbin");
auto response = http->post("/post", "{ \"data\": \"my yolo data\" }");
EXPECT_THAT(response->body(), HasSubstr("my yolo data"));
}
class HttpFactoryTest : public testing::Test {
};
TEST_F(HttpFactoryTest, shouldCreateAnHttpClient) {
auto factory = std::make_shared<HttpFactoryImpl>();
auto http = factory->create("the url");
EXPECT_NE(http, nullptr);
}
}