forked from testcontainers/testcontainers-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
67 lines (50 loc) · 2.78 KB
/
test.cpp
File metadata and controls
67 lines (50 loc) · 2.78 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
#include <iostream>
#include <string>
#include <gtest/gtest.h>
#include "testcontainers-c.h"
class WireMockTestContainer : public ::testing::Test {
const char* WIREMOCK_IMAGE = "wiremock/wiremock:3.0.1-1";
const char* WIREMOCK_ADMIN_MAPPING_ENDPOINT = "/__admin/mappings";
protected:
void SetUp() override {
std::cout << "Creating new container: " << WIREMOCK_IMAGE << '\n';
int requestId = tc_new_container_request(WIREMOCK_IMAGE);
tc_with_exposed_tcp_port(requestId, 8080);
tc_with_wait_for_http(requestId, 8080, WIREMOCK_ADMIN_MAPPING_ENDPOINT);
tc_with_file(requestId, "test_data/hello.json", "/home/wiremock/mappings/hello.json");
tc_with_file(requestId, "test_data/hello_with_resource.json", "/home/wiremock/mappings/hello2.json");
tc_with_file(requestId, "test_data/hello_with_missing_resource.json", "/home/wiremock/mappings/hello3.json");
tc_with_file(requestId, "test_data/response.xml", "/home/wiremock/__files/response.xml");
struct tc_run_container_return ret = tc_run_container(requestId);
containerId = ret.r0;
EXPECT_TRUE(ret.r1) << "Failed to run the container: " << ret.r2;
};
void TearDown() override {
char* error = tc_terminate_container(containerId);
ASSERT_EQ(error, nullptr) << "Failed to terminate the container after the test: " << error;
};
int containerId;
};
TEST_F(WireMockTestContainer, HelloWorld) {
std::cout << "Sending HTTP request to the container\n";
struct tc_send_http_get_return response = tc_send_http_get(containerId, 8080, "/hello");
ASSERT_NE(response.r0, -1) << "Failed to send HTTP request: " << response.r2;
ASSERT_EQ(response.r0, 200) << "Received wrong response code: " << response.r1 << response.r2;
std::cout << "Server Response: HTTP-" << response.r0 << '\n' << response.r1 << '\n';
}
TEST_F(WireMockTestContainer, HelloWorldFromResource) {
std::cout << "Sending HTTP request to the container\n";
struct tc_send_http_get_return response = tc_send_http_get(containerId, 8080, "/hello-from-resource");
ASSERT_NE(response.r0, -1) << "Failed to send HTTP request: " << response.r2;
ASSERT_EQ(response.r0, 200) << "Received wrong response code: " << response.r1 << response.r2;
std::cout << "Server Response: HTTP-" << response.r0 << '\n' << response.r1 << '\n';
}
TEST_F(WireMockTestContainer, HelloWorldFromMissingResource) {
std::cout << "Sending HTTP request to the container\n";
struct tc_send_http_get_return response = tc_send_http_get(containerId, 8080, "/hello-from-missing-resource");
ASSERT_EQ(response.r0, 500) << "The request should have failed";
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}