clortho/db/db_test.go
Maxime Duchene-Savard 5a23f5ecfe first commit
2025-03-30 22:44:56 -04:00

41 lines
829 B
Go

package db
import (
"os"
"testing"
)
// Test to check if all expected tables exist in the database
func TestTablesExist(t *testing.T) {
// Set up test database file
os.Setenv("CLORTHO_DB_FILE", "test_clortho.db")
defer os.Remove("test_clortho.db") // Cleanup after test
// Initialize database
err := InitDb()
if err != nil {
t.Fatalf("Failed to initialize database: %v", err)
}
// Connect to the test database
// List of expected tables
expectedTables := []string{
"users",
"user_sessions",
"keys",
"groups",
"systems",
"system_groups",
"grants",
}
for _, table := range expectedTables {
var count int64
Connection.Raw("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name=?", table).Scan(&count)
if count == 0 {
t.Errorf("Expected table %s does not exist", table)
}
}
}