Add some simple e2e tests for executing CLI plugins

To help with this add a bad plugin which produces invalid metadata and arrange
for it to be built in the e2e container.

Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
Ian Campbell
2018-12-11 14:15:04 +00:00
parent f1f31abbe5
commit 5db336798c
8 changed files with 110 additions and 2 deletions

View File

@ -0,0 +1,60 @@
package cliplugins
import (
"testing"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/golden"
"gotest.tools/icmd"
)
// TestRunNonexisting ensures correct behaviour when running a nonexistent plugin.
func TestRunNonexisting(t *testing.T) {
run, cleanup := prepare(t)
defer cleanup()
res := icmd.RunCmd(run("nonexistent"))
res.Assert(t, icmd.Expected{
ExitCode: 1,
})
assert.Assert(t, is.Equal(res.Stdout(), ""))
golden.Assert(t, res.Stderr(), "docker-nonexistent-err.golden")
}
// TestRunBad ensures correct behaviour when running an existent but invalid plugin
func TestRunBad(t *testing.T) {
run, cleanup := prepare(t)
defer cleanup()
res := icmd.RunCmd(run("badmeta"))
res.Assert(t, icmd.Expected{
ExitCode: 1,
})
assert.Assert(t, is.Equal(res.Stdout(), ""))
golden.Assert(t, res.Stderr(), "docker-badmeta-err.golden")
}
// TestRunGood ensures correct behaviour when running a valid plugin
func TestRunGood(t *testing.T) {
run, cleanup := prepare(t)
defer cleanup()
res := icmd.RunCmd(run("helloworld"))
res.Assert(t, icmd.Expected{
ExitCode: 0,
Out: "Hello World!",
})
}
// TestRunGoodSubcommand ensures correct behaviour when running a valid plugin with a subcommand
func TestRunGoodSubcommand(t *testing.T) {
run, cleanup := prepare(t)
defer cleanup()
res := icmd.RunCmd(run("helloworld", "goodbye"))
res.Assert(t, icmd.Expected{
ExitCode: 0,
Out: "Goodbye World!",
})
}