1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #20476 from wenchma/19425-TestDaemonStartWithDaemonCommand

Optimize slow bottleneck tests of TestDaemonStartWithDaemonCommand
This commit is contained in:
Tibor Vass 2016-03-11 10:54:48 -05:00
commit 1c0474ed63
2 changed files with 47 additions and 63 deletions

View file

@ -35,6 +35,53 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
}
}
func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
c := &daemon.Config{}
common := &cli.CommonFlags{
Debug: true,
LogLevel: "info",
}
f, err := ioutil.TempFile("", "docker-config-")
if err != nil {
t.Fatal(err)
}
configFile := f.Name()
f.Write([]byte(`{"log-opts": {"max-size": "1k"}}`))
f.Close()
flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
flags.String([]string{daemonConfigFileFlag}, "", "")
flags.BoolVar(&c.EnableSelinuxSupport, []string{"-selinux-enabled"}, true, "")
flags.StringVar(&c.LogConfig.Type, []string{"-log-driver"}, "json-file", "")
flags.Var(opts.NewNamedMapOpts("log-opts", c.LogConfig.Config, nil), []string{"-log-opt"}, "")
flags.Set(daemonConfigFileFlag, configFile)
loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile)
if err != nil {
t.Fatal(err)
}
if loadedConfig == nil {
t.Fatalf("expected configuration %v, got nil", c)
}
if !loadedConfig.Debug {
t.Fatalf("expected debug mode, got false")
}
if loadedConfig.LogLevel != "info" {
t.Fatalf("expected info log level, got %v", loadedConfig.LogLevel)
}
if !loadedConfig.EnableSelinuxSupport {
t.Fatalf("expected enabled selinux support, got disabled")
}
if loadedConfig.LogConfig.Type != "json-file" {
t.Fatalf("expected LogConfig type json-file, got %v", loadedConfig.LogConfig.Type)
}
if maxSize := loadedConfig.LogConfig.Config["max-size"]; maxSize != "1k" {
t.Fatalf("expected log max-size `1k`, got %s", maxSize)
}
}
func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
c := &daemon.Config{}
common := &cli.CommonFlags{

View file

@ -432,69 +432,6 @@ func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) {
c.Assert(s.d.Start("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level"))
}
func (s *DockerSuite) TestDaemonStartWithDaemonCommand(c *check.C) {
type kind int
const (
common kind = iota
daemon
)
var flags = []map[kind][]string{
{common: {"-l", "info"}, daemon: {"--selinux-enabled"}},
{common: {"-D"}, daemon: {"--selinux-enabled", "-r"}},
{common: {"-D"}, daemon: {"--restart"}},
{common: {"--debug"}, daemon: {"--log-driver=json-file", "--log-opt=max-size=1k"}},
}
var invalidGlobalFlags = [][]string{
//Invalid because you cannot pass daemon flags as global flags.
{"--selinux-enabled", "-l", "info"},
{"-D", "-r"},
{"--config", "/tmp"},
}
// `docker daemon -l info --selinux-enabled`
// should NOT error out
for _, f := range flags {
d := NewDaemon(c)
args := append(f[common], f[daemon]...)
if err := d.Start(args...); err != nil {
c.Fatalf("Daemon should have started successfully with %v: %v", args, err)
}
d.Stop()
}
// `docker -l info daemon --selinux-enabled`
// should error out
for _, f := range flags {
d := NewDaemon(c)
d.GlobalFlags = f[common]
if err := d.Start(f[daemon]...); err == nil {
d.Stop()
c.Fatalf("Daemon should have failed to start with docker %v daemon %v", d.GlobalFlags, f[daemon])
}
}
for _, f := range invalidGlobalFlags {
cmd := exec.Command(dockerBinary, append(f, "daemon")...)
errch := make(chan error)
var err error
go func() {
errch <- cmd.Run()
}()
select {
case <-time.After(time.Second):
cmd.Process.Kill()
case err = <-errch:
}
if err == nil {
c.Fatalf("Daemon should have failed to start with docker %v daemon", f)
}
}
}
func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) {
if err := s.d.Start("--log-level=debug"); err != nil {
c.Fatal(err)