Skip to content

Commit

Permalink
Move the Modules documentation over to a separate page
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Jul 14, 2024
1 parent e2a64d4 commit 30eb580
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 79 deletions.
79 changes: 3 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ Also join the `#testcontainers-c` channel on the [Testcontainers Slack](http://s
- Minimum HTTP client wrapper to simplify requests and assertions
- [Testcontainers for Go](https://golang.testcontainers.org/) under the hood
- Wrappers for native C types to minimize Golang conversion code on the user side
- Support for C and C++ projects. A fancy C++ wrapper is coming soon
- Support for Modules, e.g. the [WireMock module](./modules/wiremock/)
- Support for [C](./docs/c/README.md) and [C++](./docs/cpp/README.md) projects.
A fancy C++ wrapper is coming soon
- Support for [Modules](./modules/README.md)

## Quick Start

Expand Down Expand Up @@ -157,80 +158,6 @@ TL;DR: You get the C header file, a shared library object or a DLL file from the
Then, you know the drill.
Feel free to contribute examples or SDKs for the languages!

## Modules

As for other Testcontainers implementations, Testcontainers for C/C++ allow writing
extensions that extend the SDK and APIs to make usage of a particular service provider
easier.
The expectation is that the modules are implemented in a separate dynamic library
and linked to the consumer project.

### Available modules

- Generic container for DYI containers (embedded)
- [Demo](./demo/generic-container/)
- [WireMock](./modules/wiremock/) - for API mocking and integration testing
- [Demo](./demo/wiremock/)

### Why modules?

Modules help to simplify test development and maintenance by encapsulating
domain-specific logic of a target container.
For example, the WireMock module adds an API to simplify the configuration of the container.
You can also use modules to create specific asserts for the container,
or even attach full-fledged API clients for fine-grain testing.

Initializing WireMock with the module:

```c
#include "testcontainers-c-wiremock.h"

int main() {
printf("Creating new container: %s\n", DEFAULT_WIREMOCK_IMAGE);
int requestId = tc_wm_new_default_container();
tc_wm_with_mapping(requestId, "test_data/hello.json", "hello");
struct tc_run_container_return ret = tc_run_container(requestId);

// ...
}
```

The same initialization without a module (using the "Generic Container" API):

<details>
<summary>
Show me the Code
</summary>

```c
#include "testcontainers-c.h"

#define DEFAULT_IMAGE "wiremock/wiremock:3.1.0-1"

int main() {
printf("Using WireMock with the Testcontainers C binding:\n");

printf("Creating new container: %s\n", DEFAULT_IMAGE);
int requestId = tc_new_container_request(DEFAULT_IMAGE);
tc_with_exposed_tcp_port(requestId, 8080);
tc_with_wait_for_http(requestId, 8080, "/__admin/mappings");
tc_with_file(requestId, "test_data/hello.json", "/home/wiremock/mappings/hello.json");
struct tc_run_container_return ret = tc_run_container(requestId);

// ...
}
```

</details>

### Creating new modules

You are welcome to contribute more modules in this or a standalone repository!

> **NOTE:** Some modules are stored in this repository for demo and prototyping purposes.
> If you develop new modules, once `vcpkg` or `Conan` packaging is implemented for Testcontainers C,
> you might want to develop your module in a standalone repository instead.
## Credits

Using a complex Golang framework from C/C++ is not trivial.
Expand Down
70 changes: 67 additions & 3 deletions modules/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,82 @@
# Testcontainers for C/C++. Modules

The project offers limited support for extending it with modules,
similar to other Testcontainers implementations.
As for other Testcontainers implementations, Testcontainers for C/C++ allow writing
extensions that extend the SDK and APIs to make usage of a particular service provider
easier.
The expectation is that the modules are implemented in a separate dynamic library
and linked to the consumer project.

The modules use Native API, and
can be a fully native implementation or
a Golang bridge one, similar to the core project.

## Why Modules?

Modules help to simplify test development and maintenance by encapsulating
domain-specific logic of a target container.
For example, the WireMock module adds an API to simplify the configuration of the container.
You can also use modules to create specific asserts for the container,
or even attach full-fledged API clients for fine-grain testing.

## Available Modules

The following modules are available for this project:

- [WireMock](./wiremock/README.md)
- Embedded Generic container for DYI containers - [DEMO](../demo/generic-container/README.md)
- [WireMock for API Mocking](./wiremock/README.md)

## Using Modules

Initializing WireMock with the module:

```c
#include "testcontainers-c-wiremock.h"

int main() {
printf("Creating new container: %s\n", DEFAULT_WIREMOCK_IMAGE);
int requestId = tc_wm_new_default_container();
tc_wm_with_mapping(requestId, "test_data/hello.json", "hello");
struct tc_run_container_return ret = tc_run_container(requestId);

// ...
}
```

The same initialization without a module (using the "Generic Container" API):

<details>
<summary>
Show me the Code
</summary>

```c
#include "testcontainers-c.h"

#define DEFAULT_IMAGE "wiremock/wiremock:3.1.0-1"

int main() {
printf("Using WireMock with the Testcontainers C binding:\n");

printf("Creating new container: %s\n", DEFAULT_IMAGE);
int requestId = tc_new_container_request(DEFAULT_IMAGE);
tc_with_exposed_tcp_port(requestId, 8080);
tc_with_wait_for_http(requestId, 8080, "/__admin/mappings");
tc_with_file(requestId, "test_data/hello.json", "/home/wiremock/mappings/hello.json");
struct tc_run_container_return ret = tc_run_container(requestId);

// ...
}
```
</details>

## Creating New Modules

Just do it! Any pull requests are welcome,
and you can also create modules as standalone repositories.

### Where to Publish Modules?

Some modules are stored in [this repository](https://github.com/testcontainers/testcontainers-c) for demo and prototyping purposes.
You are welcome to add your modules there too.
If you develop new modules, once `vcpkg` or `Conan` packaging is implemented for Testcontainers C,
you might want to develop your module in a standalone repository instead.

0 comments on commit 30eb580

Please sign in to comment.