Signed-off-by: Daniel Nephin <dnephin@docker.com>
| ... | ... |
@@ -1,8 +1,10 @@ |
| 1 | 1 |
package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "archive/tar" |
|
| 4 | 5 |
"encoding/json" |
| 5 | 6 |
"fmt" |
| 7 |
+ "io" |
|
| 6 | 8 |
"io/ioutil" |
| 7 | 9 |
"os" |
| 8 | 10 |
"os/exec" |
| ... | ... |
@@ -18,7 +20,6 @@ import ( |
| 18 | 18 |
"github.com/docker/docker/pkg/testutil" |
| 19 | 19 |
icmd "github.com/docker/docker/pkg/testutil/cmd" |
| 20 | 20 |
"github.com/go-check/check" |
| 21 |
- "github.com/opencontainers/go-digest" |
|
| 22 | 21 |
) |
| 23 | 22 |
|
| 24 | 23 |
// save a repo using gz compression and try to load it using stdout |
| ... | ... |
@@ -289,7 +290,7 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
| 289 | 289 |
c.Assert(err, checker.IsNil, check.Commentf("failed to open %s: %s", layerPath, err))
|
| 290 | 290 |
defer f.Close() |
| 291 | 291 |
|
| 292 |
- entries, err := testutil.ListTar(f) |
|
| 292 |
+ entries, err := listTar(f) |
|
| 293 | 293 |
for _, e := range entries {
|
| 294 | 294 |
if !strings.Contains(e, "dev/") {
|
| 295 | 295 |
entriesSansDev = append(entriesSansDev, e) |
| ... | ... |
@@ -308,6 +309,23 @@ func (s *DockerSuite) TestSaveDirectoryPermissions(c *check.C) {
|
| 308 | 308 |
|
| 309 | 309 |
} |
| 310 | 310 |
|
| 311 |
+func listTar(f io.Reader) ([]string, error) {
|
|
| 312 |
+ tr := tar.NewReader(f) |
|
| 313 |
+ var entries []string |
|
| 314 |
+ |
|
| 315 |
+ for {
|
|
| 316 |
+ th, err := tr.Next() |
|
| 317 |
+ if err == io.EOF {
|
|
| 318 |
+ // end of tar archive |
|
| 319 |
+ return entries, nil |
|
| 320 |
+ } |
|
| 321 |
+ if err != nil {
|
|
| 322 |
+ return entries, err |
|
| 323 |
+ } |
|
| 324 |
+ entries = append(entries, th.Name) |
|
| 325 |
+ } |
|
| 326 |
+} |
|
| 327 |
+ |
|
| 311 | 328 |
// Test loading a weird image where one of the layers is of zero size. |
| 312 | 329 |
// The layer.tar file is actually zero bytes, no padding or anything else. |
| 313 | 330 |
// See issue: 18170 |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package testutil |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "archive/tar" |
|
| 5 | 4 |
"errors" |
| 6 | 5 |
"fmt" |
| 7 | 6 |
"io" |
| ... | ... |
@@ -68,24 +67,6 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in |
| 68 | 68 |
return runCommandWithOutput(cmds[len(cmds)-1]) |
| 69 | 69 |
} |
| 70 | 70 |
|
| 71 |
-// ListTar lists the entries of a tar. |
|
| 72 |
-func ListTar(f io.Reader) ([]string, error) {
|
|
| 73 |
- tr := tar.NewReader(f) |
|
| 74 |
- var entries []string |
|
| 75 |
- |
|
| 76 |
- for {
|
|
| 77 |
- th, err := tr.Next() |
|
| 78 |
- if err == io.EOF {
|
|
| 79 |
- // end of tar archive |
|
| 80 |
- return entries, nil |
|
| 81 |
- } |
|
| 82 |
- if err != nil {
|
|
| 83 |
- return entries, err |
|
| 84 |
- } |
|
| 85 |
- entries = append(entries, th.Name) |
|
| 86 |
- } |
|
| 87 |
-} |
|
| 88 |
- |
|
| 89 | 71 |
// RandomTmpDirPath provides a temporary path with rand string appended. |
| 90 | 72 |
// does not create or checks if it exists. |
| 91 | 73 |
func RandomTmpDirPath(s string, platform string) string {
|
| ... | ... |
@@ -2,10 +2,8 @@ package testutil |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"io" |
| 5 |
- "io/ioutil" |
|
| 6 | 5 |
"os" |
| 7 | 6 |
"os/exec" |
| 8 |
- "path/filepath" |
|
| 9 | 7 |
"runtime" |
| 10 | 8 |
"strings" |
| 11 | 9 |
"testing" |
| ... | ... |
@@ -59,43 +57,6 @@ func TestRunCommandPipelineWithOutput(t *testing.T) {
|
| 59 | 59 |
} |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
-// FIXME make an "unhappy path" test for ListTar without "panicking" :-) |
|
| 63 |
-func TestListTar(t *testing.T) {
|
|
| 64 |
- // TODO Windows: Figure out why this fails. Should be portable. |
|
| 65 |
- if runtime.GOOS == "windows" {
|
|
| 66 |
- t.Skip("Failing on Windows - needs further investigation")
|
|
| 67 |
- } |
|
| 68 |
- tmpFolder, err := ioutil.TempDir("", "integration-cli-utils-list-tar")
|
|
| 69 |
- if err != nil {
|
|
| 70 |
- t.Fatal(err) |
|
| 71 |
- } |
|
| 72 |
- defer os.RemoveAll(tmpFolder) |
|
| 73 |
- |
|
| 74 |
- // Let's create a Tar file |
|
| 75 |
- srcFile := filepath.Join(tmpFolder, "src") |
|
| 76 |
- tarFile := filepath.Join(tmpFolder, "src.tar") |
|
| 77 |
- os.Create(srcFile) |
|
| 78 |
- cmd := exec.Command("sh", "-c", "tar cf "+tarFile+" "+srcFile)
|
|
| 79 |
- _, err = cmd.CombinedOutput() |
|
| 80 |
- if err != nil {
|
|
| 81 |
- t.Fatal(err) |
|
| 82 |
- } |
|
| 83 |
- |
|
| 84 |
- reader, err := os.Open(tarFile) |
|
| 85 |
- if err != nil {
|
|
| 86 |
- t.Fatal(err) |
|
| 87 |
- } |
|
| 88 |
- defer reader.Close() |
|
| 89 |
- |
|
| 90 |
- entries, err := ListTar(reader) |
|
| 91 |
- if err != nil {
|
|
| 92 |
- t.Fatal(err) |
|
| 93 |
- } |
|
| 94 |
- if len(entries) != 1 && entries[0] != "src" {
|
|
| 95 |
- t.Fatalf("Expected a tar file with 1 entry (%s), got %v", srcFile, entries)
|
|
| 96 |
- } |
|
| 97 |
-} |
|
| 98 |
- |
|
| 99 | 62 |
func TestRandomTmpDirPath(t *testing.T) {
|
| 100 | 63 |
path := RandomTmpDirPath("something", runtime.GOOS)
|
| 101 | 64 |
|