forked from snowplow/snowplow-cpp-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_client_test.cpp
More file actions
70 lines (52 loc) · 2.55 KB
/
Copy pathhttp_client_test.cpp
File metadata and controls
70 lines (52 loc) · 2.55 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
/*
Copyright (c) 2016 Snowplow Analytics Ltd. All rights reserved.
This program is licensed to you under the Apache License Version 2.0,
and you may not use this file except in compliance with the Apache License Version 2.0.
You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing,
software distributed under the Apache License Version 2.0 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
#include "catch.hpp"
#include "../src/http_client.hpp"
#if defined(SNOWPLOW_TEST_SUITE)
#define HTTP_TEST_URL_GET "http://com.acme.collector/i"
#define HTTP_TEST_URL_POST "http://com.acme.collector/com.snowplowanalytics.snowplow/tp2"
TEST_CASE("http_client") {
SECTION("GET request to valid endpoint must return 200 code") {
HttpClient::reset();
CrackedUrl c(HTTP_TEST_URL_GET);
string query_string = "e=pv&tv=cpp-0.1.0";
list<int> id_list{1};
HttpRequestResult r = HttpClient::http_get(c, query_string, id_list, false);
REQUIRE(r.get_http_response_code() == 200);
REQUIRE(r.is_success() == true);
REQUIRE(r.get_row_ids().size() == id_list.size());
list<HttpClient::Request> requests_list = HttpClient::get_requests_list();
REQUIRE(1 == requests_list.size());
HttpClient::Request req = requests_list.front();
REQUIRE(HttpClient::RequestMethod::GET == req.method);
REQUIRE(query_string == req.query_string);
REQUIRE("" == req.post_data);
REQUIRE(false == req.oversize);
}
SECTION("POST request to valid endpoint must return 200 code") {
HttpClient::reset();
CrackedUrl c(HTTP_TEST_URL_POST);
string json_string = "{\"schema\":\"iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-3\",\"data\":[{\"dtm\":\"1234567890123\"}]}";
list<int> id_list{1};
HttpRequestResult r = HttpClient::http_post(c, json_string, id_list, false);
REQUIRE(r.get_http_response_code() == 200);
REQUIRE(r.is_success() == true);
REQUIRE(r.get_row_ids().size() == id_list.size());
list<HttpClient::Request> requests_list = HttpClient::get_requests_list();
REQUIRE(1 == requests_list.size());
HttpClient::Request req = requests_list.front();
REQUIRE(HttpClient::RequestMethod::POST == req.method);
REQUIRE("" == req.query_string);
REQUIRE(json_string == req.post_data);
REQUIRE(false == req.oversize);
}
}
#endif