Skip to content

Commit

Permalink
Merge pull request #126 from oleg-nenashev/golang-solution
Browse files Browse the repository at this point in the history
Document WireMock and Golang
  • Loading branch information
oleg-nenashev authored Jul 13, 2023
2 parents bd87db7 + 216b9ee commit 636be60
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
73 changes: 72 additions & 1 deletion _docs/solutions/golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,76 @@ title: "WireMock and Go"
meta_title: "Golang Solutions | WireMock"
description: "Additional solutions for WireMock when using Golang"
logo: /images/logos/technology/golang.svg
coming-soon: true
redirect_from:
- "/go.html"
- "/go/"
hide-disclaimer: true
---

## Testcontainers module for Go

The WireMock community provides a [Testcontainers for Go](https://golang.testcontainers.org/) module
which allows using WireMock single-shot containers within Golang tests.
This module can run any [WireMock Docker](https://github.com/wiremock/wiremock-docker) compatible images,
see the [documentation](https://github.com/wiremock/wiremock-testcontainers-go) for detailed usage guidelines and examples.

Example:

```golang
import (
// ...
"github.com/wiremock/wiremock-testcontainers-go"
)

func TestWireMock(t *testing.T) {
// Create Container and clean it up upon completion
ctx := context.Background()
container, err := RunContainer(ctx,
WithMappingFile("hello", filepath.Join("testdata", "hello-world.json")),
)
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := container.Terminate(ctx); err != nil {
t.Fatalf("failed to terminate container: %s", err)
}
})

uri, err := GetURI(ctx, container)
if err != nil {
t.Fatal(err, "unable to get container endpoint")
}

// Checks
statusCode, out, err := SendHttpGet(uri, "/hello")
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) != "Hello, world!" {
t.Fatalf("expected 'Hello, world!' but got %v", string(out))
}
}
```

References:

- [GitHub Repository](https://github.com/wiremock/wiremock-testcontainers-go)

## Golang WireMock admin client

A simple Golang client for [WireMock Administrative REST API](../../standalone/administration)
that allows configuring WireMock API endpoints in your code and tests.

References:

- [Documentation](https://pkg.go.dev/github.com/walkerus/go-wiremock)
- [GitHub Repository](https://github.com/walkerus/go-wiremock)

## Useful pages

- [WireMock and Docker](../docker)
- [WireMock and Kubernetes](../kubernetes)
4 changes: 4 additions & 0 deletions _docs/solutions/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ The project is under active development, and the contributions are welcome!
References:

- [GitHub Repository](https://github.com/wiremock/grpc-wiremock)

## Useful pages

- [WireMock and Golang](../golang) - There's WireMock for Golang developers too!

0 comments on commit 636be60

Please sign in to comment.