MCPcopy Create free account
hub / github.com/zalando/skipper / TestQueryLogHandler

Function TestQueryLogHandler

net/query_test.go:57–103  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

55}
56
57func TestQueryLogHandler(t *testing.T) {
58 for _, ti := range []struct {
59 name string
60 routes string
61 query string
62 expected int
63 }{
64 {
65 name: "request without query",
66 routes: `r: * -> inlineContent("OK") -> <shunt>;`,
67 query: "",
68 expected: http.StatusOK,
69 },
70 {
71 name: "request with query",
72 routes: `r1: Query("foo") -> status(400) -> inlineContent("FAIL") -> <shunt> ;r2: * -> inlineContent("OK") -> <shunt>;`,
73 query: "foo=bar",
74 expected: http.StatusOK,
75 },
76 {
77 name: "request with bad query does not block",
78 routes: `r1: Query("foo") -> status(400) -> inlineContent("FAIL") -> <shunt> ;r2: * -> inlineContent("OK") -> <shunt>;`,
79 query: "foo=bar;",
80 expected: http.StatusOK,
81 },
82 } {
83 t.Run(ti.name, func(t *testing.T) {
84
85 req, err := http.NewRequest("GET", "/path", nil)
86 if err != nil {
87 t.Fatal(err)
88 }
89 req.URL.RawQuery = ti.query
90
91 noop := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
92 recorder := httptest.NewRecorder()
93 h := &ValidateQueryLogHandler{
94 Handler: noop,
95 }
96 h.ServeHTTP(recorder, req)
97
98 if recorder.Code != ti.expected {
99 t.Fatalf("Failed to get expected code %d, got %d", ti.expected, recorder.Code)
100 }
101 })
102 }
103}

Callers

nothing calls this directly

Calls 1

ServeHTTPMethod · 0.95

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…