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

Function TestMultipleServerBefore

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

Source from the content-addressed store, hash-verified

90}
91
92func TestMultipleServerBefore(t *testing.T) {
93 var (
94 headerKey = "X-Henlo-Lizer"
95 headerVal = "Helllo you stinky lizard"
96 statusCode = http.StatusTeapot
97 responseBody = "go eat a fly ugly\n"
98 done = make(chan struct{})
99 )
100 handler := httptransport.NewServer(
101 endpoint.Nop,
102 func(context.Context, *http.Request) (interface{}, error) {
103 return struct{}{}, nil
104 },
105 func(_ context.Context, w http.ResponseWriter, _ interface{}) error {
106 w.Header().Set(headerKey, headerVal)
107 w.WriteHeader(statusCode)
108 w.Write([]byte(responseBody))
109 return nil
110 },
111 httptransport.ServerBefore(func(ctx context.Context, r *http.Request) context.Context {
112 ctx = context.WithValue(ctx, "one", 1)
113
114 return ctx
115 }),
116 httptransport.ServerBefore(func(ctx context.Context, r *http.Request) context.Context {
117 if _, ok := ctx.Value("one").(int); !ok {
118 t.Error("Value was not set properly when multiple ServerBefores are used")
119 }
120
121 close(done)
122 return ctx
123 }),
124 )
125
126 server := httptest.NewServer(handler)
127 defer server.Close()
128 go http.Get(server.URL)
129
130 select {
131 case <-done:
132 case <-time.After(time.Second):
133 t.Fatal("timeout waiting for finalizer")
134 }
135}
136
137func TestMultipleServerAfter(t *testing.T) {
138 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…