-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathsplit_test.go
59 lines (47 loc) · 1.46 KB
/
split_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
52
53
54
55
56
57
58
59
package proxy_test
import (
"io"
"net/http"
"testing"
"time"
"github.com/zalando/skipper/eskip"
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/filters/builtin"
"github.com/zalando/skipper/predicates/tee"
"github.com/zalando/skipper/proxy/proxytest"
"github.com/zalando/skipper/routing"
)
// test filter used in TestRequestURIClonedOnSplit
type dependentFilter chan string
func (f dependentFilter) Name() string { return "dependentFilter" }
func (f dependentFilter) CreateFilter([]interface{}) (filters.Filter, error) { return f, nil }
func (f dependentFilter) Response(filters.FilterContext) {}
func (f dependentFilter) Request(ctx filters.FilterContext) {
f <- ctx.Request().RequestURI
}
func TestRequestURIClonedOnSplit(t *testing.T) {
const routes = `
main: * -> teeLoopback("test") -> <shunt>;
shadow: Tee("test") -> dependentFilter() -> <shunt>
`
r := eskip.MustParse(routes)
df := make(dependentFilter)
fr := builtin.MakeRegistry()
fr.Register(df)
p := proxytest.WithRoutingOptions(fr, routing.Options{Predicates: []routing.PredicateSpec{tee.New()}}, r...)
defer p.Close()
rsp, err := http.Get(p.URL + "/foo")
if err != nil {
t.Fatal(err)
}
defer rsp.Body.Close()
io.Copy(io.Discard, rsp.Body)
select {
case uri := <-df:
if uri != "/foo" {
t.Fatalf("expected /foo, got: %s", uri)
}
case <-time.After(120 * time.Millisecond):
t.Fatal("test timeout")
}
}