-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some simple e2e tests for executing CLI plugins
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
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters