diff --git a/internal/apiendpoint/api_endpoint_test.go b/internal/apiendpoint/api_endpoint_test.go index 168d4c20..287bd180 100644 --- a/internal/apiendpoint/api_endpoint_test.go +++ b/internal/apiendpoint/api_endpoint_test.go @@ -8,6 +8,7 @@ import ( "net/http" "net/http/httptest" "testing" + "time" "github.com/stretchr/testify/require" @@ -18,6 +19,8 @@ import ( func TestMountAndServe(t *testing.T) { t.Parallel() + ctx := context.Background() + type testBundle struct { recorder *httptest.ResponseRecorder } @@ -96,6 +99,22 @@ func TestMountAndServe(t *testing.T) { requireStatusAndJSONResponse(t, http.StatusBadRequest, &apierror.APIError{Message: "Missing message value."}, bundle.recorder) }) + t.Run("Timeout", func(t *testing.T) { + t.Parallel() + + mux, bundle := setup(t) + + ctx, cancel := context.WithDeadline(ctx, time.Now()) + t.Cleanup(cancel) + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/api/post-endpoint", + bytes.NewBuffer(mustMarshalJSON(t, &postRequest{MakeInternalError: true}))) + require.NoError(t, err) + mux.ServeHTTP(bundle.recorder, req) + + requireStatusAndJSONResponse(t, http.StatusInternalServerError, &apierror.APIError{Message: "Internal server error. Check logs for more information."}, bundle.recorder) + }) + t.Run("InternalServerError", func(t *testing.T) { t.Parallel()