From 6ffbe3f6a893a97f534d535538a646d4b79fed03 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Aug 2017 18:43:39 -0400 Subject: [PATCH] Remove ListTar Signed-off-by: Daniel Nephin --- integration-cli/docker_cli_save_load_test.go | 22 ++++++++++- pkg/testutil/utils.go | 19 ---------- pkg/testutil/utils_test.go | 39 -------------------- 3 files changed, 20 insertions(+), 60 deletions(-) diff --git a/integration-cli/docker_cli_save_load_test.go b/integration-cli/docker_cli_save_load_test.go index 3b14576f7386c..d3e86aff7af6f 100644 --- a/integration-cli/docker_cli_save_load_test.go +++ b/integration-cli/docker_cli_save_load_test.go @@ -1,8 +1,10 @@ package main import ( + "archive/tar" "encoding/json" "fmt" + "io" "io/ioutil" "os" "os/exec" @@ -18,7 +20,6 @@ import ( "github.com/docker/docker/pkg/testutil" icmd "github.com/docker/docker/pkg/testutil/cmd" "github.com/go-check/check" - "github.com/opencontainers/go-digest" ) // save a repo using gz compression and try to load it using stdout @@ -289,7 +290,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) { c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err)) defer f.Close() - entries, err := testutil.ListTar(f) + entries, err := listTar(f) for _, e := range entries { if !strings.Contains(e, "dev/") { entriesSansDev = append(entriesSansDev, e) @@ -308,6 +309,23 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) { } +func listTar(f io.Reader) ([]string, error) { + tr := tar.NewReader(f) + var entries []string + + for { + th, err := tr.Next() + if err == io.EOF { + // end of tar archive + return entries, nil + } + if err != nil { + return entries, err + } + entries = append(entries, th.Name) + } +} + // Test loading a weird image where one of the layers is of zero size. // The layer.tar file is actually zero bytes, no padding or anything else. // See issue: 18170 diff --git a/pkg/testutil/utils.go b/pkg/testutil/utils.go index f7b41f48e75e3..2ef301e4acbe0 100644 --- a/pkg/testutil/utils.go +++ b/pkg/testutil/utils.go @@ -1,7 +1,6 @@ package testutil import ( - "archive/tar" "errors" "fmt" "io" @@ -68,24 +67,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in return runCommandWithOutput(cmds[len(cmds)-1]) } -// ListTar lists the entries of a tar. -func ListTar(f io.Reader) ([]string, error) { - tr := tar.NewReader(f) - var entries []string - - for { - th, err := tr.Next() - if err == io.EOF { - // end of tar archive - return entries, nil - } - if err != nil { - return entries, err - } - entries = append(entries, th.Name) - } -} - // RandomTmpDirPath provides a temporary path with rand string appended. // does not create or checks if it exists. func RandomTmpDirPath(s string, platform string) string { diff --git a/pkg/testutil/utils_test.go b/pkg/testutil/utils_test.go index 7b2ab997d965f..28dff0f254dfb 100644 --- a/pkg/testutil/utils_test.go +++ b/pkg/testutil/utils_test.go @@ -2,10 +2,8 @@ package testutil import ( "io" - "io/ioutil" "os" "os/exec" - "path/filepath" "runtime" "strings" "testing" @@ -59,43 +57,6 @@ func TestRunCommandPipelineWithOutput(t *testing.T) { } } -// FIXME make an "unhappy path" test for ListTar without "panicking" :-) -func TestListTar(t *testing.T) { - // TODO Windows: Figure out why this fails. Should be portable. - if runtime.GOOS == "windows" { - t.Skip("Failing on Windows - needs further investigation") - } - tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-list-tar") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(tmpFolder) - - // Let's create a Tar file - srcFile := filepath.Join(tmpFolder, "src") - tarFile := filepath.Join(tmpFolder, "src.tar") - os.Create(srcFile) - cmd := exec.Command("sh", "-c", "tar cf "+tarFile+" "+srcFile) - _, err = cmd.CombinedOutput() - if err != nil { - t.Fatal(err) - } - - reader, err := os.Open(tarFile) - if err != nil { - t.Fatal(err) - } - defer reader.Close() - - entries, err := ListTar(reader) - if err != nil { - t.Fatal(err) - } - if len(entries) != 1 && entries[0] != "src" { - t.Fatalf("Expected a tar file with 1 entry (%s), got %v", srcFile, entries) - } -} - func TestRandomTmpDirPath(t *testing.T) { path := RandomTmpDirPath("something", runtime.GOOS)