exit with status 1 if help is called on an invalid command.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-11-15 11:18:33 -05:00
parent 4d1209844f
commit 004fc6b9e4
1 changed files with 15 additions and 12 deletions

View File

@ -1,13 +1,14 @@
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/utils"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/docker/docker/utils"
)
func TestClientDebugEnabled(t *testing.T) {
@ -16,14 +17,16 @@ func TestClientDebugEnabled(t *testing.T) {
cmd := newDockerCommand(&command.DockerCli{})
cmd.Flags().Set("debug", "true")
if err := cmd.PersistentPreRunE(cmd, []string{}); err != nil {
t.Fatalf("Unexpected error: %s", err.Error())
}
if os.Getenv("DEBUG") != "1" {
t.Fatal("expected debug enabled, got false")
}
if logrus.GetLevel() != logrus.DebugLevel {
t.Fatalf("expected logrus debug level, got %v", logrus.GetLevel())
}
err := cmd.PersistentPreRunE(cmd, []string{})
assert.NilError(t, err)
assert.Equal(t, os.Getenv("DEBUG"), "1")
assert.Equal(t, logrus.GetLevel(), logrus.DebugLevel)
}
func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
discard := ioutil.Discard
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
cmd.SetArgs([]string{"help", "invalid"})
err := cmd.Execute()
assert.Error(t, err, "unknown help topic: invalid")
}