Add an end-to-end test for container run

for testing attach, remove, and pull image when missing.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-09-01 17:52:41 -04:00
parent 677d17150a
commit c34360cc8e
5 changed files with 66 additions and 1 deletions

View File

@ -0,0 +1,17 @@
package container
import (
"fmt"
"os"
"testing"
"github.com/docker/cli/internal/test/environment"
)
func TestMain(m *testing.M) {
if err := environment.Setup(); err != nil {
fmt.Println(err.Error())
os.Exit(3)
}
os.Exit(m.Run())
}

42
e2e/container/run_test.go Normal file
View File

@ -0,0 +1,42 @@
package container
import (
"fmt"
"testing"
shlex "github.com/flynn-archive/go-shlex"
"github.com/gotestyourself/gotestyourself/golden"
"github.com/gotestyourself/gotestyourself/icmd"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const alpineImage = "registry:5000/alpine:3.6"
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)
assert.Equal(t, "this is output\n", result.Stdout())
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"
icmd.RunCommand("docker", "pull", alpineImage).Assert(t, icmd.Success)
icmd.RunCommand("docker", "tag", alpineImage, image).Assert(t, icmd.Success)
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...))
require.NoError(t, err)
return icmd.Cmd{Command: cmd}
}

View File

@ -0,0 +1,4 @@
Unable to find image 'registry:5000/alpine:test-run-pulls' locally
test-run-pulls: Pulling from alpine
Digest: sha256:0930dd4cc97ed5771ebe9be9caf3e8dc5341e0b5e32e8fb143394d7dfdfa100e
Status: Downloaded newer image for registry:5000/alpine:test-run-pulls

View File

@ -39,11 +39,12 @@ function cleanup {
function runtests {
local engine_host=$1
# shellcheck disable=SC2086
env -i \
TEST_DOCKER_HOST="$engine_host" \
GOPATH="$GOPATH" \
PATH="$PWD/build/" \
"$(which go)" test -v ./e2e/...
"$(which go)" test -v ./e2e/... ${TESTFLAGS-}
}
export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"

View File

@ -27,6 +27,7 @@ testexit=0
docker run -i --rm \
-v "$PWD:/go/src/github.com/docker/cli" \
--network "${unique_id}_default" \
-e TESTFLAGS \
"$dev_image" \
./scripts/test/e2e/run test "$engine_host" || testexit="$?"
run_in_env cleanup