-
Notifications
You must be signed in to change notification settings - Fork 85
/
tombstones_test.go
60 lines (51 loc) · 1.24 KB
/
tombstones_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package zoekt
import (
"encoding/json"
"os"
"path/filepath"
"testing"
)
func TestSetTombstone(t *testing.T) {
mockRepos = mkRepos("r1", "r2", "r3")
readMeta := func(shard string) []byte {
blob, err := os.ReadFile(shard + ".meta")
if err != nil && !os.IsNotExist(err) {
t.Fatal(err)
}
return blob
}
dir := t.TempDir()
ghostShard := filepath.Join(dir, "test.zoekt")
isAlive := func(alive []bool) {
t.Helper()
blob := readMeta(ghostShard)
ghostRepos := []*Repository{}
if err := json.Unmarshal(blob, &ghostRepos); err != nil {
t.Fatal(err)
}
for i, repo := range ghostRepos {
if repo.Tombstone == alive[i] {
t.Fatalf("r%d: want %t, got %t\n", i+1, alive[i], repo.Tombstone)
}
}
}
if err := SetTombstone(ghostShard, 2); err != nil {
t.Fatal(err)
}
isAlive([]bool{true, false, true})
if err := SetTombstone(ghostShard, 1); err != nil {
t.Fatal(err)
}
isAlive([]bool{false, false, true})
if err := UnsetTombstone(ghostShard, 2); err != nil {
t.Fatal(err)
}
isAlive([]bool{false, true, true})
}
func mkRepos(repoNames ...string) []*Repository {
ret := make([]*Repository, 0, len(repoNames))
for i, n := range repoNames {
ret = append(ret, &Repository{ID: uint32(i + 1), Name: n})
}
return ret
}