From 2c624e89841a70f7de998e1e46f8139ec7b661ee Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Fri, 8 Mar 2019 11:16:22 +0000 Subject: [PATCH] Add e2e test for handling of `version`/`-v`/`--version` with plugins Previous commits fixed the first issue on #1661, this simply adds a test for it. Note that this is testing the current behaviour, without regard for the second issue in #1661 which proposes a different behaviour. Signed-off-by: Ian Campbell --- e2e/cli-plugins/flags_test.go | 115 ++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/e2e/cli-plugins/flags_test.go b/e2e/cli-plugins/flags_test.go index 5a446f6eb8..a958b18413 100644 --- a/e2e/cli-plugins/flags_test.go +++ b/e2e/cli-plugins/flags_test.go @@ -86,3 +86,118 @@ func TestUnknownGlobal(t *testing.T) { }) } } + +// TestCliPluginsVersion checks that `-v` and friends DTRT +func TestCliPluginsVersion(t *testing.T) { + run, _, cleanup := prepare(t) + defer cleanup() + + for _, tc := range []struct { + name string + args []string + expCode int + expOut, expErr string + }{ + { + name: "global-version", + args: []string{"version"}, + expCode: 0, + expOut: "Client:\n Version:", + expErr: icmd.None, + }, + { + name: "global-version-flag", + args: []string{"--version"}, + expCode: 0, + expOut: "Docker version", + expErr: icmd.None, + }, + { + name: "global-short-version-flag", + args: []string{"-v"}, + expCode: 0, + expOut: "Docker version", + expErr: icmd.None, + }, + { + name: "global-with-unknown-arg", + args: []string{"version", "foo"}, + expCode: 1, + expOut: icmd.None, + expErr: `"docker version" accepts no arguments.`, + }, + { + name: "global-with-plugin-arg", + args: []string{"version", "helloworld"}, + expCode: 1, + expOut: icmd.None, + expErr: `"docker version" accepts no arguments.`, + }, + { + name: "global-version-flag-with-unknown-arg", + args: []string{"--version", "foo"}, + expCode: 0, + expOut: "Docker version", + expErr: icmd.None, + }, + { + name: "global-short-version-flag-with-unknown-arg", + args: []string{"-v", "foo"}, + expCode: 0, + expOut: "Docker version", + expErr: icmd.None, + }, + { + name: "global-version-flag-with-plugin", + args: []string{"--version", "helloworld"}, + expCode: 125, + expOut: icmd.None, + expErr: "unknown flag: --version", + }, + { + name: "global-short-version-flag-with-plugin", + args: []string{"-v", "helloworld"}, + expCode: 125, + expOut: icmd.None, + expErr: "unknown shorthand flag: 'v' in -v", + }, + { + name: "plugin-with-version", + args: []string{"helloworld", "version"}, + expCode: 0, + expOut: "Hello World!", + expErr: icmd.None, + }, + { + name: "plugin-with-version-flag", + args: []string{"helloworld", "--version"}, + expCode: 125, + expOut: icmd.None, + expErr: "unknown flag: --version", + }, + { + name: "plugin-with-short-version-flag", + args: []string{"helloworld", "-v"}, + expCode: 125, + expOut: icmd.None, + expErr: "unknown shorthand flag: 'v' in -v", + }, + { + name: "", + args: []string{}, + expCode: 0, + expOut: "", + expErr: "", + }, + } { + t.Run(tc.name, func(t *testing.T) { + res := icmd.RunCmd(run(tc.args...)) + res.Assert(t, icmd.Expected{ + ExitCode: tc.expCode, + Out: tc.expOut, + Err: tc.expErr, + }) + }) + } + +}