middleware-manager/services/test_helpers_test.go
hhftechnologies ce71c4037c
Some checks are pending
Build and Push Docker Image / build-and-push (push) Waiting to run
Tests / Run Tests (push) Waiting to run
Tests / Lint (push) Waiting to run
Tests / Build (push) Blocked by required conditions
testfiles
2026-01-24 11:58:12 +05:30

38 lines
792 B
Go

package services
import (
"database/sql"
"path/filepath"
"testing"
"github.com/hhftechnology/middleware-manager/database"
)
func newTestDB(t *testing.T) *database.DB {
t.Helper()
dbPath := filepath.Join(t.TempDir(), "test.db")
db, err := database.InitDB(dbPath)
if err != nil {
t.Fatalf("failed to init temp db: %v", err)
}
t.Cleanup(func() {
db.Close()
})
return db
}
// newTestSQLDB returns the underlying *sql.DB for tests that require it
func newTestSQLDB(t *testing.T) *sql.DB {
t.Helper()
return newTestDB(t).DB
}
func newTestConfigManager(t *testing.T) *ConfigManager {
t.Helper()
cfgPath := filepath.Join(t.TempDir(), "config.json")
cm, err := NewConfigManager(cfgPath)
if err != nil {
t.Fatalf("failed to create config manager: %v", err)
}
return cm
}