Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ include(CTest)

add_subdirectory(testcontainers-bridge)
add_subdirectory(testcontainers-c)
add_subdirectory(testcontainers-cpp)
add_subdirectory(modules)
if(NOT DEFINED SKIP_DEMOS)
add_subdirectory(demo)
Expand Down
1 change: 1 addition & 0 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
add_subdirectory(generic-container)
add_subdirectory(wiremock)
add_subdirectory(google-test)
add_subdirectory(google-test-cpp)
add_subdirectory(postgresql)
32 changes: 32 additions & 0 deletions demo/google-test-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Google Test demo
# This is based on https://google.github.io/googletest/quickstart-cmake.html
cmake_minimum_required (VERSION 3.26)
project (google-test-cpp-demo
VERSION 0.1.0
DESCRIPTION "Demonstrates usage of Testcontainers C++ in Google Test"
LANGUAGES CXX
)

set(TARGET_OUT ${PROJECT_NAME}.out)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.17.0
)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_executable(${TARGET_OUT} test.cpp)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-cpp)
target_link_libraries(${TARGET_OUT} PRIVATE GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(${TARGET_OUT})
13 changes: 13 additions & 0 deletions demo/google-test-cpp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Using Testcontainers C++ in Google Test

Demonstrates usage of Testcontainers C++ in [Google
Test](https://github.com/google/googletest). See
[test.cpp](./test.cpp) for the code.

## Run the demo

```bash
cmake -S . -B /tmp/tc-native
cmake --build /tmp/tc-native/
ctest --output-on-failure -R Class
```
54 changes: 54 additions & 0 deletions demo/google-test-cpp/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <gtest/gtest.h>

#include <iostream>
#include <string>

#include "testcontainers.hpp"

using namespace testcontainers;

class WireMockTestContainerClass : 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 {
using namespace std::literals;

builder.expose_port(TcpPort{8080}).wait_for_http(TcpPort{8080}, WIREMOCK_ADMIN_MAPPING_ENDPOINT);
}

Container::Builder builder = Container::Builder{WIREMOCK_IMAGE};
};

/// This test runs a "Hello World" example.
TEST_F(WireMockTestContainerClass, HelloWorld) {
auto container = builder.with_file("test_data/hello.json", "/home/wiremock/mappings/hello.json").build();
ASSERT_TRUE(container.has_value()) << "Failed to run the container";

auto [code, response] = container->send_http(HttpMethod::Get, TcpPort{8080}, "/hello");
ASSERT_EQ(code, 200) << "Expected 200 OK. Received response: " << response;
}

/// This test responds to an HTTP request with response from a
/// prepared file.
TEST_F(WireMockTestContainerClass, HelloWorldFromResource) {
auto container = builder.with_file("test_data/hello_with_resource.json", "/home/wiremock/mappings/hello2.json")
.with_file("test_data/response.xml", "/home/wiremock/__files/response.xml")
.build();
ASSERT_TRUE(container.has_value()) << "Failed to run the container";

auto [code, response] = container->send_http(HttpMethod::Get, TcpPort{8080}, "/hello-from-resource");
ASSERT_EQ(code, 200) << "Expected 200 OK. Received response: " << response;
}

/// This test performs a request that is guaranteed to fail and
/// return an HTTP-500.
TEST_F(WireMockTestContainerClass, HelloWorldFromMissingResource) {
auto container =
builder.with_file("test_data/hello_with_missing_resource.json", "/home/wiremock/mappings/hello3.json").build();
ASSERT_TRUE(container.has_value()) << "Failed to run the container";

auto [code, response] = container->send_http(HttpMethod::Get, TcpPort{8080}, "/hello-from-missing-resource");
ASSERT_EQ(code, 500) << "Expected 500 Internal Server Error. Received response: " << response;
}
12 changes: 12 additions & 0 deletions demo/google-test-cpp/test_data/hello.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"request": {
"method": "GET",
"url": "/hello"
},

"response": {
"status": 200,
"body": "Hello, world!"
}
}

10 changes: 10 additions & 0 deletions demo/google-test-cpp/test_data/hello_with_missing_resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"request": {
"method": "GET",
"url": "/hello-from-missing-resource"
},
"response": {
"status": 200,
"bodyFileName": "response_missing.xml"
}
}
10 changes: 10 additions & 0 deletions demo/google-test-cpp/test_data/hello_with_resource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"request": {
"method": "GET",
"url": "/hello-from-resource"
},
"response": {
"status": 200,
"bodyFileName": "response.xml"
}
}
6 changes: 6 additions & 0 deletions demo/google-test-cpp/test_data/response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<note>
<to>you</to>
<from>WireMock</from>
<heading>Response</heading>
<body>Hello, world!</body>
</note>
81 changes: 51 additions & 30 deletions testcontainers-bridge/go.mod
Original file line number Diff line number Diff line change
@@ -1,44 +1,65 @@
module github.com/testcontainers/testcontainers-native

go 1.19
go 1.25.0

require (
github.com/docker/go-connections v0.4.0
github.com/testcontainers/testcontainers-go v0.22.0
github.com/docker/go-connections v0.6.0
github.com/testcontainers/testcontainers-go v0.40.0
)

require (
dario.cat/mergo v1.0.0 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/containerd/containerd v1.7.3 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/errdefs v1.0.0 // indirect
github.com/containerd/errdefs/pkg v0.3.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v28.5.1+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/ebitengine/purego v0.8.4 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.10 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/go-archive v0.1.0 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/user v0.4.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v4 v4.25.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.42.0 // indirect
go.opentelemetry.io/otel/metric v1.42.0 // indirect
go.opentelemetry.io/otel/sdk v1.42.0 // indirect
go.opentelemetry.io/otel/trace v1.42.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/sys v0.41.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading
Loading