Skip to content

Commit

Permalink
Add API for terminating containers
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-nenashev committed Sep 25, 2023
1 parent d7dc97b commit a497066
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions demo/google-test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const char* WIREMOCK_ADMIN_MAPPING_ENDPOINT = "/__admin/mappings";
};

void TearDown() override {
// Code here will be called immediately after each test (right
// before the destructor).
char* error = tc_terminate_container(containerId);
ASSERT_EQ(error, nullptr) << "Failed to terminate the container after the test: " << error;
};

int containerId;
Expand Down
12 changes: 11 additions & 1 deletion testcontainers-c/testcontainers-c.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ func _RunContainer(requestID int) (id int, ok bool, err error) {
return containerId, true, nil
}

//export tc_terminate_container
func tc_terminate_container(containerID int) *C.char {
ctx := context.Background()
container := *containers[containerID]
return ToCString(container.Terminate(ctx))
}

//export tc_get_container_log
func tc_get_container_log(containerID int) (log *C.char) {
ctx := context.Background()
Expand Down Expand Up @@ -187,7 +194,10 @@ func SendHttpRequest(httpMethod string, container testcontainers.Container, port
}

func ToCString(err error) *C.char {
return C.CString(fmt.Sprintf("%v", err))
if err != nil {
return C.CString(fmt.Sprintf("%v", err))
}
return nil
}

func main() {}

0 comments on commit a497066

Please sign in to comment.