forked from mrtazz/restclient-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_restclient_delete.cpp
More file actions
71 lines (61 loc) · 1.58 KB
/
test_restclient_delete.cpp
File metadata and controls
71 lines (61 loc) · 1.58 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 RestClientDeleteTest : public ::testing::Test
{
protected:
std::string url;
std::string ctype;
std::string data;
RestClientDeleteTest()
{
}
virtual ~RestClientDeleteTest()
{
}
virtual void SetUp()
{
url = "http://httpbin.org/delete";
ctype = "";
data = "";
}
virtual void TearDown()
{
}
};
// Tests
// check return code
TEST_F(RestClientDeleteTest, TestRestClientDeleteCode)
{
RestClient::response res = RestClient::del(url);
EXPECT_EQ(200, res.code);
}
TEST_F(RestClientDeleteTest, TestRestClientDeleteBody)
{
RestClient::response res = RestClient::del(url);
Json::Value root;
std::istringstream str(res.body);
str >> root;
EXPECT_EQ("http://httpbin.org/delete", 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(RestClientDeleteTest, TestRestClientFailureCode)
{
std::string u = "http://nonexistent";
RestClient::response res = RestClient::del(u);
EXPECT_EQ(-1, res.code);
}
TEST_F(RestClientDeleteTest, TestRestClientDeleteHeaders)
{
RestClient::response res = RestClient::del(url);
EXPECT_EQ("keep-alive", res.headers["Connection"]);
}
/*TEST_F(RestClientDeleteTest, TestRestClientDeleteTimeout)
{
std::string u = "http://httpbin.org/delay/10";
RestClient::response res = RestClient::del(u, 5);
EXPECT_EQ(28, res.code);
}*/