package store import ( "regexp" "sort" "strings" "testing" ) // owner names the chapter 10 item a table belongs to, since one with no item makes rule 3 false. var owner = map[string]string{ "accounts": "1. account name to public keys", "pubkeys": "1. account name to public keys", "gpgkeys": "1. account name to public keys", "repos": "2. namespace ownership", "tokens": "3. tokens", "challenges": "3. tokens", "signup_challenges": "3. tokens", "redirects": "4. namespace redirects", "events": "6. caches, indexes and derived state", "participation": "6. caches, indexes and derived state", "search_docs": "6. caches, indexes and derived state", "runners": "7. work in flight", "jobs": "7. work in flight", "webhooks": "7. work in flight", "webhook_cursor": "7. work in flight", } var createTable = regexp.MustCompile(`CREATE TABLE ([a-z_]+)`) // Rule 3: nothing is stored that is not a git object, except a closed list. This is that list. func TestEveryTableIsOnTheClosedList(t *testing.T) { found := map[string]bool{} for _, m := range migrations { for _, hit := range createTable.FindAllStringSubmatch(m.sqlite, -1) { found[hit[1]] = true } } if len(found) < 10 { t.Fatalf("only found %d tables, so this test is reading the wrong thing", len(found)) } for name := range found { if _, ok := owner[name]; !ok { t.Errorf("the table %q is on no item of chapter 10's closed list. either it belongs "+ "to one, or the list has grown and the chapter has to say so", name) } } // The other direction, so a dropped table does not leave a claim about storage that is not made. var stale []string for name := range owner { if !found[name] { stale = append(stale, name) } } sort.Strings(stale) if len(stale) > 0 { t.Errorf("the closed list claims %s, and no migration makes them", strings.Join(stale, ", ")) } }