Files
IDP-Backend/internal/server/server_test.go

49 lines
982 B
Go

package server
import (
"net/http/httptest"
"testing"
"git.logidex.ru/fakz9/logidex-id/internal/config"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
)
func TestNewFiberApp(t *testing.T) {
cfg := config.Config{}
cfg.App.Port = 8080
app := NewFiberApp(cfg)
assert.NotNil(t, app)
// Test health check endpoint
req := httptest.NewRequest("GET", "/health", nil)
resp, err := app.Test(req)
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
}
func TestNewAPIRouter(t *testing.T) {
cfg := config.Config{}
cfg.App.Port = 8080
app := NewFiberApp(cfg)
router := NewAPIRouter(app)
assert.NotNil(t, router)
// Test that we can add routes to the router
router.Get("/test", func(c *fiber.Ctx) error {
return c.JSON(map[string]string{"message": "test"})
})
// Test the route works
req := httptest.NewRequest("GET", "/api/test", nil)
resp, err := app.Test(req)
assert.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
}