/
issue57_test.go
44 lines (39 loc) · 1.01 KB
/
issue57_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
package route
import (
"net/http"
"testing"
)
// TestIssue57 tests that after deleting a all targets for
// a route requests to that route are handled by the next
// matching route.
func TestIssue57(t *testing.T) {
tests := []string{
`
route add svca / http://foo.com:800
route add svcb /foo http://foo.com:900
route del svcb /foo http://foo.com:900`,
`
route add svca / http://foo.com:800
route add svcb /foo http://foo.com:900
route del svcb /foo`,
`
route add svca / http://foo.com:800
route add svcb /foo http://foo.com:900
route del svcb`,
}
req := &http.Request{URL: mustParse("/foo")}
want := "http://foo.com:800"
for i, tt := range tests {
tbl, err := NewTable(tt)
if err != nil {
t.Fatalf("%d: got %v want nil", i, err)
}
target := tbl.Lookup(req, "", rrPicker, prefixMatcher, globEnabled)
if target == nil {
t.Fatalf("%d: got %v want %v", i, target, want)
}
if got := target.URL.String(); got != want {
t.Errorf("%d: got %v want %v", i, got, want)
}
}
}