-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_test.go
More file actions
86 lines (73 loc) · 2.39 KB
/
full_test.go
File metadata and controls
86 lines (73 loc) · 2.39 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"testing"
"os"
"path/filepath"
"sort"
)
func TestFullScan(t *testing.T) {
registry, err := os.MkdirTemp("", "")
if err != nil {
t.Fatalf("failed to create registry; %v", err)
}
// Creating project and asset directories.
err = os.MkdirAll(filepath.Join(registry, "foo", "bar", "1"), 0755)
if err != nil {
t.Fatalf("failed to create a 'foo/bar' project; %v", err)
}
err = os.WriteFile(filepath.Join(registry, "foo", "bar", "..latest"), []byte("{ \"version\": \"1\" }"), 0644)
if err != nil {
t.Fatal(err)
}
err = os.MkdirAll(filepath.Join(registry, "shibuya", "kanon", "2"), 0755)
if err != nil {
t.Fatalf("failed to create a 'shibuya/kanon' project; %v", err)
}
err = os.WriteFile(filepath.Join(registry, "shibuya", "kanon", "..latest"), []byte("{ \"version\": \"2\" }"), 0644)
if err != nil {
t.Fatal(err)
}
err = os.MkdirAll(filepath.Join(registry, "shibuya", "aria", "1"), 0755)
if err != nil {
t.Fatalf("failed to create a 'shibuya/kanon' project; %v", err)
}
err = os.WriteFile(filepath.Join(registry, "shibuya", "aria", "..latest"), []byte("{ \"version\": \"1\" }"), 0644)
if err != nil {
t.Fatal(err)
}
url := getSewerRatUrl()
names := []string{ "metadata.json" }
// Initial run registers everything.
{
err := fullScan(url, registry, names)
if err != nil {
t.Fatal(err)
}
found, err := listRegisteredSubdirectories(url, registry)
if err != nil {
t.Fatal(err)
}
sort.Strings(found)
if len(found) != 3 || found[0] != "foo/bar/1" || found[1] != "shibuya/aria/1" || found[2] != "shibuya/kanon/2" {
t.Errorf("unexpected results after a full scan; %v", found)
}
}
// Next run deregisters all the shibuya entries.
{
err := os.RemoveAll(filepath.Join(registry, "shibuya"))
if err != nil {
t.Fatal(err)
}
err = fullScan(url, registry, names)
if err != nil {
t.Fatal(err)
}
found, err := listRegisteredSubdirectories(url, registry)
if err != nil {
t.Fatal(err)
}
if len(found) != 1 || found[0] != "foo/bar/1" {
t.Errorf("unexpected results after a full scan; %v", found)
}
}
}