(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestClientNext(t *testing.T) { |
| 22 | dummyRequestID := "dummy-request-id" |
| 23 | dummyPayload := `{"hello": "world"}` |
| 24 | |
| 25 | returnsBody := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 26 | if r.Method != http.MethodGet || r.URL.Path != "/2018-06-01/runtime/invocation/next" { |
| 27 | w.WriteHeader(http.StatusNotImplemented) |
| 28 | } |
| 29 | w.Header().Add(headerAWSRequestID, dummyRequestID) |
| 30 | _, _ = w.Write([]byte(dummyPayload)) |
| 31 | })) |
| 32 | defer returnsBody.Close() |
| 33 | |
| 34 | returnsNoBody := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 35 | if r.Method != http.MethodGet || r.URL.Path != "/2018-06-01/runtime/invocation/next" { |
| 36 | w.WriteHeader(http.StatusNotImplemented) |
| 37 | } |
| 38 | w.Header().Add(headerAWSRequestID, dummyRequestID) |
| 39 | w.WriteHeader(http.StatusOK) |
| 40 | })) |
| 41 | defer returnsNoBody.Close() |
| 42 | |
| 43 | t.Run("handles regular response", func(t *testing.T) { |
| 44 | invoke, err := newRuntimeAPIClient(serverAddress(returnsBody)).next(context.Background()) |
| 45 | require.NoError(t, err) |
| 46 | assert.Equal(t, dummyRequestID, invoke.id) |
| 47 | assert.Equal(t, dummyPayload, invoke.payload.String()) |
| 48 | }) |
| 49 | |
| 50 | t.Run("handles no body", func(t *testing.T) { |
| 51 | invoke, err := newRuntimeAPIClient(serverAddress(returnsNoBody)).next(context.Background()) |
| 52 | require.NoError(t, err) |
| 53 | assert.Equal(t, dummyRequestID, invoke.id) |
| 54 | assert.Equal(t, 0, len(invoke.payload.Bytes())) |
| 55 | }) |
| 56 | |
| 57 | t.Run("error on context canceled", func(t *testing.T) { |
| 58 | ctx, cancel := context.WithCancel(context.Background()) |
| 59 | cancel() |
| 60 | _, err := newRuntimeAPIClient(serverAddress(returnsNoBody)).next(ctx) |
| 61 | require.Error(t, err) |
| 62 | }) |
| 63 | } |
| 64 | |
| 65 | func TestClientDoneAndError(t *testing.T) { |
| 66 | invokeID := "theid" |
nothing calls this directly
no test coverage detected
searching dependent graphs…