test: add AddPrefix test.
This commit is contained in:
parent
2d1ddcf28b
commit
18c3d8dc62
1 changed files with 29 additions and 0 deletions
29
middlewares/addPrefix_test.go
Normal file
29
middlewares/addPrefix_test.go
Normal file
|
@ -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.")
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue