Skip to content
Snippets Groups Projects
Commit b8eba847 authored by Will McCutchen's avatar Will McCutchen
Browse files

Add library use case to README

parent a4831155
No related branches found
No related tags found
No related merge requests found
...@@ -30,6 +30,37 @@ Docker images are published to [Docker Hub][docker-hub]: ...@@ -30,6 +30,37 @@ Docker images are published to [Docker Hub][docker-hub]:
$ docker run -P mccutchen/go-httpbin $ docker run -P mccutchen/go-httpbin
``` ```
The `github.com/mccutchen/go-httpbin/httpbin` package can also be used as a
library for testing an applications interactions with an upstream HTTP service,
like so:
```go
package httpbin_test
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/mccutchen/go-httpbin/httpbin"
)
func TestSlowResponse(t *testing.T) {
handler := httpbin.NewHTTPBin().Handler()
srv := httptest.NewServer(handler)
defer srv.Close()
client := http.Client{
Timeout: time.Duration(1 * time.Second),
}
_, err := client.Get(srv.URL + "/delay/10")
if err == nil {
t.Fatal("expected timeout error")
}
}
```
## Installation ## Installation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment