11#include < iostream>
22#include < string>
33#include < gtest/gtest.h>
4- #include " testcontainers-c.h"
4+
5+ extern " C" {
6+ #include " testcontainers-c/container.h"
7+ }
58
69class WireMockTestContainer : public ::testing::Test {
710
@@ -11,23 +14,23 @@ const char* WIREMOCK_ADMIN_MAPPING_ENDPOINT = "/__admin/mappings";
1114protected:
1215 void SetUp () override {
1316 std::cout << " Creating new container: " << WIREMOCK_IMAGE << ' \n ' ;
14-
15- int requestId = tc_new_container_request (WIREMOCK_IMAGE);
16- tc_with_exposed_tcp_port (requestId, 8080 );
17- tc_with_wait_for_http (requestId, 8080 , WIREMOCK_ADMIN_MAPPING_ENDPOINT);
18- tc_with_file (requestId, " test_data/hello.json" , " /home/wiremock/mappings/hello.json" );
19- tc_with_file (requestId, " test_data/hello_with_resource.json" , " /home/wiremock/mappings/hello2.json" );
20- tc_with_file (requestId, " test_data/hello_with_missing_resource.json" , " /home/wiremock/mappings/hello3.json" );
21- tc_with_file (requestId, " test_data/response.xml" , " /home/wiremock/__files/response.xml" );
22-
23- struct tc_run_container_return ret = tc_run_container (requestId) ;
24- containerId = ret. r0 ;
25-
26- EXPECT_TRUE (ret. r1 ) << " Failed to run the container: " << ret. r2 ;
17+
18+ int requestId = tc_container_create (WIREMOCK_IMAGE);
19+ tc_container_with_exposed_tcp_port (requestId, 8080 );
20+ tc_container_with_wait_for_http (requestId, 8080 , WIREMOCK_ADMIN_MAPPING_ENDPOINT);
21+ tc_container_with_file (requestId, " test_data/hello.json" , " /home/wiremock/mappings/hello.json" );
22+ tc_container_with_file (requestId, " test_data/hello_with_resource.json" , " /home/wiremock/mappings/hello2.json" );
23+ tc_container_with_file (requestId, " test_data/hello_with_missing_resource.json" , " /home/wiremock/mappings/hello3.json" );
24+ tc_container_with_file (requestId, " test_data/response.xml" , " /home/wiremock/__files/response.xml" );
25+
26+ char * error ;
27+ int containerId = tc_container_run (requestId, error) ;
28+
29+ EXPECT_TRUE (containerId != - 1 ) << " Failed to run the container: " << error ;
2730 };
2831
2932 void TearDown () override {
30- char * error = tc_terminate_container (containerId);
33+ char * error = tc_container_terminate (containerId);
3134 ASSERT_EQ (error, nullptr ) << " Failed to terminate the container after the test: " << error;
3235 };
3336
@@ -36,32 +39,33 @@ const char* WIREMOCK_ADMIN_MAPPING_ENDPOINT = "/__admin/mappings";
3639
3740TEST_F (WireMockTestContainer, HelloWorld) {
3841 std::cout << " Sending HTTP request to the container\n " ;
39- struct tc_send_http_get_return response = tc_send_http_get (containerId, 8080 , " /hello" );
40-
41- ASSERT_NE (response.r0 , -1 ) << " Failed to send HTTP request: " << response.r2 ;
42- ASSERT_EQ (response.r0 , 200 ) << " Received wrong response code: " << response.r1 << response.r2 ;
43-
44- std::cout << " Server Response: HTTP-" << response.r0 << ' \n ' << response.r1 << ' \n ' ;
42+ char *response_body;
43+ char *error;
44+ int response_code = tc_container_send_http_get (containerId, 8080 , " /hello" , response_body, error);
45+
46+ ASSERT_NE (response_code, -1 ) << " Failed to send HTTP request: " << error;
47+ ASSERT_EQ (response_code, 200 ) << " Received wrong response code: " << response_body << error;
48+
49+ std::cout << " Server Response: HTTP-" << response_code << ' \n ' << response_body << ' \n ' ;
4550}
4651
4752TEST_F (WireMockTestContainer, HelloWorldFromResource) {
4853 std::cout << " Sending HTTP request to the container\n " ;
49- struct tc_send_http_get_return response = tc_send_http_get (containerId, 8080 , " /hello-from-resource" );
50-
51- ASSERT_NE (response.r0 , -1 ) << " Failed to send HTTP request: " << response.r2 ;
52- ASSERT_EQ (response.r0 , 200 ) << " Received wrong response code: " << response.r1 << response.r2 ;
53-
54- std::cout << " Server Response: HTTP-" << response.r0 << ' \n ' << response.r1 << ' \n ' ;
54+ char *response_body;
55+ char *error;
56+ int response_code = tc_container_send_http_get (containerId, 8080 , " /hello-from-resource" , response_body, error);
57+
58+ ASSERT_NE (response_code, -1 ) << " Failed to send HTTP request: " << error;
59+ ASSERT_EQ (response_code, 200 ) << " Received wrong response code: " << response_body << error;
60+
61+ std::cout << " Server Response: HTTP-" << response_code << ' \n ' << response_body << ' \n ' ;
5562}
5663
5764TEST_F (WireMockTestContainer, HelloWorldFromMissingResource) {
5865 std::cout << " Sending HTTP request to the container\n " ;
59- struct tc_send_http_get_return response = tc_send_http_get (containerId, 8080 , " /hello-from-missing-resource" );
60-
61- ASSERT_EQ (response.r0 , 500 ) << " The request should have failed" ;
62- }
66+ char *response_body;
67+ char *error;
68+ int response_code = tc_container_send_http_get (containerId, 8080 , " /hello-from-missing-resource" , response_body, error);
6369
64- int main (int argc, char **argv) {
65- ::testing::InitGoogleTest (&argc, argv);
66- return RUN_ALL_TESTS ();
70+ ASSERT_EQ (response_code, 500 ) << " The request should have failed" ;
6771}
0 commit comments