serveCallback drives the callback handler with the given query string and returns the recorded response and the single reported result.
(t *testing.T, expectedState, query string)
| 13 | // serveCallback drives the callback handler with the given query string and |
| 14 | // returns the recorded response and the single reported result. |
| 15 | func serveCallback(t *testing.T, expectedState, query string) (*httptest.ResponseRecorder, callbackResult) { |
| 16 | t.Helper() |
| 17 | cs := &callbackServer{results: make(chan callbackResult, 1)} |
| 18 | rec := httptest.NewRecorder() |
| 19 | req := httptest.NewRequest(http.MethodGet, "/callback?"+query, nil) |
| 20 | |
| 21 | cs.handler(expectedState).ServeHTTP(rec, req) |
| 22 | |
| 23 | select { |
| 24 | case res := <-cs.results: |
| 25 | return rec, res |
| 26 | default: |
| 27 | t.Fatal("handler did not report a result") |
| 28 | return nil, callbackResult{} |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestCallbackHandlerSuccess(t *testing.T) { |
| 33 | rec, res := serveCallback(t, "state123", "code=the-code&state=state123") |
no test coverage detected