Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -11,6 +11,7 @@ import ( |
| 11 | 11 |
"testing" |
| 12 | 12 |
|
| 13 | 13 |
"github.com/docker/docker/api/types" |
| 14 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 14 | 15 |
"github.com/docker/docker/integration-cli/cli/build" |
| 15 | 16 |
"gotest.tools/v3/assert" |
| 16 | 17 |
is "gotest.tools/v3/assert/cmp" |
| ... | ... |
@@ -34,19 +35,19 @@ func (s *DockerCLISaveLoadSuite) OnTimeout(c *testing.T) {
|
| 34 | 34 |
func (s *DockerCLISaveLoadSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) {
|
| 35 | 35 |
testRequires(c, DaemonIsLinux) |
| 36 | 36 |
name := "test-save-xz-and-load-repo-stdout" |
| 37 |
- dockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 37 |
+ cli.DockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 38 | 38 |
|
| 39 |
- repoName := "foobar-save-load-test-xz-gz" |
|
| 40 |
- out, _ := dockerCmd(c, "commit", name, repoName) |
|
| 39 |
+ imgRepoName := "foobar-save-load-test-xz-gz" |
|
| 40 |
+ out := cli.DockerCmd(c, "commit", name, imgRepoName).Combined() |
|
| 41 | 41 |
|
| 42 |
- dockerCmd(c, "inspect", repoName) |
|
| 42 |
+ cli.DockerCmd(c, "inspect", imgRepoName) |
|
| 43 | 43 |
|
| 44 | 44 |
repoTarball, err := RunCommandPipelineWithOutput( |
| 45 |
- exec.Command(dockerBinary, "save", repoName), |
|
| 45 |
+ exec.Command(dockerBinary, "save", imgRepoName), |
|
| 46 | 46 |
exec.Command("xz", "-c"),
|
| 47 | 47 |
exec.Command("gzip", "-c"))
|
| 48 | 48 |
assert.NilError(c, err, "failed to save repo: %v %v", out, err) |
| 49 |
- deleteImages(repoName) |
|
| 49 |
+ deleteImages(imgRepoName) |
|
| 50 | 50 |
|
| 51 | 51 |
icmd.RunCmd(icmd.Cmd{
|
| 52 | 52 |
Command: []string{dockerBinary, "load"},
|
| ... | ... |
@@ -55,7 +56,7 @@ func (s *DockerCLISaveLoadSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) {
|
| 55 | 55 |
ExitCode: 1, |
| 56 | 56 |
}) |
| 57 | 57 |
|
| 58 |
- after, _, err := dockerCmdWithError("inspect", repoName)
|
|
| 58 |
+ after, _, err := dockerCmdWithError("inspect", imgRepoName)
|
|
| 59 | 59 |
assert.ErrorContains(c, err, "", "the repo should not exist: %v", after) |
| 60 | 60 |
} |
| 61 | 61 |
|
| ... | ... |
@@ -63,12 +64,12 @@ func (s *DockerCLISaveLoadSuite) TestSaveXzAndLoadRepoStdout(c *testing.T) {
|
| 63 | 63 |
func (s *DockerCLISaveLoadSuite) TestSaveXzGzAndLoadRepoStdout(c *testing.T) {
|
| 64 | 64 |
testRequires(c, DaemonIsLinux) |
| 65 | 65 |
name := "test-save-xz-gz-and-load-repo-stdout" |
| 66 |
- dockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 66 |
+ cli.DockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 67 | 67 |
|
| 68 | 68 |
repoName := "foobar-save-load-test-xz-gz" |
| 69 |
- dockerCmd(c, "commit", name, repoName) |
|
| 69 |
+ cli.DockerCmd(c, "commit", name, repoName) |
|
| 70 | 70 |
|
| 71 |
- dockerCmd(c, "inspect", repoName) |
|
| 71 |
+ cli.DockerCmd(c, "inspect", repoName) |
|
| 72 | 72 |
|
| 73 | 73 |
out, err := RunCommandPipelineWithOutput( |
| 74 | 74 |
exec.Command(dockerBinary, "save", repoName), |
| ... | ... |
@@ -91,10 +92,10 @@ func (s *DockerCLISaveLoadSuite) TestSaveXzGzAndLoadRepoStdout(c *testing.T) {
|
| 91 | 91 |
|
| 92 | 92 |
func (s *DockerCLISaveLoadSuite) TestSaveSingleTag(c *testing.T) {
|
| 93 | 93 |
testRequires(c, DaemonIsLinux) |
| 94 |
- repoName := "foobar-save-single-tag-test" |
|
| 95 |
- dockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", repoName))
|
|
| 94 |
+ imgRepoName := "foobar-save-single-tag-test" |
|
| 95 |
+ cli.DockerCmd(c, "tag", "busybox:latest", fmt.Sprintf("%v:latest", imgRepoName))
|
|
| 96 | 96 |
|
| 97 |
- out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName) |
|
| 97 |
+ out := cli.DockerCmd(c, "images", "-q", "--no-trunc", imgRepoName).Stdout() |
|
| 98 | 98 |
cleanedImageID := strings.TrimSpace(out) |
| 99 | 99 |
|
| 100 | 100 |
filesFilter := fmt.Sprintf("(^manifest.json$|%v)", cleanedImageID)
|
| ... | ... |
@@ -102,7 +103,7 @@ func (s *DockerCLISaveLoadSuite) TestSaveSingleTag(c *testing.T) {
|
| 102 | 102 |
filesFilter = fmt.Sprintf("(^index.json$|^manifest.json$|%v)", cleanedImageID)
|
| 103 | 103 |
} |
| 104 | 104 |
out, err := RunCommandPipelineWithOutput( |
| 105 |
- exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", repoName)),
|
|
| 105 |
+ exec.Command(dockerBinary, "save", fmt.Sprintf("%v:latest", imgRepoName)),
|
|
| 106 | 106 |
exec.Command("tar", "t"),
|
| 107 | 107 |
exec.Command("grep", "-E", filesFilter))
|
| 108 | 108 |
assert.NilError(c, err, "failed to save repo with image ID and index files: %s, %v", out, err) |
| ... | ... |
@@ -110,13 +111,13 @@ func (s *DockerCLISaveLoadSuite) TestSaveSingleTag(c *testing.T) {
|
| 110 | 110 |
|
| 111 | 111 |
func (s *DockerCLISaveLoadSuite) TestSaveImageId(c *testing.T) {
|
| 112 | 112 |
testRequires(c, DaemonIsLinux) |
| 113 |
- repoName := "foobar-save-image-id-test" |
|
| 114 |
- dockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", repoName))
|
|
| 113 |
+ imgRepoName := "foobar-save-image-id-test" |
|
| 114 |
+ cli.DockerCmd(c, "tag", "emptyfs:latest", fmt.Sprintf("%v:latest", imgRepoName))
|
|
| 115 | 115 |
|
| 116 |
- out, _ := dockerCmd(c, "images", "-q", "--no-trunc", repoName) |
|
| 116 |
+ out := cli.DockerCmd(c, "images", "-q", "--no-trunc", imgRepoName).Stdout() |
|
| 117 | 117 |
cleanedLongImageID := strings.TrimPrefix(strings.TrimSpace(out), "sha256:") |
| 118 | 118 |
|
| 119 |
- out, _ = dockerCmd(c, "images", "-q", repoName) |
|
| 119 |
+ out = cli.DockerCmd(c, "images", "-q", imgRepoName).Stdout() |
|
| 120 | 120 |
cleanedShortImageID := strings.TrimSpace(out) |
| 121 | 121 |
|
| 122 | 122 |
// Make sure IDs are not empty |
| ... | ... |
@@ -138,7 +139,7 @@ func (s *DockerCLISaveLoadSuite) TestSaveImageId(c *testing.T) {
|
| 138 | 138 |
defer func() {
|
| 139 | 139 |
saveCmd.Wait() |
| 140 | 140 |
tarCmd.Wait() |
| 141 |
- dockerCmd(c, "rmi", repoName) |
|
| 141 |
+ cli.DockerCmd(c, "rmi", imgRepoName) |
|
| 142 | 142 |
}() |
| 143 | 143 |
|
| 144 | 144 |
out, _, err = runCommandWithOutput(grepCmd) |
| ... | ... |
@@ -149,24 +150,22 @@ func (s *DockerCLISaveLoadSuite) TestSaveImageId(c *testing.T) {
|
| 149 | 149 |
// save a repo and try to load it using flags |
| 150 | 150 |
func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoFlags(c *testing.T) {
|
| 151 | 151 |
testRequires(c, DaemonIsLinux) |
| 152 |
- name := "test-save-and-load-repo-flags" |
|
| 153 |
- dockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 152 |
+ const name = "test-save-and-load-repo-flags" |
|
| 153 |
+ cli.DockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 154 | 154 |
|
| 155 |
- repoName := "foobar-save-load-test" |
|
| 155 |
+ const imgRepoName = "foobar-save-load-test" |
|
| 156 | 156 |
|
| 157 |
- deleteImages(repoName) |
|
| 158 |
- dockerCmd(c, "commit", name, repoName) |
|
| 157 |
+ deleteImages(imgRepoName) |
|
| 158 |
+ cli.DockerCmd(c, "commit", name, imgRepoName) |
|
| 159 | 159 |
|
| 160 |
- beforeStr, _, err := dockerCmdWithError("inspect", repoName)
|
|
| 161 |
- assert.NilError(c, err, "failed to inspect before save") |
|
| 160 |
+ beforeStr := cli.DockerCmd(c, "inspect", imgRepoName).Stdout() |
|
| 162 | 161 |
|
| 163 | 162 |
out, err := RunCommandPipelineWithOutput( |
| 164 |
- exec.Command(dockerBinary, "save", repoName), |
|
| 163 |
+ exec.Command(dockerBinary, "save", imgRepoName), |
|
| 165 | 164 |
exec.Command(dockerBinary, "load")) |
| 166 | 165 |
assert.NilError(c, err, "failed to save and load repo: %s, %v", out, err) |
| 167 | 166 |
|
| 168 |
- afterStr, _, err := dockerCmdWithError("inspect", repoName)
|
|
| 169 |
- assert.NilError(c, err, "failed to inspect after load") |
|
| 167 |
+ afterStr := cli.DockerCmd(c, "inspect", imgRepoName).Stdout() |
|
| 170 | 168 |
|
| 171 | 169 |
var before, after []types.ImageInspect |
| 172 | 170 |
err = json.Unmarshal([]byte(beforeStr), &before) |
| ... | ... |
@@ -204,13 +203,13 @@ func (s *DockerCLISaveLoadSuite) TestSaveWithNoExistImage(c *testing.T) {
|
| 204 | 204 |
|
| 205 | 205 |
func (s *DockerCLISaveLoadSuite) TestSaveMultipleNames(c *testing.T) {
|
| 206 | 206 |
testRequires(c, DaemonIsLinux) |
| 207 |
- repoName := "foobar-save-multi-name-test" |
|
| 207 |
+ const imgRepoName = "foobar-save-multi-name-test" |
|
| 208 | 208 |
|
| 209 |
- oneTag := fmt.Sprintf("%v-one:latest", repoName)
|
|
| 210 |
- twoTag := fmt.Sprintf("%v-two:latest", repoName)
|
|
| 209 |
+ oneTag := fmt.Sprintf("%v-one:latest", imgRepoName)
|
|
| 210 |
+ twoTag := fmt.Sprintf("%v-two:latest", imgRepoName)
|
|
| 211 | 211 |
|
| 212 |
- dockerCmd(c, "tag", "emptyfs:latest", oneTag) |
|
| 213 |
- dockerCmd(c, "tag", "emptyfs:latest", twoTag) |
|
| 212 |
+ cli.DockerCmd(c, "tag", "emptyfs:latest", oneTag) |
|
| 213 |
+ cli.DockerCmd(c, "tag", "emptyfs:latest", twoTag) |
|
| 214 | 214 |
|
| 215 | 215 |
out, err := RunCommandPipelineWithOutput( |
| 216 | 216 |
exec.Command(dockerBinary, "save", strings.TrimSuffix(oneTag, ":latest"), twoTag), |
| ... | ... |
@@ -233,7 +232,7 @@ func (s *DockerCLISaveLoadSuite) TestLoadZeroSizeLayer(c *testing.T) {
|
| 233 | 233 |
// very weird test |
| 234 | 234 |
testRequires(c, DaemonIsLinux, testEnv.IsLocalDaemon) |
| 235 | 235 |
|
| 236 |
- dockerCmd(c, "load", "-i", "testdata/emptyLayer.tar") |
|
| 236 |
+ cli.DockerCmd(c, "load", "-i", "testdata/emptyLayer.tar") |
|
| 237 | 237 |
} |
| 238 | 238 |
|
| 239 | 239 |
func (s *DockerCLISaveLoadSuite) TestSaveLoadParents(c *testing.T) {
|
| ... | ... |
@@ -241,14 +240,13 @@ func (s *DockerCLISaveLoadSuite) TestSaveLoadParents(c *testing.T) {
|
| 241 | 241 |
skip.If(c, testEnv.UsingSnapshotter(), "Parent image property is not supported with containerd") |
| 242 | 242 |
|
| 243 | 243 |
makeImage := func(from string, addfile string) string {
|
| 244 |
- var out string |
|
| 245 |
- out, _ = dockerCmd(c, "run", "-d", from, "touch", addfile) |
|
| 246 |
- cleanedContainerID := strings.TrimSpace(out) |
|
| 244 |
+ id := cli.DockerCmd(c, "run", "-d", from, "touch", addfile).Stdout() |
|
| 245 |
+ id = strings.TrimSpace(id) |
|
| 247 | 246 |
|
| 248 |
- out, _ = dockerCmd(c, "commit", cleanedContainerID) |
|
| 249 |
- imageID := strings.TrimSpace(out) |
|
| 247 |
+ imageID := cli.DockerCmd(c, "commit", id).Stdout() |
|
| 248 |
+ imageID = strings.TrimSpace(imageID) |
|
| 250 | 249 |
|
| 251 |
- dockerCmd(c, "rm", "-f", cleanedContainerID) |
|
| 250 |
+ cli.DockerCmd(c, "rm", "-f", id) |
|
| 252 | 251 |
return imageID |
| 253 | 252 |
} |
| 254 | 253 |
|
| ... | ... |
@@ -263,9 +261,9 @@ func (s *DockerCLISaveLoadSuite) TestSaveLoadParents(c *testing.T) {
|
| 263 | 263 |
|
| 264 | 264 |
outfile := filepath.Join(tmpDir, "out.tar") |
| 265 | 265 |
|
| 266 |
- dockerCmd(c, "save", "-o", outfile, idBar, idFoo) |
|
| 267 |
- dockerCmd(c, "rmi", idBar) |
|
| 268 |
- dockerCmd(c, "load", "-i", outfile) |
|
| 266 |
+ cli.DockerCmd(c, "save", "-o", outfile, idBar, idFoo) |
|
| 267 |
+ cli.DockerCmd(c, "rmi", idBar) |
|
| 268 |
+ cli.DockerCmd(c, "load", "-i", outfile) |
|
| 269 | 269 |
|
| 270 | 270 |
inspectOut := inspectField(c, idBar, "Parent") |
| 271 | 271 |
assert.Equal(c, inspectOut, idFoo) |
| ... | ... |
@@ -12,6 +12,7 @@ import ( |
| 12 | 12 |
"time" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/creack/pty" |
| 15 |
+ "github.com/docker/docker/integration-cli/cli" |
|
| 15 | 16 |
"github.com/docker/docker/integration-cli/cli/build" |
| 16 | 17 |
"github.com/docker/docker/testutil" |
| 17 | 18 |
"gotest.tools/v3/assert" |
| ... | ... |
@@ -22,10 +23,10 @@ import ( |
| 22 | 22 |
// save a repo and try to load it using stdout |
| 23 | 23 |
func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
|
| 24 | 24 |
name := "test-save-and-load-repo-stdout" |
| 25 |
- dockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 25 |
+ cli.DockerCmd(c, "run", "--name", name, "busybox", "true") |
|
| 26 | 26 |
|
| 27 |
- repoName := "foobar-save-load-test" |
|
| 28 |
- before, _ := dockerCmd(c, "commit", name, repoName) |
|
| 27 |
+ imgRepoName := "foobar-save-load-test" |
|
| 28 |
+ before := cli.DockerCmd(c, "commit", name, imgRepoName).Stdout() |
|
| 29 | 29 |
before = strings.TrimRight(before, "\n") |
| 30 | 30 |
|
| 31 | 31 |
tmpFile, err := os.CreateTemp("", "foobar-save-load-test.tar")
|
| ... | ... |
@@ -33,7 +34,7 @@ func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
|
| 33 | 33 |
defer os.Remove(tmpFile.Name()) |
| 34 | 34 |
|
| 35 | 35 |
icmd.RunCmd(icmd.Cmd{
|
| 36 |
- Command: []string{dockerBinary, "save", repoName},
|
|
| 36 |
+ Command: []string{dockerBinary, "save", imgRepoName},
|
|
| 37 | 37 |
Stdout: tmpFile, |
| 38 | 38 |
}).Assert(c, icmd.Success) |
| 39 | 39 |
|
| ... | ... |
@@ -41,23 +42,23 @@ func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
|
| 41 | 41 |
assert.NilError(c, err) |
| 42 | 42 |
defer tmpFile.Close() |
| 43 | 43 |
|
| 44 |
- deleteImages(repoName) |
|
| 44 |
+ deleteImages(imgRepoName) |
|
| 45 | 45 |
|
| 46 | 46 |
icmd.RunCmd(icmd.Cmd{
|
| 47 | 47 |
Command: []string{dockerBinary, "load"},
|
| 48 | 48 |
Stdin: tmpFile, |
| 49 | 49 |
}).Assert(c, icmd.Success) |
| 50 | 50 |
|
| 51 |
- after := inspectField(c, repoName, "Id") |
|
| 51 |
+ after := inspectField(c, imgRepoName, "Id") |
|
| 52 | 52 |
after = strings.TrimRight(after, "\n") |
| 53 | 53 |
|
| 54 | 54 |
assert.Equal(c, after, before, "inspect is not the same after a save / load") |
| 55 | 55 |
|
| 56 |
- deleteImages(repoName) |
|
| 56 |
+ deleteImages(imgRepoName) |
|
| 57 | 57 |
|
| 58 |
- pty, tty, err := pty.Open() |
|
| 58 |
+ p, tty, err := pty.Open() |
|
| 59 | 59 |
assert.NilError(c, err) |
| 60 |
- cmd := exec.Command(dockerBinary, "save", repoName) |
|
| 60 |
+ cmd := exec.Command(dockerBinary, "save", imgRepoName) |
|
| 61 | 61 |
cmd.Stdin = tty |
| 62 | 62 |
cmd.Stdout = tty |
| 63 | 63 |
cmd.Stderr = tty |
| ... | ... |
@@ -66,7 +67,7 @@ func (s *DockerCLISaveLoadSuite) TestSaveAndLoadRepoStdout(c *testing.T) {
|
| 66 | 66 |
|
| 67 | 67 |
buf := make([]byte, 1024) |
| 68 | 68 |
|
| 69 |
- n, err := pty.Read(buf) |
|
| 69 |
+ n, err := p.Read(buf) |
|
| 70 | 70 |
assert.NilError(c, err, "could not read tty output") |
| 71 | 71 |
assert.Assert(c, strings.Contains(string(buf[:n]), "cowardly refusing"), "help output is not being yielded") |
| 72 | 72 |
} |
| ... | ... |
@@ -81,19 +82,19 @@ func (s *DockerCLISaveLoadSuite) TestSaveAndLoadWithProgressBar(c *testing.T) {
|
| 81 | 81 |
`)) |
| 82 | 82 |
|
| 83 | 83 |
tmptar := name + ".tar" |
| 84 |
- dockerCmd(c, "save", "-o", tmptar, name) |
|
| 84 |
+ cli.DockerCmd(c, "save", "-o", tmptar, name) |
|
| 85 | 85 |
defer os.Remove(tmptar) |
| 86 | 86 |
|
| 87 |
- dockerCmd(c, "rmi", name) |
|
| 88 |
- dockerCmd(c, "tag", "busybox", name) |
|
| 89 |
- out, _ := dockerCmd(c, "load", "-i", tmptar) |
|
| 87 |
+ cli.DockerCmd(c, "rmi", name) |
|
| 88 |
+ cli.DockerCmd(c, "tag", "busybox", name) |
|
| 89 |
+ out := cli.DockerCmd(c, "load", "-i", tmptar).Combined() |
|
| 90 | 90 |
expected := fmt.Sprintf("The image %s:latest already exists, renaming the old one with ID", name)
|
| 91 | 91 |
assert.Assert(c, strings.Contains(out, expected)) |
| 92 | 92 |
} |
| 93 | 93 |
|
| 94 | 94 |
// fail because load didn't receive data from stdin |
| 95 | 95 |
func (s *DockerCLISaveLoadSuite) TestLoadNoStdinFail(c *testing.T) {
|
| 96 |
- pty, tty, err := pty.Open() |
|
| 96 |
+ p, tty, err := pty.Open() |
|
| 97 | 97 |
assert.NilError(c, err) |
| 98 | 98 |
ctx, cancel := context.WithTimeout(testutil.GetContext(c), 5*time.Second) |
| 99 | 99 |
defer cancel() |
| ... | ... |
@@ -105,7 +106,7 @@ func (s *DockerCLISaveLoadSuite) TestLoadNoStdinFail(c *testing.T) {
|
| 105 | 105 |
|
| 106 | 106 |
buf := make([]byte, 1024) |
| 107 | 107 |
|
| 108 |
- n, err := pty.Read(buf) |
|
| 108 |
+ n, err := p.Read(buf) |
|
| 109 | 109 |
assert.NilError(c, err) // could not read tty output |
| 110 | 110 |
assert.Assert(c, strings.Contains(string(buf[:n]), "requested load from stdin, but stdin is empty")) |
| 111 | 111 |
} |