init push
This commit is contained in:
40
internal/transport/http/handlers/health_handler_test.go
Normal file
40
internal/transport/http/handlers/health_handler_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func TestNewHealthHandler(t *testing.T) {
|
||||
h := NewHealthHandler()
|
||||
if h == nil {
|
||||
t.Fatalf("expected health handler instance")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthHandler_Handle(t *testing.T) {
|
||||
h := NewHealthHandler()
|
||||
app := fiber.New()
|
||||
app.Get("/health", h.Handle)
|
||||
|
||||
req, _ := http.NewRequest(http.MethodGet, "/health", nil)
|
||||
resp, err := app.Test(req)
|
||||
if err != nil {
|
||||
t.Fatalf("app.Test: %v", err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("expected 200, got %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
if !strings.Contains(string(body), `"type":"health"`) {
|
||||
t.Fatalf("expected health type in body, got %s", string(body))
|
||||
}
|
||||
if !strings.Contains(string(body), `"status":"ok"`) {
|
||||
t.Fatalf("expected status ok in body, got %s", string(body))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user