package backup import ( "slices" "strings" "testing" ) func everyListedTable() []string { var names []string for _, t := range Tables { names = append(names, t.Name) } for name := range Excluded { names = append(names, name) } return names } func TestCoverageAcceptsASchemaThatMatchesTheLists(t *testing.T) { if problems := Coverage(everyListedTable()); len(problems) != 0 { t.Fatalf("problems = %v, want none", problems) } } func TestCoverageNamesATableInNeitherList(t *testing.T) { problems := Coverage(append(everyListedTable(), "new_table")) if len(problems) != 1 || !strings.HasPrefix(problems[0], "new_table: neither") { t.Fatalf("problems = %v, want one naming new_table", problems) } } func TestCoverageNamesAListedTableTheSchemaLacks(t *testing.T) { schema := slices.DeleteFunc(everyListedTable(), func(n string) bool { return n == "playlists" || n == "scan_runs" }) problems := Coverage(schema) if len(problems) != 2 { t.Fatalf("problems = %v, want playlists and scan_runs named", problems) } } func TestEveryExclusionHasAReason(t *testing.T) { for name, why := range Excluded { if strings.TrimSpace(why) == "" { t.Errorf("%s is excluded without a reason", name) } if carried(name) { t.Errorf("%s is both backed up and excluded", name) } } }