-
Notifications
You must be signed in to change notification settings - Fork 3
/
prefix_test.go
42 lines (38 loc) · 972 Bytes
/
prefix_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package strip
import (
"github.com/go-martini/martini"
"net/http"
"net/http/httptest"
"testing"
)
func TestStripPrefix(t *testing.T) {
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/foo/bar", nil)
Prefix("/foo").(func(http.ResponseWriter, *http.Request))(w, r)
if r.URL.Path != "/bar" {
t.Fatalf("Strip Prefix Failed")
}
}
func TestInMartini(t *testing.T) {
m := martini.New()
m.Use(Prefix("/foo"))
m.Use(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/bar" {
t.Fatalf("Strip Prefix Failed")
}
})
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/foo/bar", nil)
m.ServeHTTP(w, r)
}
func TestInRequestContext(t *testing.T) {
m := martini.Classic()
m.Get("/foo/bar", Prefix("/foo"), func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/bar" {
t.Fatalf("Strip Prefix Failed")
}
})
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/foo/bar", nil)
m.ServeHTTP(w, r)
}