瀏覽代碼

Remove ListTar

Signed-off-by: Daniel Nephin <dnephin@docker.com>
Daniel Nephin 7 年之前
父節點
當前提交
6ffbe3f6a8
共有 3 個文件被更改,包括 20 次插入60 次删除
  1. 20 2
      integration-cli/docker_cli_save_load_test.go
  2. 0 19
      pkg/testutil/utils.go
  3. 0 39
      pkg/testutil/utils_test.go

+ 20 - 2
integration-cli/docker_cli_save_load_test.go

@@ -1,8 +1,10 @@
 package main
 package main
 
 
 import (
 import (
+	"archive/tar"
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	"io"
 	"io/ioutil"
 	"io/ioutil"
 	"os"
 	"os"
 	"os/exec"
 	"os/exec"
@@ -18,7 +20,6 @@ import (
 	"github.com/docker/docker/pkg/testutil"
 	"github.com/docker/docker/pkg/testutil"
 	icmd "github.com/docker/docker/pkg/testutil/cmd"
 	icmd "github.com/docker/docker/pkg/testutil/cmd"
 	"github.com/go-check/check"
 	"github.com/go-check/check"
-	"github.com/opencontainers/go-digest"
 )
 )
 
 
 // save a repo using gz compression and try to load it using stdout
 // 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))
 			c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
 			defer f.Close()
 			defer f.Close()
 
 
-			entries, err := testutil.ListTar(f)
+			entries, err := listTar(f)
 			for _, e := range entries {
 			for _, e := range entries {
 				if !strings.Contains(e, "dev/") {
 				if !strings.Contains(e, "dev/") {
 					entriesSansDev = append(entriesSansDev, e)
 					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.
 // 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.
 // The layer.tar file is actually zero bytes, no padding or anything else.
 // See issue: 18170
 // See issue: 18170

+ 0 - 19
pkg/testutil/utils.go

@@ -1,7 +1,6 @@
 package testutil
 package testutil
 
 
 import (
 import (
-	"archive/tar"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
 	"io"
 	"io"
@@ -68,24 +67,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
 	return runCommandWithOutput(cmds[len(cmds)-1])
 	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.
 // RandomTmpDirPath provides a temporary path with rand string appended.
 // does not create or checks if it exists.
 // does not create or checks if it exists.
 func RandomTmpDirPath(s string, platform string) string {
 func RandomTmpDirPath(s string, platform string) string {

+ 0 - 39
pkg/testutil/utils_test.go

@@ -2,10 +2,8 @@ package testutil
 
 
 import (
 import (
 	"io"
 	"io"
-	"io/ioutil"
 	"os"
 	"os"
 	"os/exec"
 	"os/exec"
-	"path/filepath"
 	"runtime"
 	"runtime"
 	"strings"
 	"strings"
 	"testing"
 	"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) {
 func TestRandomTmpDirPath(t *testing.T) {
 	path := RandomTmpDirPath("something", runtime.GOOS)
 	path := RandomTmpDirPath("something", runtime.GOOS)