Skip to content
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

Docker compose support #22

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pull requests are more than enough for it.

## Building the project

You need CMake 3.16.3 and Golang 1.19+.
You need CMake 3.16.3 and Golang 1.22.5+.
At the moment there are not so many configuration flags, so the build is straightforward:

```shell
Expand Down
29 changes: 29 additions & 0 deletions demo/scadalts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Google Test demo
# This is based on https://google.github.io/googletest/quickstart-cmake.html
project(scadalts-demo
VERSION 0.0.1
DESCRIPTION "Demonstrates usage of Testcontainers C with SCADA-LTS")

set(TARGET_OUT ${PROJECT_NAME}.out)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
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)
add_dependencies(${TARGET_OUT} testcontainers-c-shim)
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c)
target_link_libraries(${TARGET_OUT} PRIVATE GTest::gtest_main)

include(GoogleTest)
gtest_discover_tests(${TARGET_OUT})
13 changes: 13 additions & 0 deletions demo/scadalts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Using Testcontainers C for OpenSCADA testing

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 .
cmake --build .
cd demo/google-test
ctest --output-on-failure
```
43 changes: 43 additions & 0 deletions demo/scadalts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Docker compose file to manage your deployed images.
# Use MySQL server 5.7 and latest Scada-LTS local build.
# Using attached webapps folder as developer you will be able to modify the static content from host os.
# Attach shell to stop the tomcat instance and then you will be able to run in JPDA mode.
version: '3'
services:
database:
container_name: mysql
image: mysql/mysql-server:8.0.32
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=scadalts
expose: ["3306"]
volumes:
- ./db_data:/var/lib/mysql:rw
- ./db_conf:/etc/mysql:ro
command: --log_bin_trust_function_creators=1
scadalts:
image: scadalts/scadalts:latest
environment:
- CATALINA_OPTS=-Xmx512m -Xms512m
ports:
- "8080:8080"
depends_on:
- database
expose: ["8080", "8000"]
volumes:
- ./tomcat_log:/usr/local/tomcat/logs:rw
links:
- database:database
command:
- /usr/bin/wait-for-it
- --host=database
- --port=3306
- --timeout=30
- --strict
- --
- /usr/local/tomcat/bin/catalina.sh
- run
43 changes: 43 additions & 0 deletions demo/scadalts/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <iostream>
#include <string>
#include <gtest/gtest.h>
#include "testcontainers-c.h"

class WireMockTestContainer : public ::testing::Test {

const char* SCADALTS_IMAGE = "dudanov/openscada:latest";
const char* SCADALTS_COMPOSE = "./docker-compose.yml";
const char* SCADALTS_ENDPOINT = "/";

protected:
void SetUp() override {
std::cout << "Creating new container: " << SCADALTS_IMAGE << '\n';

struct tc_new_docker_composer_return = tc_new_docker_compose(SCADALTS_COMPOSE);
compose_id = ret.r0;

EXPECT_TRUE(ret.r1) << "Failed to run the container: " << ret.r2;
};

void TearDown() override {
char* error = tc_terminate_compose(compose_id);
ASSERT_EQ(error, nullptr) << "Failed to terminate the container after the test: " << error;
};

int compose_id;
};

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, "/");

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';
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
4 changes: 2 additions & 2 deletions docs/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ that automates pulling and building of CMake projects from GitHub,

### Building locally

You need CMake 3.16.3 and Golang 1.19+.
You need CMake 3.16.3 and Golang 1.22.5+.
At the moment there are not so many configuration flags, so the build is straightforward:

```shell
Expand Down Expand Up @@ -50,7 +50,7 @@ Some frameworks like CTest provide wrappers for such executables.
In such examples, you do not even have to worry about releasing the Testcontainers resources, because
Testcontainers for Go has automatic resource de-provisioning.

#### Initializing the Testcontainer
#### Initializing the Testcontainers fixture

```c
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ For test framework framework examples, see the [demos](../demo/README.md).
## Build the Project

Right now you have to check out and build the project to use it locally.
You will need CMake, Docker, Golang 1.19++, and recent C/C++ build tools.
You will need CMake, Docker, Golang 1.22.5+, and recent C/C++ build tools.
The first build may take a while because the build process will need to download
[Testcontainers for Go](https://github.com/testcontainers/testcontainers-go)
and its dependencies like Docker client libraries,
Expand Down
2 changes: 1 addition & 1 deletion testcontainers-c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(testcontainers-c VERSION 0.0.1

include(GNUInstallDirs)

set(SRCS testcontainers-c.go)
set(SRCS testcontainers-c.go testcontainers-c-compose.go)

set(TARGET testcontainers-c-shim)
set(TARGET_LIB testcontainers-c.so)
Expand Down
Loading
Loading