From b8eba84745c9f06b5c4e5cc952b31dcff7419b49 Mon Sep 17 00:00:00 2001 From: Will McCutchen <will@mccutch.org> Date: Sun, 25 Jun 2017 13:59:06 -0700 Subject: [PATCH] Add library use case to README --- README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/README.md b/README.md index f200377..e241835 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,37 @@ Docker images are published to [Docker Hub][docker-hub]: $ 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 -- GitLab