forked from quay/claircore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer_integration_test.go
131 lines (119 loc) · 3.25 KB
/
layer_integration_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
// we will use the claircore_test package here to avoid import cycles when
// importing the fetcher.fetcher. using the fetcher is an attempt to not repeat
// a lot of layer fetching code. if this pattern continues reconsider importing anything
// into claircore package
package claircore_test
import (
"bytes"
"context"
"testing"
"time"
"github.com/quay/claircore"
"github.com/quay/claircore/test"
"github.com/quay/claircore/test/integration"
)
var goldenLayers []test.LayerSpec
func init() {
id, err := claircore.ParseDigest("sha256:35c102085707f703de2d9eaad8752d6fe1b8f02b5d2149f1d8357c9cc7fb7d0a")
if err != nil {
panic(err)
}
goldenLayers = []test.LayerSpec{
{
Domain: "docker.io",
Repo: "library/ubuntu",
ID: id,
},
}
}
func Test_Layer_Files_Miss(t *testing.T) {
integration.Skip(t)
ctx, done := context.WithCancel(context.Background())
defer done()
var tt = []struct {
// name of the test
name string
// the number of layers to generate for the test
layers []test.LayerSpec
// a list of paths we know exist in the retrieved layer(s). we wil test to make sure their associated
// buffer is full
paths []string
}{
{
name: "ubuntu:18.04 fake path, leading slash",
layers: goldenLayers,
paths: []string{"/path/to/nowhere"},
},
{
name: "ubuntu:18.04 fake path, no leading slash",
layers: goldenLayers,
paths: []string{"path/to/nowhere"},
},
}
for _, table := range tt {
t.Run(table.name, func(t *testing.T) {
ctx, done := context.WithCancel(ctx)
defer done()
// fetch the layer
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()
layers := test.RealizeLayers(ctx, t, table.layers...)
// attempt to get files
_, err := layers[0].Files(table.paths...)
if err == nil {
t.Error("expected error")
}
})
}
}
func Test_Layer_Files_Hit(t *testing.T) {
integration.Skip(t)
ctx, done := context.WithCancel(context.Background())
defer done()
var tt = []struct {
// name of the test
name string
// the number of layers to generate for the test
layers []test.LayerSpec
// a list of paths we know exist in the retrieved layer(s). we wil test to make sure their associated
// buffer is full
paths []string
}{
{
name: "ubuntu:18.04 os-release (linked file), leading slash, inmem fetch",
layers: goldenLayers,
paths: []string{"/etc/os-release"},
},
{
name: "ubuntu:18.04 os-release (linked file), no leading slash, inmem fetch",
layers: goldenLayers,
paths: []string{"etc/os-release"},
},
}
for _, table := range tt {
t.Run(table.name, func(t *testing.T) {
ctx, done := context.WithCancel(ctx)
defer done()
// fetch the layer
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
defer cancel()
layers := test.RealizeLayers(ctx, t, table.layers...)
// attempt to get files
files, err := layers[0].Files(table.paths...)
if err != nil {
t.Fatal(err)
}
var b *bytes.Buffer
var ok bool
for _, path := range table.paths {
if b, ok = files[path]; !ok {
t.Fatalf("test path %v was not found in resulting file map", path)
}
if l := b.Len(); l <= 0 {
t.Fatalf("returned buffer for path %v has len %v", path, l)
}
t.Logf("contents: %+q", b.String())
}
})
}
}