-
Notifications
You must be signed in to change notification settings - Fork 231
/
save_test.go
56 lines (44 loc) · 1.29 KB
/
save_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
package main
import (
"os"
"path/filepath"
"testing"
)
func TestSaveImage(t *testing.T) {
runBuild(t, "savething", withDockerfile(`
FROM busybox
RUN echo savetest
`))
tmpf := filepath.Join(os.TempDir(), "save-image-test.tar")
defer os.RemoveAll(tmpf)
run(t, "save", "-o", tmpf, "savething")
// Make sure the file exists
if _, err := os.Stat(tmpf); os.IsNotExist(err) {
t.Fatalf("%s should exist after saving the image but it didn't", tmpf)
}
}
func TestSaveImageOCI(t *testing.T) {
runBuild(t, "savethingoci", withDockerfile(`
FROM busybox
RUN echo savetest
`))
tmpf := filepath.Join(os.TempDir(), "save-oci-test.tar")
defer os.RemoveAll(tmpf)
run(t, "save", "--format", "oci", "-o", tmpf, "savethingoci")
// Make sure the file exists
if _, err := os.Stat(tmpf); os.IsNotExist(err) {
t.Fatalf("%s should exist after saving the image but it didn't", tmpf)
}
}
func TestSaveImageInvalid(t *testing.T) {
runBuild(t, "savethinginvalid", withDockerfile(`
FROM busybox
RUN echo savetest
`))
tmpf := filepath.Join(os.TempDir(), "save-invalid.tar")
defer os.RemoveAll(tmpf)
out, err := doRun([]string{"save", "--format", "blah", "-o", tmpf, "savethinginvalid"}, nil)
if err == nil {
t.Fatalf("expected invalid format to fail but did not: %s", string(out))
}
}