diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-04-24 20:11:36 -0400 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-04-24 20:11:36 -0400 |
commit | f5437632f486b7d0a0a181c58f113c86d032b02c (patch) | |
tree | 407388e3003a210a89f4b2128d7ad656f8b79d26 /vendor/github.com/prometheus/common/route/route_test.go | |
parent | 7f68a60f8c228d5604e0566bf84cabb145d16c37 (diff) | |
download | chat-f5437632f486b7d0a0a181c58f113c86d032b02c.tar.gz chat-f5437632f486b7d0a0a181c58f113c86d032b02c.tar.bz2 chat-f5437632f486b7d0a0a181c58f113c86d032b02c.zip |
Upgrading server dependancies (#6215)
Diffstat (limited to 'vendor/github.com/prometheus/common/route/route_test.go')
-rw-r--r-- | vendor/github.com/prometheus/common/route/route_test.go | 45 |
1 files changed, 7 insertions, 38 deletions
diff --git a/vendor/github.com/prometheus/common/route/route_test.go b/vendor/github.com/prometheus/common/route/route_test.go index e7b1cba33..a9bb20996 100644 --- a/vendor/github.com/prometheus/common/route/route_test.go +++ b/vendor/github.com/prometheus/common/route/route_test.go @@ -1,16 +1,13 @@ package route import ( - "fmt" "net/http" "net/http/httptest" "testing" - - "golang.org/x/net/context" ) func TestRedirect(t *testing.T) { - router := New(nil).WithPrefix("/test/prefix") + router := New().WithPrefix("/test/prefix") w := httptest.NewRecorder() r, err := http.NewRequest("GET", "http://localhost:9090/foo", nil) if err != nil { @@ -29,47 +26,19 @@ func TestRedirect(t *testing.T) { } } -func TestContextFunc(t *testing.T) { - router := New(func(r *http.Request) (context.Context, error) { - return context.WithValue(context.Background(), "testkey", "testvalue"), nil - }) - - router.Get("/test", func(w http.ResponseWriter, r *http.Request) { - want := "testvalue" - got := Context(r).Value("testkey") +func TestContext(t *testing.T) { + router := New() + router.Get("/test/:foo/", func(w http.ResponseWriter, r *http.Request) { + want := "bar" + got := Param(r.Context(), "foo") if want != got { t.Fatalf("Unexpected context value: want %q, got %q", want, got) } }) - r, err := http.NewRequest("GET", "http://localhost:9090/test", nil) + r, err := http.NewRequest("GET", "http://localhost:9090/test/bar/", nil) if err != nil { t.Fatalf("Error building test request: %s", err) } router.ServeHTTP(nil, r) } - -func TestContextFnError(t *testing.T) { - router := New(func(r *http.Request) (context.Context, error) { - return context.Background(), fmt.Errorf("test error") - }) - - router.Get("/test", func(w http.ResponseWriter, r *http.Request) {}) - - r, err := http.NewRequest("GET", "http://localhost:9090/test", nil) - if err != nil { - t.Fatalf("Error building test request: %s", err) - } - w := httptest.NewRecorder() - router.ServeHTTP(w, r) - - if w.Code != http.StatusBadRequest { - t.Fatalf("Unexpected response status: got %q, want %q", w.Code, http.StatusBadRequest) - } - - want := "Error creating request context: test error\n" - got := w.Body.String() - if want != got { - t.Fatalf("Unexpected response body: got %q, want %q", got, want) - } -} |