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
71 lines (61 loc) · 1.64 KB
/
test_restclient_post.cpp
File metadata and controls
71 lines (61 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 "restclient-cpp/meta.h"
#include <gtest/gtest.h>
#include <json/json.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://httpbin.org/post";
ctype = "Content-Type: text/text";
data = "data";
}
virtual void TearDown()
{
}
};
// Tests
// check return code
TEST_F(RestClientPostTest, TestRestClientPOSTCode)
{
RestClient::response res = RestClient::post(url, ctype, data);
EXPECT_EQ(200, res.code);
}
TEST_F(RestClientPostTest, TestRestClientPostBody)
{
RestClient::response res = RestClient::post(url, ctype, data);
Json::Value root;
std::istringstream str(res.body);
str >> root;
EXPECT_EQ("http://httpbin.org/post", root.get("url", "no url set").asString());
EXPECT_EQ("restclient-cpp/" VERSION, root["headers"].get("User-Agent", "no url set").asString());
}
// 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"]);
}
/*TEST_F(RestClientPostTest, TestRestClientPOSTTimeout)
{
std::string u = "http://httpbin.org/delay/10";
RestClient::response res = RestClient::post(u, ctype, data, 5);
EXPECT_EQ(28, res.code);
}*/