Skip to content

Commit

Permalink
Add e2e test for handling of version/-v/--version with plugins
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Ian Campbell committed Mar 11, 2019
1 parent 76d0d1e commit 1fce752
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions e2e/cli-plugins/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})
}

}

0 comments on commit 1fce752

Please sign in to comment.