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"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/cli/cli/debug"
|
2017-08-07 05:52:40 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-06-08 12:24:26 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
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{})
|
2018-03-06 14:44:13 -05:00
|
|
|
assert.NilError(t, err)
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("1", os.Getenv("DEBUG")))
|
|
|
|
assert.Check(t, is.Equal(logrus.DebugLevel, logrus.GetLevel()))
|
2016-11-15 11:18:33 -05:00
|
|
|
}
|
2016-04-23 21:31:57 -04:00
|
|
|
|
2016-11-15 11:18:33 -05:00
|
|
|
func TestExitStatusForInvalidSubcommandWithHelpFlag(t *testing.T) {
|
|
|
|
discard := ioutil.Discard
|
2018-09-11 08:46:30 -04:00
|
|
|
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard, false, nil))
|
2016-11-15 11:18:33 -05:00
|
|
|
cmd.SetArgs([]string{"help", "invalid"})
|
|
|
|
err := cmd.Execute()
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, err, "unknown help topic: invalid")
|
2016-04-23 21:31:57 -04:00
|
|
|
}
|