clortho/lib/apis/apis_test.go
Maxime Duchene-Savard ea2bb235a2 work
2025-04-14 23:50:22 -04:00

42 lines
757 B
Go

package apis
import (
"clortho/lib/db"
"fmt"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"os"
"testing"
)
func TestMain(m *testing.M) {
// Set up test database file
os.Setenv("CLORTHO_DB_FILE", "clortho_test.db")
// Global setup
fmt.Println("Setting up resources...")
db.InitDb()
defer db.ResetDb()
exitCode := m.Run() // Run all tests
// Global teardown
fmt.Println("Cleaning up resources...")
os.Exit(exitCode)
}
func TestPingRoute(t *testing.T) {
r := gin.Default()
SetupRouter(r, nil)
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/ping", nil)
r.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.JSONEq(t, `{"message": "pong"}`, w.Body.String())
}