41 lines
829 B
Go
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", "clortho_test.db")
|
|
defer os.Remove("clortho_test.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)
|
|
}
|
|
}
|
|
}
|