mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
update test using c.Assert replace c.Fatal
Signed-off-by: Hao Zhang <21521210@zju.edu.cn>
This commit is contained in:
parent
9273c53d83
commit
d5830d66e0
1 changed files with 32 additions and 78 deletions
|
@ -12,6 +12,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/integration/checker"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,22 +31,16 @@ func (s *DockerSuite) TestSaveXzAndLoadRepoStdout(c *check.C) {
|
||||||
exec.Command(dockerBinary, "save", repoName),
|
exec.Command(dockerBinary, "save", repoName),
|
||||||
exec.Command("xz", "-c"),
|
exec.Command("xz", "-c"),
|
||||||
exec.Command("gzip", "-c"))
|
exec.Command("gzip", "-c"))
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo: %v %v", out, err))
|
||||||
c.Fatalf("failed to save repo: %v %v", out, err)
|
|
||||||
}
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
loadCmd := exec.Command(dockerBinary, "load")
|
loadCmd := exec.Command(dockerBinary, "load")
|
||||||
loadCmd.Stdin = strings.NewReader(repoTarball)
|
loadCmd.Stdin = strings.NewReader(repoTarball)
|
||||||
out, _, err = runCommandWithOutput(loadCmd)
|
out, _, err = runCommandWithOutput(loadCmd)
|
||||||
if err == nil {
|
c.Assert(err, checker.NotNil, check.Commentf("expected error, but succeeded with no error and output: %v", out))
|
||||||
c.Fatalf("expected error, but succeeded with no error and output: %v", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
after, _, err := dockerCmdWithError("inspect", repoName)
|
after, _, err := dockerCmdWithError("inspect", repoName)
|
||||||
if err == nil {
|
c.Assert(err, checker.NotNil, check.Commentf("the repo should not exist: %v", after))
|
||||||
c.Fatalf("the repo should not exist: %v", after)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save a repo using xz+gz compression and try to load it using stdout
|
// save a repo using xz+gz compression and try to load it using stdout
|
||||||
|
@ -63,23 +58,17 @@ func (s *DockerSuite) TestSaveXzGzAndLoadRepoStdout(c *check.C) {
|
||||||
exec.Command(dockerBinary, "save", repoName),
|
exec.Command(dockerBinary, "save", repoName),
|
||||||
exec.Command("xz", "-c"),
|
exec.Command("xz", "-c"),
|
||||||
exec.Command("gzip", "-c"))
|
exec.Command("gzip", "-c"))
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo: %v %v", out, err))
|
||||||
c.Fatalf("failed to save repo: %v %v", out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
deleteImages(repoName)
|
deleteImages(repoName)
|
||||||
|
|
||||||
loadCmd := exec.Command(dockerBinary, "load")
|
loadCmd := exec.Command(dockerBinary, "load")
|
||||||
loadCmd.Stdin = strings.NewReader(out)
|
loadCmd.Stdin = strings.NewReader(out)
|
||||||
out, _, err = runCommandWithOutput(loadCmd)
|
out, _, err = runCommandWithOutput(loadCmd)
|
||||||
if err == nil {
|
c.Assert(err, checker.NotNil, check.Commentf("expected error, but succeeded with no error and output: %v", out))
|
||||||
c.Fatalf("expected error, but succeeded with no error and output: %v", out)
|
|
||||||
}
|
|
||||||
|
|
||||||
after, _, err := dockerCmdWithError("inspect", repoName)
|
after, _, err := dockerCmdWithError("inspect", repoName)
|
||||||
if err == nil {
|
c.Assert(err, checker.NotNil, check.Commentf("the repo should not exist: %v", after))
|
||||||
c.Fatalf("the repo should not exist: %v", after)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
||||||
|
@ -94,9 +83,7 @@ func (s *DockerSuite) TestSaveSingleTag(c *check.C) {
|
||||||
exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
||||||
exec.Command("tar", "t"),
|
exec.Command("tar", "t"),
|
||||||
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
|
exec.Command("grep", "-E", fmt.Sprintf("(^repositories$|%v)", cleanedImageID)))
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err))
|
||||||
c.Fatalf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
||||||
|
@ -107,14 +94,14 @@ func (s *DockerSuite) TestSaveCheckTimes(c *check.C) {
|
||||||
Created time.Time
|
Created time.Time
|
||||||
}{}
|
}{}
|
||||||
err := json.Unmarshal([]byte(out), &data)
|
err := json.Unmarshal([]byte(out), &data)
|
||||||
c.Assert(err, check.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
|
c.Assert(err, checker.IsNil, check.Commentf("failed to marshal from %q: err %v", repoName, err))
|
||||||
c.Assert(len(data), check.Not(check.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
|
c.Assert(len(data), checker.Not(checker.Equals), 0, check.Commentf("failed to marshal the data from %q", repoName))
|
||||||
tarTvTimeFormat := "2006-01-02 15:04"
|
tarTvTimeFormat := "2006-01-02 15:04"
|
||||||
out, _, err = runCommandPipelineWithOutput(
|
out, _, err = runCommandPipelineWithOutput(
|
||||||
exec.Command(dockerBinary, "save", repoName),
|
exec.Command(dockerBinary, "save", repoName),
|
||||||
exec.Command("tar", "tv"),
|
exec.Command("tar", "tv"),
|
||||||
exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), data[0].ID)))
|
exec.Command("grep", "-E", fmt.Sprintf("%s %s", data[0].Created.Format(tarTvTimeFormat), data[0].ID)))
|
||||||
c.Assert(err, check.IsNil, check.Commentf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err))
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID and 'repositories' file: %s, %v", out, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
||||||
|
@ -129,37 +116,27 @@ func (s *DockerSuite) TestSaveImageId(c *check.C) {
|
||||||
cleanedShortImageID := strings.TrimSpace(out)
|
cleanedShortImageID := strings.TrimSpace(out)
|
||||||
|
|
||||||
// Make sure IDs are not empty
|
// Make sure IDs are not empty
|
||||||
c.Assert(cleanedLongImageID, check.Not(check.Equals), "", check.Commentf("Id should not be empty."))
|
c.Assert(cleanedLongImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
|
||||||
c.Assert(cleanedShortImageID, check.Not(check.Equals), "", check.Commentf("Id should not be empty."))
|
c.Assert(cleanedShortImageID, checker.Not(check.Equals), "", check.Commentf("Id should not be empty."))
|
||||||
|
|
||||||
saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID)
|
saveCmd := exec.Command(dockerBinary, "save", cleanedShortImageID)
|
||||||
tarCmd := exec.Command("tar", "t")
|
tarCmd := exec.Command("tar", "t")
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
tarCmd.Stdin, err = saveCmd.StdoutPipe()
|
tarCmd.Stdin, err = saveCmd.StdoutPipe()
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for tar: %v", err))
|
||||||
c.Fatalf("cannot set stdout pipe for tar: %v", err)
|
|
||||||
}
|
|
||||||
grepCmd := exec.Command("grep", cleanedLongImageID)
|
grepCmd := exec.Command("grep", cleanedLongImageID)
|
||||||
grepCmd.Stdin, err = tarCmd.StdoutPipe()
|
grepCmd.Stdin, err = tarCmd.StdoutPipe()
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("cannot set stdout pipe for grep: %v", err))
|
||||||
c.Fatalf("cannot set stdout pipe for grep: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = tarCmd.Start(); err != nil {
|
c.Assert(tarCmd.Start(), checker.IsNil, check.Commentf("tar failed with error: %v", err))
|
||||||
c.Fatalf("tar failed with error: %v", err)
|
c.Assert(saveCmd.Start(), checker.IsNil, check.Commentf("docker save failed with error: %v", err))
|
||||||
}
|
|
||||||
if err = saveCmd.Start(); err != nil {
|
|
||||||
c.Fatalf("docker save failed with error: %v", err)
|
|
||||||
}
|
|
||||||
defer saveCmd.Wait()
|
defer saveCmd.Wait()
|
||||||
defer tarCmd.Wait()
|
defer tarCmd.Wait()
|
||||||
|
|
||||||
out, _, err = runCommandWithOutput(grepCmd)
|
out, _, err = runCommandWithOutput(grepCmd)
|
||||||
|
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save repo with image ID: %s, %v", out, err))
|
||||||
c.Fatalf("failed to save repo with image ID: %s, %v", out, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// save a repo and try to load it using flags
|
// save a repo and try to load it using flags
|
||||||
|
@ -178,14 +155,10 @@ func (s *DockerSuite) TestSaveAndLoadRepoFlags(c *check.C) {
|
||||||
out, _, err := runCommandPipelineWithOutput(
|
out, _, err := runCommandPipelineWithOutput(
|
||||||
exec.Command(dockerBinary, "save", repoName),
|
exec.Command(dockerBinary, "save", repoName),
|
||||||
exec.Command(dockerBinary, "load"))
|
exec.Command(dockerBinary, "load"))
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and load repo: %s, %v", out, err))
|
||||||
c.Fatalf("failed to save and load repo: %s, %v", out, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
after, _ := dockerCmd(c, "inspect", repoName)
|
after, _ := dockerCmd(c, "inspect", repoName)
|
||||||
if before != after {
|
c.Assert(before, checker.Equals, after, check.Commentf("inspect is not the same after a save / load"))
|
||||||
c.Fatalf("inspect is not the same after a save / load")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
||||||
|
@ -203,9 +176,7 @@ func (s *DockerSuite) TestSaveMultipleNames(c *check.C) {
|
||||||
exec.Command("tar", "xO", "repositories"),
|
exec.Command("tar", "xO", "repositories"),
|
||||||
exec.Command("grep", "-q", "-E", "(-one|-two)"),
|
exec.Command("grep", "-q", "-E", "(-one|-two)"),
|
||||||
)
|
)
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple repos: %s, %v", out, err))
|
||||||
c.Fatalf("failed to save multiple repos: %s, %v", out, err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
||||||
|
@ -237,9 +208,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
||||||
exec.Command("tar", "t"),
|
exec.Command("tar", "t"),
|
||||||
exec.Command("grep", "VERSION"),
|
exec.Command("grep", "VERSION"),
|
||||||
exec.Command("cut", "-d", "/", "-f1"))
|
exec.Command("cut", "-d", "/", "-f1"))
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save multiple images: %s, %v", out, err))
|
||||||
c.Fatalf("failed to save multiple images: %s, %v", out, err)
|
|
||||||
}
|
|
||||||
actual := strings.Split(strings.TrimSpace(out), "\n")
|
actual := strings.Split(strings.TrimSpace(out), "\n")
|
||||||
|
|
||||||
// make the list of expected layers
|
// make the list of expected layers
|
||||||
|
@ -248,9 +217,7 @@ func (s *DockerSuite) TestSaveRepoWithMultipleImages(c *check.C) {
|
||||||
|
|
||||||
sort.Strings(actual)
|
sort.Strings(actual)
|
||||||
sort.Strings(expected)
|
sort.Strings(expected)
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
c.Assert(actual, checker.DeepEquals, expected, check.Commentf("archive does not contains the right layers: got %v, expected %v", actual, expected))
|
||||||
c.Fatalf("archive does not contains the right layers: got %v, expected %v", actual, expected)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Issue #6722 #5892 ensure directories are included in changes
|
// Issue #6722 #5892 ensure directories are included in changes
|
||||||
|
@ -261,9 +228,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
||||||
|
|
||||||
name := "save-directory-permissions"
|
name := "save-directory-permissions"
|
||||||
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
|
tmpDir, err := ioutil.TempDir("", "save-layers-with-directories")
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary directory: %s", err))
|
||||||
c.Errorf("failed to create temporary directory: %s", err)
|
|
||||||
}
|
|
||||||
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
|
extractionDirectory := filepath.Join(tmpDir, "image-extraction-dir")
|
||||||
os.Mkdir(extractionDirectory, 0777)
|
os.Mkdir(extractionDirectory, 0777)
|
||||||
|
|
||||||
|
@ -273,21 +238,16 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
||||||
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
|
RUN adduser -D user && mkdir -p /opt/a/b && chown -R user:user /opt/a
|
||||||
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`,
|
RUN touch /opt/a/b/c && chown user:user /opt/a/b/c`,
|
||||||
true)
|
true)
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("%v", err))
|
||||||
c.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if out, _, err := runCommandPipelineWithOutput(
|
out, _, err := runCommandPipelineWithOutput(
|
||||||
exec.Command(dockerBinary, "save", name),
|
exec.Command(dockerBinary, "save", name),
|
||||||
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
|
exec.Command("tar", "-xf", "-", "-C", extractionDirectory),
|
||||||
); err != nil {
|
)
|
||||||
c.Errorf("failed to save and extract image: %s", out)
|
c.Assert(err, checker.IsNil, check.Commentf("failed to save and extract image: %s", out))
|
||||||
}
|
|
||||||
|
|
||||||
dirs, err := ioutil.ReadDir(extractionDirectory)
|
dirs, err := ioutil.ReadDir(extractionDirectory)
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to get a listing of the layer directories: %s", err))
|
||||||
c.Errorf("failed to get a listing of the layer directories: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
for _, entry := range dirs {
|
for _, entry := range dirs {
|
||||||
|
@ -296,9 +256,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
||||||
layerPath := filepath.Join(extractionDirectory, entry.Name(), "layer.tar")
|
layerPath := filepath.Join(extractionDirectory, entry.Name(), "layer.tar")
|
||||||
|
|
||||||
f, err := os.Open(layerPath)
|
f, err := os.Open(layerPath)
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
|
||||||
c.Fatalf("failed to open %s: %s", layerPath, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
entries, err := listTar(f)
|
entries, err := listTar(f)
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
|
@ -306,9 +264,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
||||||
entriesSansDev = append(entriesSansDev, e)
|
entriesSansDev = append(entriesSansDev, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
c.Assert(err, checker.IsNil, check.Commentf("encountered error while listing tar entries: %s", err))
|
||||||
c.Fatalf("encountered error while listing tar entries: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if reflect.DeepEqual(entriesSansDev, layerEntries) || reflect.DeepEqual(entriesSansDev, layerEntriesAUFS) {
|
if reflect.DeepEqual(entriesSansDev, layerEntries) || reflect.DeepEqual(entriesSansDev, layerEntriesAUFS) {
|
||||||
found = true
|
found = true
|
||||||
|
@ -317,8 +273,6 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
c.Assert(found, checker.Equals, true, check.Commentf("failed to find the layer with the right content listing"))
|
||||||
c.Fatalf("failed to find the layer with the right content listing")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue