-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest_test.go
148 lines (140 loc) · 4.36 KB
/
manifest_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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"testing"
"os"
"path/filepath"
)
func TestReadManifest(t *testing.T) {
f, err := os.MkdirTemp("", "test-")
if err != nil {
t.Fatalf("failed to create tempdir; %v", err)
}
err = os.WriteFile(
filepath.Join(f, manifestFileName),
[]byte(`
{
"foobar": {
"size": 10000,
"md5sum": "abcdefgh"
},
"whee/stuff": {
"size": 20000,
"md5sum": "12345678",
"link": {
"project": "seabird",
"asset": "albatross",
"version": "987",
"path": "genesis"
}
},
"blah/boo/akira": {
"size": 30000,
"md5sum": "a1b2c3d4",
"link": {
"project": "evangelion",
"asset": "ayanami",
"version": "first",
"path": "rei",
"ancestor": {
"project": "neon",
"asset": "asuka",
"version": "nerv",
"path": "langley"
}
}
}
}`),
0644,
)
if err != nil {
t.Fatalf("failed to create test manifest; %v", err)
}
out, err := readManifest(f)
if err != nil {
t.Fatalf("failed to read test manifest; %v", err)
}
if len(out) != 3 {
t.Fatalf("unexpected length of manifest")
}
first, ok := out["foobar"]
if !ok {
t.Fatalf("expected 'foobar' to be in the manifest")
}
if first.Size != 10000 {
t.Fatalf("unexpected size for 'foobar' in the manifest")
}
if first.Md5sum != "abcdefgh" {
t.Fatalf("unexpected MD5 sum for 'foobar' in the manifest")
}
if first.Link != nil {
t.Fatalf("unexpected links for 'foobar' in the manifest")
}
second, ok := out["whee/stuff"]
if !ok {
t.Fatalf("expected 'whee/stuff' to be in the manifest")
}
if second.Size != 20000 {
t.Fatalf("unexpected size for 'whee/stuff' in the manifest")
}
if second.Md5sum != "12345678" {
t.Fatalf("unexpected MD5 sum for 'whee/stuff' in the manifest")
}
if second.Link == nil {
t.Fatalf("missing links for 'whee/stuff' in the manifest")
}
if second.Link.Project != "seabird" {
t.Fatalf("unexpected link project for 'whee/stuff' in the manifest")
}
if second.Link.Asset != "albatross" {
t.Fatalf("unexpected link asset for 'whee/stuff' in the manifest")
}
if second.Link.Version != "987" {
t.Fatalf("unexpected link version for 'whee/stuff' in the manifest")
}
if second.Link.Path != "genesis" {
t.Fatalf("unexpected link path for 'whee/stuff' in the manifest")
}
if second.Link.Ancestor != nil {
t.Fatalf("unexpected link ancestor for 'whee/stuff' in the manifest")
}
third, ok := out["blah/boo/akira"]
if !ok {
t.Fatalf("expected 'blah/boo/akira' to be in the manifest")
}
if third.Size != 30000 {
t.Fatalf("unexpected size for 'blah/boo/akira' in the manifest")
}
if third.Md5sum != "a1b2c3d4" {
t.Fatalf("unexpected MD5 sum for 'blah/boo/akira' in the manifest")
}
if third.Link == nil {
t.Fatalf("missing links for 'blah/boo/akira' in the manifest")
}
if third.Link.Project != "evangelion" {
t.Fatalf("unexpected link project for 'blah/boo/akira' in the manifest")
}
if third.Link.Asset != "ayanami" {
t.Fatalf("unexpected link asset for 'blah/boo/akira' in the manifest")
}
if third.Link.Version != "first" {
t.Fatalf("unexpected link version for 'blah/boo/akira' in the manifest")
}
if third.Link.Path != "rei" {
t.Fatalf("unexpected link path for 'blah/boo/akira' in the manifest")
}
if third.Link.Ancestor == nil {
t.Fatalf("missing ancestor link for 'blah/boo/akira' in the manifest")
}
if third.Link.Ancestor.Project != "neon" {
t.Fatalf("unexpected link ancestor project for 'blah/boo/akira' in the manifest")
}
if third.Link.Ancestor.Asset != "asuka" {
t.Fatalf("unexpected link ancestor asset for 'blah/boo/akira' in the manifest")
}
if third.Link.Ancestor.Version != "nerv" {
t.Fatalf("unexpected link ancestor version for 'blah/boo/akira' in the manifest")
}
if third.Link.Ancestor.Path != "langley" {
t.Fatalf("unexpected link ancestor path for 'blah/boo/akira' in the manifest")
}
}