-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split WireMock Module and Generic Container demos
- Loading branch information
1 parent
26e3129
commit 9d85469
Showing
10 changed files
with
61 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
# Builds Demos with embedded tests | ||
add_subdirectory(generic-container) | ||
add_subdirectory(wiremock) |
This file contains 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,15 @@ | ||
project(testcontainers-c-generic-container-demo | ||
VERSION 0.0.1 | ||
DESCRIPTION "Demonstrates usage of the generic container API in a simple main app") | ||
|
||
set(TARGET_OUT demo_generic_container.out) | ||
|
||
include_directories(${testcontainers-c_SOURCE_DIR}) | ||
# WORKING_DIRECTORY breaks shared lib loading | ||
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
# Vanilla Demo for WireMock | ||
add_executable(${TARGET_OUT} generic_container_demo.c) | ||
add_dependencies(${TARGET_OUT} testcontainers-c-shim) | ||
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c) | ||
add_test(NAME generic_container_demo COMMAND ${TARGET_OUT}) |
This file contains 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,19 @@ | ||
# Demo - Generic Container on Testcontainers C | ||
|
||
Demonstrates usage of the generic container API provided by the Testcontainers C library. | ||
In this demo, we do not use any module SDKs or test frameworks, just a simple `main()` function. | ||
|
||
## Running demo | ||
|
||
From the root of the repository: | ||
|
||
```bash | ||
cmake . | ||
cmake --build . | ||
cd demo/generic-container | ||
./demo_generic_container.out | ||
``` | ||
|
||
## Sample output | ||
|
||
![Sample Output](./sample_output.png) |
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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!" | ||
} | ||
} | ||
|
This file contains 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 |
---|---|---|
@@ -1,23 +1,17 @@ | ||
project(testcontainers-c-wiremock-demo VERSION 0.0.1 | ||
project(testcontainers-c-wiremock-demo | ||
VERSION 0.0.1 | ||
DESCRIPTION "Demonstrates usage of the WireMock module for Testcontainers C in a simple main app") | ||
|
||
set(TARGET_OUT demo_wiremock_module.out) | ||
set(VANILLA_OUT demo_vanilla.out) | ||
|
||
include_directories(${testcontainers-c_SOURCE_DIR}) | ||
# WORKING_DIRECTORY breaks shared lib loading | ||
file(COPY test_data DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) | ||
|
||
# Vanilla Demo for WireMock | ||
add_executable(${VANILLA_OUT} wiremock_demo_vanilla.c) | ||
add_dependencies(${VANILLA_OUT} testcontainers-c-shim) | ||
target_link_libraries(${VANILLA_OUT} PRIVATE testcontainers-c) | ||
add_test(NAME vanilla_smoke COMMAND ${VANILLA_OUT}) | ||
|
||
# WireMock Module demo | ||
add_executable(${TARGET_OUT} wiremock_demo.c) | ||
add_dependencies(${VANILLA_OUT} testcontainers-c-shim) | ||
add_executable(${TARGET_OUT} wiremock_module_demo.c) | ||
add_dependencies(${TARGET_OUT} testcontainers-c-shim) | ||
target_include_directories(${TARGET_OUT} PRIVATE ${testcontainers-c-wiremock_SOURCE_DIR}) | ||
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c) | ||
target_link_libraries(${TARGET_OUT} PRIVATE testcontainers-c-wiremock) | ||
add_test(NAME wiremock_module_smoke COMMAND ${TARGET_OUT}) | ||
add_test(NAME wiremock_module_demo COMMAND ${TARGET_OUT}) |
This file contains 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 |
---|---|---|
@@ -1,60 +1,19 @@ | ||
# Demo - WireMock on Testcontainers C | ||
|
||
Demonstrates usage of the [WireMock](https://wiremock.org/) module in a simple main function. | ||
Demonstrates usage of the [WireMock Module for Testcontainers C](../../modules/wiremock/) in a simple main function. | ||
No test framework is used here. | ||
|
||
## Running demo | ||
|
||
From the root of the repository: | ||
|
||
```bash | ||
cmake . | ||
cmake --build . | ||
cd demo/wiremock | ||
./demo.out | ||
./demo_wiremock_module.out | ||
``` | ||
|
||
## Sample output | ||
|
||
![Sample Output](./sample_output.png) | ||
|
||
## Wishlist | ||
|
||
The library implementation and api is sub-optimal at the moment. | ||
This is how we want to see the code once everything is done, maybe: | ||
|
||
```c | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include "testcontainers-c.h" | ||
#include "testcontainers-c-wiremock.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 = NewContainerRequest(DEFAULT_IMAGE); | ||
WithExposedTcpPort(requestId, 8080); | ||
WithWaitForHttp(requestId, 8080, "/__admin/mappings"); | ||
WithFile(requestId, "test_data/hello.json", "/home/wiremock/mappings/hello.json"); | ||
struct TestContainer container = RunContainer(requestId); | ||
if (container.Id == -1) { | ||
printf("Failed to run the container: %s\n", container.errorMsg); | ||
return -1; | ||
} | ||
|
||
printf("Sending HTTP request to the container\n"); | ||
struct HttpGetResponse response = SendHttpGet(container.Id, 8080, "/hello"); | ||
if (response.code == -1) { | ||
printf("Failed to send HTTP request: %s\n", response.errorMsg); | ||
return -1; | ||
} | ||
if (response.code != 200) { | ||
printf("Request failed: HTTP-%d\n%s\n", response.code, response.errorMsg); | ||
return -1; | ||
} | ||
printf("Server Response: HTTP-%d\n%s\n\n", response.code, response.msg); | ||
return 0; | ||
} | ||
``` |
File renamed without changes.