2017-09-01 17:52:41 -04:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2017-11-13 20:18:04 -05:00
|
|
|
"github.com/docker/cli/e2e/internal/fixtures"
|
2017-09-01 17:52:41 -04:00
|
|
|
shlex "github.com/flynn-archive/go-shlex"
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-09-01 17:52:41 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/golden"
|
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRunAttachedFromRemoteImageAndRemove(t *testing.T) {
|
|
|
|
image := createRemoteImage(t)
|
|
|
|
|
|
|
|
result := icmd.RunCmd(shell(t,
|
|
|
|
"docker run --rm %s echo this is output", image))
|
|
|
|
|
|
|
|
result.Assert(t, icmd.Success)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("this is output\n", result.Stdout()))
|
2017-09-01 17:52:41 -04:00
|
|
|
golden.Assert(t, result.Stderr(), "run-attached-from-remote-and-remove.golden")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: create this with registry API instead of engine API
|
|
|
|
func createRemoteImage(t *testing.T) string {
|
|
|
|
image := "registry:5000/alpine:test-run-pulls"
|
2017-11-13 20:18:04 -05:00
|
|
|
icmd.RunCommand("docker", "pull", fixtures.AlpineImage).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "tag", fixtures.AlpineImage, image).Assert(t, icmd.Success)
|
2017-09-01 17:52:41 -04:00
|
|
|
icmd.RunCommand("docker", "push", image).Assert(t, icmd.Success)
|
|
|
|
icmd.RunCommand("docker", "rmi", image).Assert(t, icmd.Success)
|
|
|
|
return image
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: move to gotestyourself
|
|
|
|
func shell(t *testing.T, format string, args ...interface{}) icmd.Cmd {
|
|
|
|
cmd, err := shlex.Split(fmt.Sprintf(format, args...))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.NilError(t, err)
|
2017-09-01 17:52:41 -04:00
|
|
|
return icmd.Cmd{Command: cmd}
|
|
|
|
}
|