133728e barerepo 1mo
1
package store
133728e barerepo 1mo
3
import (
133728e barerepo 1mo
4
"regexp"
133728e barerepo 1mo
5
"sort"
133728e barerepo 1mo
6
"strings"
133728e barerepo 1mo
7
"testing"
133728e barerepo 1mo
10
// owner names the chapter 10 item a table belongs to, since one with no item makes rule 3 false.
133728e barerepo 1mo
11
var owner = map[string]string{
133728e barerepo 1mo
12
"accounts": "1. account name to public keys",
133728e barerepo 1mo
13
"pubkeys": "1. account name to public keys",
133728e barerepo 1mo
14
"gpgkeys": "1. account name to public keys",
133728e barerepo 1mo
15
"repos": "2. namespace ownership",
133728e barerepo 1mo
16
"tokens": "3. tokens",
133728e barerepo 1mo
17
"challenges": "3. tokens",
133728e barerepo 1mo
18
"signup_challenges": "3. tokens",
133728e barerepo 1mo
19
"redirects": "4. namespace redirects",
133728e barerepo 1mo
20
"events": "6. caches, indexes and derived state",
133728e barerepo 1mo
21
"participation": "6. caches, indexes and derived state",
133728e barerepo 1mo
22
"search_docs": "6. caches, indexes and derived state",
133728e barerepo 1mo
23
"runners": "7. work in flight",
133728e barerepo 1mo
24
"jobs": "7. work in flight",
133728e barerepo 1mo
25
"webhooks": "7. work in flight",
133728e barerepo 1mo
26
"webhook_cursor": "7. work in flight",
133728e barerepo 1mo
29
var createTable = regexp.MustCompile(`CREATE TABLE ([a-z_]+)`)
133728e barerepo 1mo
31
// Rule 3: nothing is stored that is not a git object, except a closed list. This is that list.
133728e barerepo 1mo
32
func TestEveryTableIsOnTheClosedList(t *testing.T) {
133728e barerepo 1mo
33
found := map[string]bool{}
133728e barerepo 1mo
34
for _, m := range migrations {
133728e barerepo 1mo
35
for _, hit := range createTable.FindAllStringSubmatch(m.sqlite, -1) {
133728e barerepo 1mo
36
found[hit[1]] = true
133728e barerepo 1mo
39
if len(found) < 10 {
133728e barerepo 1mo
40
t.Fatalf("only found %d tables, so this test is reading the wrong thing", len(found))
133728e barerepo 1mo
42
for name := range found {
133728e barerepo 1mo
43
if _, ok := owner[name]; !ok {
133728e barerepo 1mo
44
t.Errorf("the table %q is on no item of chapter 10's closed list. either it belongs "+
133728e barerepo 1mo
45
"to one, or the list has grown and the chapter has to say so", name)
133728e barerepo 1mo
48
// The other direction, so a dropped table does not leave a claim about storage that is not made.
133728e barerepo 1mo
49
var stale []string
133728e barerepo 1mo
50
for name := range owner {
133728e barerepo 1mo
51
if !found[name] {
133728e barerepo 1mo
52
stale = append(stale, name)
133728e barerepo 1mo
55
sort.Strings(stale)
133728e barerepo 1mo
56
if len(stale) > 0 {
133728e barerepo 1mo
57
t.Errorf("the closed list claims %s, and no migration makes them", strings.Join(stale, ", "))