-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathpathpatch_test.go
51 lines (40 loc) · 1.05 KB
/
pathpatch_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
43
44
45
46
47
48
49
50
51
package proxy
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/zalando/skipper/dataclients/routestring"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/routing"
)
func testPatch(t *testing.T, title string, f Flags, expectedStatus int) {
t.Run(title, func(t *testing.T) {
dc, err := routestring.New(`Path("/foo%2Fbar") -> status(200) -> <shunt>`)
if err != nil {
t.Fatal(err)
}
rt := routing.New(routing.Options{
SignalFirstLoad: true,
FilterRegistry: builtin.MakeRegistry(),
DataClients: []routing.DataClient{dc},
})
defer rt.Close()
p := WithParams(Params{Routing: rt, Flags: f})
defer p.Close()
s := httptest.NewServer(p)
defer s.Close()
<-rt.FirstLoad()
rsp, err := http.Get(s.URL + "/foo%2Fbar")
if err != nil {
t.Fatal(err)
}
defer rsp.Body.Close()
if rsp.StatusCode != expectedStatus {
t.Error()
}
})
}
func TestPathPatch(t *testing.T) {
testPatch(t, "not patched", FlagsNone, http.StatusNotFound)
testPatch(t, "patched", PatchPath, http.StatusOK)
}