mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add regression tests for client debug flag.
- Add client debug info to the `docker info` command. Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
b6a6ed7200
commit
9f315dd328
5 changed files with 110 additions and 1 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
|
"github.com/docker/docker/utils"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -73,8 +74,10 @@ func (cli *DockerCli) CmdInfo(args ...string) error {
|
||||||
ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name)
|
ioutils.FprintfIfNotEmpty(cli.out, "Name: %s\n", info.Name)
|
||||||
ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID)
|
ioutils.FprintfIfNotEmpty(cli.out, "ID: %s\n", info.ID)
|
||||||
|
|
||||||
if info.Debug {
|
fmt.Fprintf(cli.out, "Debug mode (client): %v\n", utils.IsDebugEnabled())
|
||||||
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
|
fmt.Fprintf(cli.out, "Debug mode (server): %v\n", info.Debug)
|
||||||
|
|
||||||
|
if info.Debug {
|
||||||
fmt.Fprintf(cli.out, " File Descriptors: %d\n", info.NFd)
|
fmt.Fprintf(cli.out, " File Descriptors: %d\n", info.NFd)
|
||||||
fmt.Fprintf(cli.out, " Goroutines: %d\n", info.NGoroutines)
|
fmt.Fprintf(cli.out, " Goroutines: %d\n", info.NGoroutines)
|
||||||
fmt.Fprintf(cli.out, " System Time: %s\n", info.SystemTime)
|
fmt.Fprintf(cli.out, " System Time: %s\n", info.SystemTime)
|
||||||
|
|
23
docker/client_test.go
Normal file
23
docker/client_test.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
"github.com/docker/docker/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestClientDebugEnabled(t *testing.T) {
|
||||||
|
defer utils.DisableDebug()
|
||||||
|
|
||||||
|
clientFlags.Common.FlagSet.Parse([]string{"-D"})
|
||||||
|
clientFlags.PostParse()
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}
|
|
@ -2095,3 +2095,24 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
|
||||||
newD.Stop()
|
newD.Stop()
|
||||||
c.Assert(b.String(), check.Not(checker.Contains), infoLog)
|
c.Assert(b.String(), check.Not(checker.Contains), infoLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerDaemonSuite) TestDaemonDebugLog(c *check.C) {
|
||||||
|
testRequires(c, DaemonIsLinux)
|
||||||
|
newD := NewDaemon(c)
|
||||||
|
|
||||||
|
debugLog := "\x1b[37mDEBU\x1b"
|
||||||
|
|
||||||
|
p, tty, err := pty.Open()
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
defer func() {
|
||||||
|
tty.Close()
|
||||||
|
p.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
b := bytes.NewBuffer(nil)
|
||||||
|
go io.Copy(b, p)
|
||||||
|
|
||||||
|
newD.StartWithLogFile(tty, "--debug")
|
||||||
|
newD.Stop()
|
||||||
|
c.Assert(b.String(), checker.Contains, debugLog)
|
||||||
|
}
|
||||||
|
|
|
@ -146,3 +146,22 @@ func (s *DockerSuite) TestInfoDisplaysStoppedContainers(c *check.C) {
|
||||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Paused: %d\n", 0))
|
||||||
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
|
c.Assert(out, checker.Contains, fmt.Sprintf(" Stopped: %d\n", 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DockerSuite) TestInfoDebug(c *check.C) {
|
||||||
|
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
||||||
|
|
||||||
|
d := NewDaemon(c)
|
||||||
|
err := d.Start("--debug")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
defer d.Stop()
|
||||||
|
|
||||||
|
out, err := d.Cmd("--debug", "info")
|
||||||
|
c.Assert(err, checker.IsNil)
|
||||||
|
c.Assert(out, checker.Contains, "Debug mode (client): true\n")
|
||||||
|
c.Assert(out, checker.Contains, "Debug mode (server): true\n")
|
||||||
|
c.Assert(out, checker.Contains, "File Descriptors")
|
||||||
|
c.Assert(out, checker.Contains, "Goroutines")
|
||||||
|
c.Assert(out, checker.Contains, "System Time")
|
||||||
|
c.Assert(out, checker.Contains, "EventsListeners")
|
||||||
|
c.Assert(out, checker.Contains, "Docker Root Dir")
|
||||||
|
}
|
||||||
|
|
43
utils/debug_test.go
Normal file
43
utils/debug_test.go
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEnableDebug(t *testing.T) {
|
||||||
|
defer func() {
|
||||||
|
os.Setenv("DEBUG", "")
|
||||||
|
logrus.SetLevel(logrus.InfoLevel)
|
||||||
|
}()
|
||||||
|
EnableDebug()
|
||||||
|
if os.Getenv("DEBUG") != "1" {
|
||||||
|
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
|
||||||
|
}
|
||||||
|
if logrus.GetLevel() != logrus.DebugLevel {
|
||||||
|
t.Fatalf("expected log level %v, got %v\n", logrus.DebugLevel, logrus.GetLevel())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDisableDebug(t *testing.T) {
|
||||||
|
DisableDebug()
|
||||||
|
if os.Getenv("DEBUG") != "" {
|
||||||
|
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
|
||||||
|
}
|
||||||
|
if logrus.GetLevel() != logrus.InfoLevel {
|
||||||
|
t.Fatalf("expected log level %v, got %v\n", logrus.InfoLevel, logrus.GetLevel())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDebugEnabled(t *testing.T) {
|
||||||
|
EnableDebug()
|
||||||
|
if !IsDebugEnabled() {
|
||||||
|
t.Fatal("expected debug enabled, got false")
|
||||||
|
}
|
||||||
|
DisableDebug()
|
||||||
|
if IsDebugEnabled() {
|
||||||
|
t.Fatal("expected debug disabled, got true")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue