-
-
Notifications
You must be signed in to change notification settings - Fork 8
Initial C++ library #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seffradev
wants to merge
5
commits into
testcontainers:main
Choose a base branch
from
seffradev:cpp-abstraction
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
30e0be9
build: Add rudimentary Nix shell flake
seffradev ccccd3a
docs: Rephrase sentences, and improve grammar and spelling
seffradev fecf6bc
Merge pull request #52 from seffradev/nix-flake
oleg-nenashev f9a498b
Merge pull request #48 from seffradev/language-and-grammar
oleg-nenashev f691262
feat: Implement initial C++ library
seffradev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
10
demo/google-test-cpp/test_data/hello_with_missing_resource.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| description = "Testcontainers Native"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; | ||
| }; | ||
|
|
||
| outputs = { self, nixpkgs }: let | ||
| system = "x86_64-linux"; | ||
| pkgs = import nixpkgs { inherit system; }; | ||
| in { | ||
| devShells.${system}.default = pkgs.mkShell { | ||
| packages = with pkgs; [ | ||
| clang-tools | ||
| cmake | ||
| gcc15 | ||
| gdb | ||
| go | ||
| ninja | ||
| pre-commit | ||
| ]; | ||
| }; | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| set(TARGET testcontainers-cpp) | ||
| set(TARGET_NAME ${TARGET}) | ||
| set(TARGET_DESCRIPTION "Testcontainer library for C++") | ||
| set(TARGET_VERSION ${PROJECT_VERSION}) | ||
|
|
||
| add_library(${TARGET} INTERFACE) | ||
|
|
||
| set(CMAKE_CXX_STANDARD 23) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
|
||
| target_sources(${TARGET} | ||
| PUBLIC FILE_SET HEADERS | ||
| BASE_DIRS . | ||
| FILES testcontainers.hpp | ||
| ) | ||
|
|
||
| target_link_libraries(${TARGET} INTERFACE testcontainers-c) | ||
|
|
||
| configure_file(cmake.pc.in ${TARGET}.pc @ONLY) | ||
| install(TARGETS ${TARGET} | ||
| LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) | ||
| install(FILES ${CMAKE_BINARY_DIR}/${TARGET}.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig) | ||
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR I am fine with doing only 23 for now, that's not a blocker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My biggest argument against merging what we have is that I have a redesign almost done. I just have some UB to refine away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me