-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from walkerus/admin-client
Add wiremock admin client
- Loading branch information
Showing
9 changed files
with
225 additions
and
151 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module wiremock.org/testcontainers-go-quickstart | ||
|
||
go 1.19 | ||
|
||
require ( | ||
github.com/wiremock/go-wiremock v1.7.1 | ||
github.com/wiremock/wiremock-testcontainers-go v1.0.0-alpha-6 | ||
) | ||
|
||
require ( | ||
dario.cat/mergo v1.0.0 // indirect | ||
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect | ||
github.com/Microsoft/go-winio v0.6.1 // indirect | ||
github.com/cenkalti/backoff/v4 v4.2.0 // indirect | ||
github.com/containerd/containerd v1.7.3 // indirect | ||
github.com/cpuguy83/dockercfg v0.3.1 // indirect | ||
github.com/docker/distribution v2.8.2+incompatible // indirect | ||
github.com/docker/docker v24.0.5+incompatible // indirect | ||
github.com/docker/go-connections v0.4.0 // indirect | ||
github.com/docker/go-units v0.5.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/uuid v1.3.0 // indirect | ||
github.com/klauspost/compress v1.16.0 // indirect | ||
github.com/magiconair/properties v1.8.7 // indirect | ||
github.com/moby/patternmatcher v0.5.0 // indirect | ||
github.com/moby/sys/sequential v0.5.0 // indirect | ||
github.com/moby/term v0.5.0 // indirect | ||
github.com/morikuni/aec v1.0.0 // indirect | ||
github.com/opencontainers/go-digest v1.0.0 // indirect | ||
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect | ||
github.com/opencontainers/runc v1.1.5 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/sirupsen/logrus v1.9.0 // indirect | ||
github.com/testcontainers/testcontainers-go v0.22.0 // indirect | ||
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect | ||
golang.org/x/mod v0.9.0 // indirect | ||
golang.org/x/net v0.9.0 // indirect | ||
golang.org/x/sys v0.9.0 // indirect | ||
golang.org/x/tools v0.7.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect | ||
google.golang.org/grpc v1.57.0 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
) | ||
|
||
replace github.com/wiremock/wiremock-testcontainers-go => ../../../wiremock-testcontainers-go // needed to use new method written localy in the quickstart_test.go |
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,55 @@ | ||
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 := RunContainer(ctx) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Clean up the container after the test is complete | ||
t.Cleanup(func() { | ||
if err := container.Terminate(ctx); err != nil { | ||
t.Fatalf("failed to terminate container: %s", 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) | ||
} | ||
} |
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
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