2016-04-23 21:31:57 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-15 11:18:33 -05:00
|
|
|
"io/ioutil"
|
2016-04-23 21:31:57 -04:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2016-09-08 13:11:39 -04:00
|
|
|
"github.com/docker/docker/cli/command"
|
2016-12-12 03:33:58 -05:00
|
|
|
"github.com/docker/docker/cli/debug"
|
2016-11-15 11:18:33 -05:00
|
|
|
"github.com/docker/docker/pkg/testutil/assert"
|
2016-04-23 21:31:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestClientDebugEnabled(t *testing.T) {
|
2016-12-12 03:33:58 -05:00
|
|
|
defer debug.Disable()
|
2016-04-23 21:31:57 -04:00
|
|
|
|
2016-09-08 13:11:39 -04:00
|
|
|
cmd := newDockerCommand(&command.DockerCli{})
|
2016-06-22 18:36:51 -04:00
|
|
|
cmd.Flags().Set("debug", "true")
|
2016-06-22 13:08:04 -04:00
|
|
|
|
2016-11-15 11:18:33 -05:00
|
|
|
err := cmd.PersistentPreRunE(cmd, []string{})
|
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Equal(t, os.Getenv("DEBUG"), "1")
|
|
|
|
assert.Equal(t, logrus.GetLevel(), logrus.DebugLevel)
|
|
|
|
}
|
2016-04-23 21:31:57 -04:00
|
|
|
|
2016-11-15 11:18:33 -05:00
|
|
|
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")
|
2016-04-23 21:31:57 -04:00
|
|
|
}
|