Skip to content

Commit

Permalink
Remove ListTar
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed Aug 22, 2017
1 parent 6151d55 commit 6ffbe3f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 60 deletions.
22 changes: 20 additions & 2 deletions integration-cli/docker_cli_save_load_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"archive/tar"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
19 changes: 0 additions & 19 deletions pkg/testutil/utils.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testutil

import (
"archive/tar"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -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 {
Expand Down
39 changes: 0 additions & 39 deletions pkg/testutil/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package testutil

import (
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 6ffbe3f

Please sign in to comment.