forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli_save_and_load_test.go
68 lines (53 loc) · 2.03 KB
/
cli_save_and_load_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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"
"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)
// PouchSaveLoadSuite is the test suite for save and load CLI.
type PouchSaveLoadSuite struct{}
func init() {
check.Suite(&PouchSaveLoadSuite{})
}
// SetUpSuite does common setup in the beginning of each test suite.
func (suite *PouchSaveLoadSuite) SetUpSuite(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
environment.PruneAllContainers(apiClient)
}
// TestSaveLoadWorks tests "pouch save" and "pouch load" work.
func (suite *PouchSaveLoadSuite) TestSaveLoadWorks(c *check.C) {
res := command.PouchRun("pull", helloworldImage)
res.Assert(c, icmd.Success)
res = command.PouchRun("image", "inspect", helloworldImage)
res.Assert(c, icmd.Success)
before := []types.ImageInfo{}
if err := json.Unmarshal([]byte(res.Stdout()), &before); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
dir, err := ioutil.TempDir("", "TestSaveLoadWorks")
if err != nil {
c.Errorf("failed to create a new temporary directory: %v", err)
}
defer os.RemoveAll(dir)
res = command.PouchRun("save", "-o", filepath.Join(dir, "helloworld.tar"), helloworldImage)
res.Assert(c, icmd.Success)
loadImageName := "load-helloworld"
res = command.PouchRun("load", "-i", filepath.Join(dir, "helloworld.tar"), loadImageName)
res.Assert(c, icmd.Success)
defer command.PouchRun("rmi", loadImageName+":"+environment.HelloworldTag)
res = command.PouchRun("image", "inspect", loadImageName+":"+environment.HelloworldTag)
res.Assert(c, icmd.Success)
after := []types.ImageInfo{}
if err := json.Unmarshal([]byte(res.Stdout()), &after); err != nil {
c.Errorf("failed to decode inspect output: %v", err)
}
c.Assert(before[0].ID, check.Equals, after[0].ID)
c.Assert(before[0].CreatedAt, check.Equals, after[0].CreatedAt)
c.Assert(before[0].Size, check.Equals, after[0].Size)
}