-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker_test.go
More file actions
64 lines (60 loc) · 1.73 KB
/
docker_test.go
File metadata and controls
64 lines (60 loc) · 1.73 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
package containerapi
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestConsumePullStream(t *testing.T) {
tests := []struct {
name string
stream string
wantDownloaded bool
wantErr string
}{
{
name: "image already up to date",
stream: `{"status":"Pulling from library/alpine","id":"latest"}
{"status":"Digest: sha256:abc"}
{"status":"Status: Image is up to date for alpine:latest"}`,
wantDownloaded: false,
},
{
name: "newly downloaded image",
stream: `{"status":"Pulling from library/alpine","id":"latest"}
{"status":"Pulling fs layer","progressDetail":{},"id":"abc"}
{"status":"Downloading","progressDetail":{"current":1,"total":2},"id":"abc"}
{"status":"Pull complete","progressDetail":{},"id":"abc"}
{"status":"Digest: sha256:def"}
{"status":"Status: Downloaded newer image for alpine:latest"}`,
wantDownloaded: true,
},
{
name: "all layers already exist still counts as no-op",
stream: `{"status":"Pulling from library/alpine","id":"latest"}
{"status":"Already exists","progressDetail":{},"id":"abc"}
{"status":"Status: Image is up to date for alpine:latest"}`,
wantDownloaded: false,
},
{
name: "engine error in stream",
stream: `{"errorDetail":{"message":"manifest unknown"},"error":"manifest unknown"}`,
wantErr: "manifest unknown",
},
{
name: "empty stream",
stream: ``,
wantDownloaded: false,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
downloaded, err := consumePullStream(strings.NewReader(tc.stream))
if tc.wantErr != "" {
assert.EqualError(t, err, tc.wantErr)
return
}
assert.NoError(t, err)
assert.Equal(t, tc.wantDownloaded, downloaded)
})
}
}