fix(schema): distinguish optional ML budget installation from corruption
This commit is contained in:
1 parent
367bfa3a2a
commit
cbcb8a24b4
4 files changed
+64
-1
No files matched your search
@@ -7,6 +7,46 @@ import (
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
func TestSchemaInspectionOptionalMLBudget(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
for _, mode := range []string{"absent", "partial", "installed", "missing-tables"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
s := newSchemaTestStore(t)
|
||||
if mode == "partial" {
|
||||
if _, err := s.DB.Exec(mlBudgetStatements[0]); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
} else if mode != "absent" {
|
||||
if err := s.EnsureMLBudgetSchema(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mode == "missing-tables" {
|
||||
if _, err := s.DB.Exec(`DROP TABLE ml_daily_budget; DROP TABLE ml_budget_receipts`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
report, err := InspectSchema(ctx, s.DB)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := false
|
||||
for _, component := range report.Components {
|
||||
if component.Component != "machine-learning-budget" {
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if (component.State == "current") != (mode == "installed") {
|
||||
t.Fatalf("%s: %+v", mode, component)
|
||||
}
|
||||
}
|
||||
if found != (mode != "absent") {
|
||||
t.Fatalf("optional component visibility: %s %v", mode, found)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSchemaInspectionDoesNotRecoverJobsOrBackfill(t *testing.T) {
|
||||
st := newSchemaTestStore(t)
|
||||
for name := range managedStoreSchemas {
|
||||
|
||||
Reference in new issue
Block a user