65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
package data
|
|
|
|
import (
|
|
"testing"
|
|
|
|
integrationmodule "kra/internal/modules/integration"
|
|
paymentmodule "kra/internal/modules/payment"
|
|
systemmodule "kra/internal/modules/system"
|
|
taskmodule "kra/internal/modules/task"
|
|
"kra/pkg/database/migration"
|
|
platformmodule "kra/pkg/module"
|
|
)
|
|
|
|
func testCatalog() platformmodule.Catalog {
|
|
return platformmodule.Catalog{Definitions: []platformmodule.Definition{
|
|
systemmodule.Definition(), integrationmodule.Definition(), taskmodule.Definition(), paymentmodule.Definition(),
|
|
}}
|
|
}
|
|
|
|
func TestMigrateAllRunsModuleSchemasWithoutBootstrapSeed(t *testing.T) {
|
|
db, err := openWithDriver("sqlite", "file:"+t.Name()+"?mode=memory&cache=shared")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = migrateAll(db, testCatalog()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err = migrateAll(db, testCatalog()); err != nil {
|
|
t.Fatalf("second migration run: %v", err)
|
|
}
|
|
for _, table := range []string{"sys_integration_configs", "sys_users", "sys_base_menus", "pay_orders"} {
|
|
if !db.Migrator().HasTable(table) {
|
|
t.Fatalf("migration did not create %s", table)
|
|
}
|
|
}
|
|
var versions int64
|
|
if err = db.Table(migration.TableName).Count(&versions).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if versions != 8 {
|
|
t.Fatalf("migration versions = %d, want 8", versions)
|
|
}
|
|
var communicationRows []dataintegration.ConfigPO
|
|
if err = db.Where("kind IN ?", []string{"mq", "websocket"}).Order("kind, provider").Find(&communicationRows).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(communicationRows) != 3 {
|
|
t.Fatalf("communication integration rows = %d, want 3", len(communicationRows))
|
|
}
|
|
for _, row := range communicationRows {
|
|
if row.Enabled || row.Config == "" {
|
|
t.Fatalf("default communication integration = %#v", row)
|
|
}
|
|
}
|
|
for _, table := range []string{"sys_users", "sys_base_menus", "sys_apis"} {
|
|
var count int64
|
|
if err = db.Table(table).Count(&count).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if count != 0 {
|
|
t.Fatalf("migration seeded %s: rows=%d", table, count)
|
|
}
|
|
}
|
|
}
|