Skip to content

Commit

Permalink
Update README with a small usage section
Browse files Browse the repository at this point in the history
  • Loading branch information
callebjorkell committed Jan 11, 2024
1 parent 392ddee commit 57d2937
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,36 @@ Implementing these checks in tests will allow your application to check API corr
before the code ever hits production. As long as the specification and application is not edited in the same change set,
breaking changes will also be prevented. Since the verification runs during builds only, there is no overhead during
production use, nor does Copper impose any sort of requirements on the implementation other than that it needs to
conform to its own specification.
conform to its own specification.

## Usage
Copper is used from integration style tests. Wrap the HTTP client being used in copper
and then use that client for performing the API calls in your test case. This works best from
a single main test for a single spec, and then subtest for the specific endpoints/use cases.

```go
func TestVersion1(t *testing.T) {
f, err := os.Open("spec.yaml")
if err != nil {
t.Fatal(err)
}
defer f.Close()

client, err := copper.WrapClient(http.DefaultClient, f)
if err != nil {
t.Fatal(err)
}

t.Run("ping", func(t *testing.T) {
testPingEndpoints(t, client)
}
t.Run("other use case that I have", func(t *testing.T) {
testMyOtherThing(t, client)
}

// Verifying at the end checks that all paths, methods and responses are covered and that no extra paths have been hit.
client.Verify(t)
}
```

See the [examples](examples) for complete examples.

0 comments on commit 57d2937

Please sign in to comment.