Skip to content

Commit

Permalink
Add some simple e2e tests for executing CLI plugins
Browse files Browse the repository at this point in the history
To help with this add a bad plugin which produces invalid metadata.

Signed-off-by: Ian Campbell <ijc@docker.com>
  • Loading branch information
Ian Campbell committed Dec 13, 2018
1 parent a4d6b68 commit 7163d1c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cli-plugins/examples/badmeta/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
31 changes: 31 additions & 0 deletions e2e/cli-plugins/run_test.go
Original file line number Diff line number Diff line change
@@ -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!",
})
}
1 change: 1 addition & 0 deletions scripts/test/e2e/run
Original file line number Diff line number Diff line change
Expand Up @@ -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-}
}

Expand Down

0 comments on commit 7163d1c

Please sign in to comment.