response_test.go 995 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package response // import "miniflux.app/v2/internal/http/response"
  4. import (
  5. "net/http"
  6. "net/http/httptest"
  7. "testing"
  8. )
  9. func TestNoContentResponse(t *testing.T) {
  10. r, err := http.NewRequest("GET", "/", nil)
  11. if err != nil {
  12. t.Fatal(err)
  13. }
  14. w := httptest.NewRecorder()
  15. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  16. NoContent(w, r)
  17. })
  18. handler.ServeHTTP(w, r)
  19. resp := w.Result()
  20. if resp.StatusCode != http.StatusNoContent {
  21. t.Fatalf(`Unexpected status code, got %d instead of %d`, resp.StatusCode, http.StatusNoContent)
  22. }
  23. if actualBody := w.Body.String(); actualBody != `` {
  24. t.Fatalf(`Unexpected body, got %s instead of %s`, actualBody, ``)
  25. }
  26. if actualContentType := resp.Header.Get("Content-Type"); actualContentType != "" {
  27. t.Fatalf(`Unexpected content type, got %q instead of empty string`, actualContentType)
  28. }
  29. }