MCPcopy Index your code
hub / github.com/zalando/skipper / testLoopback

Function testLoopback

proxy/loopback_test.go:55–167  ·  view source on GitHub ↗
(
	t *testing.T,
	routes string,
	params Params,
	input *url.URL,
	expectedStatus int,
	expectedHeader http.Header,
)

Source from the content-addressed store, hash-verified

53}
54
55func testLoopback(
56 t *testing.T,
57 routes string,
58 params Params,
59 input *url.URL,
60 expectedStatus int,
61 expectedHeader http.Header,
62) {
63 var backend *httptest.Server
64 backend = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
65 if params.Flags.PreserveOriginal() {
66 if r.Header.Get("X-Test-Preserved") != "test-value" {
67 t.Error("failed to preserve original request")
68 return
69 }
70
71 w.Header().Set("X-Test", "test-value")
72 }
73
74 if params.Flags.PreserveHost() && r.Host != "www.example.org" {
75 t.Error("failed to preserve host")
76 } else if !params.Flags.PreserveHost() {
77 u, err := url.Parse(backend.URL)
78 if err != nil {
79 t.Error(err)
80 return
81 }
82
83 if r.Host != u.Host {
84 t.Error("failed to set host")
85 return
86 }
87 }
88
89 w.Header().Set("X-Backend-Done", "true")
90 }))
91 defer backend.Close()
92
93 routes = strings.ReplaceAll(routes, "$backend", backend.URL)
94
95 fr := builtin.MakeRegistry()
96 fr.Register(&preserveOriginalSpec{})
97 fr.Register(&returnPathParam{})
98 fr.Register(&setState{})
99 fr.Register(&returnState{})
100 fr.Register(builtin.NewLoopbackIfStatus())
101
102 p, err := newTestProxyWithFiltersAndParams(fr, routes, params, nil)
103 if err != nil {
104 t.Error(err)
105 return
106 }
107
108 defer p.close()
109
110 var u *url.URL
111 if input == nil {
112 u, err = url.ParseRequestURI("https://www.example.org/test/path")

Callers 11

TestLoopbackShuntFunction · 0.85
TestLoopbackWithBackendFunction · 0.85
TestLoopbackReachLimitFunction · 0.85
TestLoopbackPreserveHostFunction · 0.85
TestLoopbackFilterShuntFunction · 0.85
TestLoopbackPathParamsFunction · 0.85
TestLoopbackStatebagFunction · 0.85
TestLoopbackWithResponseFunction · 0.85

Calls 14

MakeRegistryFunction · 0.92
NewLoopbackIfStatusFunction · 0.92
PreserveOriginalMethod · 0.80
PreserveHostMethod · 0.80
RegisterMethod · 0.80
GetMethod · 0.65
ErrorMethod · 0.65
SetMethod · 0.65
ParseMethod · 0.65
CloseMethod · 0.65
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…