| 135 | } |
| 136 | |
| 137 | func 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 | |
| 182 | func TestServerFinalizer(t *testing.T) { |
| 183 | var ( |