Remove ListTar

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-08-21 18:43:39 -04:00
parent 6151d55ee7
commit 6ffbe3f6a8
3 changed files with 20 additions and 60 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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)