MCPcopy
hub / github.com/go-kit/kit / TestMultipleServerAfter

Function TestMultipleServerAfter

transport/http/server_test.go:137–180  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestMultipleServerAfter(t *testing.T) {
138 var (
139 headerKey = "X-Henlo-Lizer"
140 headerVal = "Helllo you stinky lizard"
141 statusCode = http.StatusTeapot
142 responseBody = "go eat a fly ugly\n"
143 done = make(chan struct{})
144 )
145 handler := httptransport.NewServer(
146 endpoint.Nop,
147 func(context.Context, *http.Request) (interface{}, error) {
148 return struct{}{}, nil
149 },
150 func(_ context.Context, w http.ResponseWriter, _ interface{}) error {
151 w.Header().Set(headerKey, headerVal)
152 w.WriteHeader(statusCode)
153 w.Write([]byte(responseBody))
154 return nil
155 },
156 httptransport.ServerAfter(func(ctx context.Context, w http.ResponseWriter) context.Context {
157 ctx = context.WithValue(ctx, "one", 1)
158
159 return ctx
160 }),
161 httptransport.ServerAfter(func(ctx context.Context, w http.ResponseWriter) context.Context {
162 if _, ok := ctx.Value("one").(int); !ok {
163 t.Error("Value was not set properly when multiple ServerAfters are used")
164 }
165
166 close(done)
167 return ctx
168 }),
169 )
170
171 server := httptest.NewServer(handler)
172 defer server.Close()
173 go http.Get(server.URL)
174
175 select {
176 case <-done:
177 case <-time.After(time.Second):
178 t.Fatal("timeout waiting for finalizer")
179 }
180}
181
182func TestServerFinalizer(t *testing.T) {
183 var (

Callers

nothing calls this directly

Calls 7

SetMethod · 0.65
WriteMethod · 0.65
WriteHeaderMethod · 0.45
ValueMethod · 0.45
ErrorMethod · 0.45
CloseMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…