forked from mrtazz/restclient-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_restclient_post.cpp
More file actions
70 lines (63 loc) · 1.64 KB
/
Copy pathtest_restclient_post.cpp
File metadata and controls
70 lines (63 loc) · 1.64 KB
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
64
65
66
67
68
69
70
#include "restclient-cpp/restclient.h"
#include <gtest/gtest.h>
#include <string>
class RestClientPostTest : public ::testing::Test
{
protected:
std::string url;
std::string ctype;
std::string data;
RestClientPostTest()
{
}
virtual ~RestClientPostTest()
{
}
virtual void SetUp()
{
url = "http://http-test-server.heroku.com";
ctype = "Content-Type: text/text";
data = "data";
}
virtual void TearDown()
{
}
};
// Tests
TEST_F(RestClientPostTest, TestRestClientPOSTSimple)
{
RestClient::response res = RestClient::post(url, ctype, data);
EXPECT_EQ("POST", res.body);
}
// check return code
TEST_F(RestClientPostTest, TestRestClientPOSTCode)
{
RestClient::response res = RestClient::post(url, ctype, data);
EXPECT_EQ(200, res.code);
}
// check content type
TEST_F(RestClientPostTest, TestRestClientPOSTContentType)
{
RestClient::response res = RestClient::post(url+"/contenttype",
ctype, data);
EXPECT_EQ(ctype, res.body);
}
// check response body
TEST_F(RestClientPostTest, TestRestClientPOSTBody)
{
RestClient::response res = RestClient::post(url+"/body",
ctype, data);
EXPECT_EQ(data, res.body);
}
// check for failure
TEST_F(RestClientPostTest, TestRestClientFailureCode)
{
std::string u = "http://nonexistent";
RestClient::response res = RestClient::post(u, ctype, data);
EXPECT_EQ(-1, res.code);
}
TEST_F(RestClientPostTest, TestRestClientPOSTHeaders)
{
RestClient::response res = RestClient::post(url, ctype, data);
EXPECT_EQ("keep-alive", res.headers["Connection"]);
}