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

Add a testcontainers_wiremock#RunContainerAndStopOnCleanup() method to simplify automatic termination #30

Merged
Merged
Changes from 1 commit
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
35 changes: 21 additions & 14 deletions examples/quickstart/quickstart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"testing"
)

func TestWireMock(t *testing.T) {
func SetupAndCleanupContainer(t *testing.T, mappingFilePath string, testFunc func(container *Container, t *testing.T)) {
// Create Container
ctx := context.Background()
container, err := RunContainer(ctx,
WithMappingFile("hello", "hello-world.json"),
WithMappingFile("hello", mappingFilePath),
)
if err != nil {
t.Fatal(err)
Expand All @@ -23,18 +23,25 @@ func TestWireMock(t *testing.T) {
}
})

// Send a simple HTTP GET request to the mocked API
statusCode, out, err := SendHttpGet(container, "/hello", nil)
if err != nil {
t.Fatal(err, "Failed to get a response")
}
// Execute the test function with the container
testFunc(container, t)
}

// Verify the response
if statusCode != 200 {
t.Fatalf("expected HTTP-200 but got %d", statusCode)
}
func TestWireMock(t *testing.T) {
SetupAndCleanupContainer(t, "hello-world.json", func(container *Container, t *testing.T) {
// Send a simple HTTP GET request to the mocked API
statusCode, out, err := SendHttpGet(container, "/hello", nil)
if err != nil {
t.Fatal(err, "Failed to get a response")
}

if string(out) != "Hello, world!" {
t.Fatalf("expected 'Hello, world!' but got %v", string(out))
}
// Verify the response
if statusCode != 200 {
t.Fatalf("expected HTTP-200 but got %d", statusCode)
}

if string(out) != "Hello, world!" {
t.Fatalf("expected 'Hello, world!' but got %v", string(out))
}
})
}