-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopy_chunked_types_test.go
More file actions
78 lines (71 loc) · 1.89 KB
/
Copy pathcopy_chunked_types_test.go
File metadata and controls
78 lines (71 loc) · 1.89 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
package slicer
import (
"encoding/json"
"strings"
"testing"
)
func TestCopyManifestValidate(t *testing.T) {
digest := strings.Repeat("a", 64)
manifest := CopyManifest{
Version: ChunkedCopyManifestVersion,
Mode: "binary",
Destination: "/home/ubuntu/tool",
Size: 3,
Chunks: []CopyChunk{{
Index: 0,
Size: 3,
SHA256: digest,
}},
}
if err := manifest.Validate(); err != nil {
t.Fatalf("valid manifest: %v", err)
}
badIndex := manifest
badIndex.Chunks = append([]CopyChunk(nil), manifest.Chunks...)
badIndex.Chunks[0].Index = 1
if err := badIndex.Validate(); err == nil {
t.Fatal("out-of-sequence chunk was accepted")
}
badSize := manifest
badSize.Size++
if err := badSize.Validate(); err == nil {
t.Fatal("incorrect stream size was accepted")
}
}
func TestCopyManifestV2AllowsUnnamedContentsSource(t *testing.T) {
manifest := CopyManifest{
Version: ChunkedCopyManifestV2,
Mode: "tar",
Destination: "/tmp/root",
CopySemantics: cpCopySemanticsV1,
SourceType: copySourceTypeDir,
CopyContents: true,
Chunks: []CopyChunk{},
}
if err := manifest.Validate(); err != nil {
t.Fatalf("Validate: %v", err)
}
}
func TestCopyManifestV1OmitsV2Fields(t *testing.T) {
data, err := json.Marshal(CopyManifest{
Version: ChunkedCopyManifestVersion,
Mode: "binary",
Destination: "/tmp/file",
Chunks: []CopyChunk{},
})
if err != nil {
t.Fatal(err)
}
for _, field := range []string{"copy_semantics", "source_name", "source_type", "copy_contents"} {
if strings.Contains(string(data), `"`+field+`"`) {
t.Fatalf("v1 manifest contains %s: %s", field, data)
}
}
}
func TestCopyChunkFileName(t *testing.T) {
chunk := CopyChunk{Index: 12, SHA256: strings.Repeat("b", 64)}
want := "000012.chunk"
if got := CopyChunkFileName(chunk); got != want {
t.Fatalf("CopyChunkFileName() = %q, want %q", got, want)
}
}