-
Notifications
You must be signed in to change notification settings - Fork 12
/
using_api_client_test.go
47 lines (39 loc) · 1.05 KB
/
using_api_client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package testcontainers_wiremock_using_api_client
import (
"context"
"net/http"
"testing"
"github.com/wiremock/go-wiremock"
. "github.com/wiremock/wiremock-testcontainers-go"
)
func TestWireMock(t *testing.T) {
// Create Container
ctx := context.Background()
container, err := RunDefaultContainerAndStopOnCleanup(ctx)
if err != nil {
t.Fatal(err)
}
// Use the WireMock client to stub a new endpoint manually
err = container.Client.StubFor(
wiremock.Get(wiremock.URLEqualTo("/hello")).
WillReturnResponse(
wiremock.NewResponse().
WithJSONBody(map[string]string{"result": "Hello, world!"}).
WithHeader("Content-Type", "application/json").
WithStatus(http.StatusOK),
),
)
if err != nil {
t.Fatal(err)
}
statusCode, out, err := SendHttpGet(container, "/hello", nil)
if err != nil {
t.Fatal(err, "Failed to get a response")
}
if statusCode != 200 {
t.Fatalf("expected HTTP-200 but got %d", statusCode)
}
if string(out) != `{"result":"Hello, world!"}` {
t.Fatalf("expected 'Hello, world!' but got %v", out)
}
}