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 integration test for wiremock v3 #42

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ Just a teaser of how it feels at the real speed!
## Requirements

- Golang version 1.17 or above, so all modern Golang projects should be compatible with it.
- The module supports the official [WireMock Docker](https://github.com/wiremock/wiremock-docker) images 2.35.0-1 or above.
- The module supports the official [WireMock Docker](https://github.com/wiremock/wiremock-docker) images
- for v2 - 2.35.0-1 or above
- for v3 - 3.9.1 or above (check Usage section on how to use v3)
- Custom images are supported too as long as they follow the same CLI and API structure.

## Usage
Expand All @@ -47,6 +49,7 @@ func TestWireMock(t *testing.T) {
// Create Container
ctx := context.Background()
container, err := RunContainerAndStopOnCleanup(ctx,
// WithImage("docker.io/wiremock/wiremock:3.9.1"), for v3
ninadingole marked this conversation as resolved.
Show resolved Hide resolved
WithMappingFile("hello", "hello-world.json"),
)
if err != nil {
Expand Down
16 changes: 15 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Create the `hello-world.json` file with the following content:

In `func TestWireMock(t *testing.T)`, add the following code:

### wiremock v2
```go
// Create Container
ctx := context.Background()
Expand All @@ -82,6 +83,19 @@ if err != nil {
}
```

### wiremock v3
```go
// Create Container
ctx := context.Background()
container, err := RunContainerAndStopOnCleanup(ctx, t,
WithImage("docker.io/wiremock/wiremock:3.9.1"),
WithMappingFile("hello", "hello-world.json"),
)
if err != nil {
t.Fatal(err)
}
```

## Add logic to send a request

Now, we will need to send an HTTP request to our test API.
Expand All @@ -101,7 +115,7 @@ func TestWireMock(t *testing.T) {
}
```

In the code above, we used the `SendHttpGet` method to send a HTTP GET request. The library also offers methods to send requests with other HTTP methods, i.e. `SendHttpPost`, `SendHttpDelete`,`SendHttpPatch`, `SendHttpPut`.
In the code above, we used the `SendHttpGet` method to send a HTTP GET request. The library also offers methods to send requests with other HTTP methods, i.e. `SendHttpPost`, `SendHttpDelete`,`SendHttpPatch`, `SendHttpPut`.

## Verify the response

Expand Down
17 changes: 17 additions & 0 deletions examples/quickstart-v3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Quick Start - WireMockV3 on Testcontainers Go

See the [Quickstart Guide](../../docs/quickstart.md)

## Pre-requisites

- Go 1.20 or above
- Docker-API compatible container runtime ([more info](https://golang.testcontainers.org/system_requirements/docker/))

## TL;DR

```bash
git clone https://github.com/wiremock/wiremock-testcontainers-go repository
cd wiremock-testcontainers-go/examples/quickstart-v3
go mod download
go test
```
60 changes: 60 additions & 0 deletions examples/quickstart-v3/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module wiremock.org/testcontainers-go-quickstart

go 1.21

require github.com/wiremock/wiremock-testcontainers-go v1.0.0-alpha-7

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/Microsoft/hcsshim v0.11.4 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.15 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/docker v25.0.5+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.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 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/testcontainers/testcontainers-go v0.31.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/wiremock/go-wiremock v1.8.0 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/mod v0.16.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230731190214-cbb8c96f2d6d // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)

replace github.com/wiremock/wiremock-testcontainers-go => ../../../wiremock-testcontainers-go // needed to use new method written localy in the quickstart_test.go
Loading