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"
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-08-07 05:52:40 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
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-05 18:53:52 -05:00
|
|
|
assert.Check(t, err)
|
|
|
|
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
|
|
|
|
cmd := newDockerCommand(command.NewDockerCli(os.Stdin, discard, discard))
|
|
|
|
cmd.SetArgs([]string{"help", "invalid"})
|
|
|
|
err := cmd.Execute()
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Error(err, "unknown help topic: invalid"))
|
2016-04-23 21:31:57 -04:00
|
|
|
}
|