From 18c3d8dc62e2a93ed0ee201f94336df400a0802b Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 6 Jun 2017 13:19:01 +0200 Subject: [PATCH] test: add AddPrefix test. --- middlewares/addPrefix_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 middlewares/addPrefix_test.go diff --git a/middlewares/addPrefix_test.go b/middlewares/addPrefix_test.go new file mode 100644 index 000000000..a3af7a7a4 --- /dev/null +++ b/middlewares/addPrefix_test.go @@ -0,0 +1,29 @@ +package middlewares + +import ( + "net/http" + "testing" + + "github.com/containous/traefik/testhelpers" + "github.com/stretchr/testify/assert" +) + +func TestAddPrefix(t *testing.T) { + + path := "/bar" + prefix := "/foo" + + var expectedPath string + handler := &AddPrefix{ + Prefix: prefix, + Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + expectedPath = r.URL.Path + }), + } + + req := testhelpers.MustNewRequest(http.MethodGet, "http://localhost"+path, nil) + + handler.ServeHTTP(nil, req) + + assert.Equal(t, expectedPath, "/foo/bar", "Unexpected path.") +}