diff --git a/cli-plugins/examples/badmeta/main.go b/cli-plugins/examples/badmeta/main.go new file mode 100644 index 000000000000..1b3d1e342ee4 --- /dev/null +++ b/cli-plugins/examples/badmeta/main.go @@ -0,0 +1,19 @@ +package main + +// This is not a real plugin, but just returns malformated metadata +// from the subcommand and otherwise exits with failure. + +import ( + "fmt" + "os" + + cliplugins "github.com/docker/cli/cli-plugins" +) + +func main() { + if len(os.Args) == 2 && os.Args[1] == cliplugins.MetadataSubcommandName { + fmt.Println(`{invalid-json}`) + os.Exit(0) + } + os.Exit(1) +} diff --git a/e2e/cli-plugins/run_test.go b/e2e/cli-plugins/run_test.go new file mode 100644 index 000000000000..418210134cc6 --- /dev/null +++ b/e2e/cli-plugins/run_test.go @@ -0,0 +1,31 @@ +package cliplugins + +import ( + "testing" + + "gotest.tools/icmd" +) + +func TestRunNonexisting(t *testing.T) { + res := icmd.RunCmd(icmd.Command("docker", "nonexistent")) + res.Assert(t, icmd.Expected{ + ExitCode: 1, + Err: "docker: 'nonexistent' is not a docker command.\nSee 'docker --help'", + }) +} + +func TestRunBad(t *testing.T) { + res := icmd.RunCmd(icmd.Command("docker", "badmeta")) + res.Assert(t, icmd.Expected{ + ExitCode: 1, + Err: "docker: 'badmeta' is not a docker command.\nSee 'docker --help'", + }) +} + +func TestRunGood(t *testing.T) { + res := icmd.RunCmd(icmd.Command("docker", "helloworld")) + res.Assert(t, icmd.Expected{ + ExitCode: 0, + Out: "Hello World!", + }) +} diff --git a/scripts/test/e2e/run b/scripts/test/e2e/run index 2b718e52f1ee..15132b8acac0 100755 --- a/scripts/test/e2e/run +++ b/scripts/test/e2e/run @@ -69,6 +69,7 @@ function runtests { TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \ GOPATH="$GOPATH" \ PATH="$PWD/build/:/usr/bin" \ + DOCKER_CLI_PLUGIN_EXTRA_DIRS="$PWD/build/plugins-linux-amd64" \ "$(which go)" test -v ./e2e/... ${TESTFLAGS-} }