health_test.go 890 B

1234567891011121314151617181920212223242526272829303132
  1. package handlers
  2. import (
  3. "net/http"
  4. "net/http/httptest"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/imgproxy/imgproxy/v3/httpheaders"
  8. )
  9. func TestHealthHandler(t *testing.T) {
  10. // Create a ResponseRecorder to record the response
  11. rr := httptest.NewRecorder()
  12. // Call the handler function directly (no need for actual HTTP request)
  13. HealthHandler("test-req-id", rr, nil)
  14. // Check that we get a valid response (either 200 or 500 depending on vips state)
  15. assert.True(t, rr.Code == http.StatusOK || rr.Code == http.StatusInternalServerError)
  16. // Check headers are set correctly
  17. assert.Equal(t, "text/plain", rr.Header().Get(httpheaders.ContentType))
  18. assert.Equal(t, "no-cache", rr.Header().Get(httpheaders.CacheControl))
  19. // Verify response format and content
  20. body := rr.Body.String()
  21. assert.NotEmpty(t, body)
  22. assert.Equal(t, "imgproxy is running", body)
  23. }