37 lines
856 B
Go
37 lines
856 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
"testing"
|
|
|
|
"infinite-canvas/backend/internal/database"
|
|
|
|
"gorm.io/gorm/schema"
|
|
)
|
|
|
|
func TestMigrationListCoversSchemaModels(t *testing.T) {
|
|
want := make(map[string]bool, len(database.Models()))
|
|
cache := &sync.Map{}
|
|
for _, value := range database.Models() {
|
|
parsed, err := schema.Parse(value, cache, schema.NamingStrategy{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want[parsed.Table] = false
|
|
}
|
|
for _, migration := range migrations() {
|
|
if _, exists := want[migration.name]; !exists {
|
|
t.Fatalf("migration list contains unknown table %q", migration.name)
|
|
}
|
|
if want[migration.name] {
|
|
t.Fatalf("migration list contains duplicate table %q", migration.name)
|
|
}
|
|
want[migration.name] = true
|
|
}
|
|
for table, covered := range want {
|
|
if !covered {
|
|
t.Errorf("migration list is missing table %q", table)
|
|
}
|
|
}
|
|
}
|