Optimize slow bottleneck tests of TestDaemonStartWithDaemonCommand
| ... | ... |
@@ -35,6 +35,53 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) {
|
| 35 | 35 |
} |
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 |
+func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) {
|
|
| 39 |
+ c := &daemon.Config{}
|
|
| 40 |
+ common := &cli.CommonFlags{
|
|
| 41 |
+ Debug: true, |
|
| 42 |
+ LogLevel: "info", |
|
| 43 |
+ } |
|
| 44 |
+ |
|
| 45 |
+ f, err := ioutil.TempFile("", "docker-config-")
|
|
| 46 |
+ if err != nil {
|
|
| 47 |
+ t.Fatal(err) |
|
| 48 |
+ } |
|
| 49 |
+ |
|
| 50 |
+ configFile := f.Name() |
|
| 51 |
+ f.Write([]byte(`{"log-opts": {"max-size": "1k"}}`))
|
|
| 52 |
+ f.Close() |
|
| 53 |
+ |
|
| 54 |
+ flags := mflag.NewFlagSet("test", mflag.ContinueOnError)
|
|
| 55 |
+ flags.String([]string{daemonConfigFileFlag}, "", "")
|
|
| 56 |
+ flags.BoolVar(&c.EnableSelinuxSupport, []string{"-selinux-enabled"}, true, "")
|
|
| 57 |
+ flags.StringVar(&c.LogConfig.Type, []string{"-log-driver"}, "json-file", "")
|
|
| 58 |
+ flags.Var(opts.NewNamedMapOpts("log-opts", c.LogConfig.Config, nil), []string{"-log-opt"}, "")
|
|
| 59 |
+ flags.Set(daemonConfigFileFlag, configFile) |
|
| 60 |
+ |
|
| 61 |
+ loadedConfig, err := loadDaemonCliConfig(c, flags, common, configFile) |
|
| 62 |
+ if err != nil {
|
|
| 63 |
+ t.Fatal(err) |
|
| 64 |
+ } |
|
| 65 |
+ if loadedConfig == nil {
|
|
| 66 |
+ t.Fatalf("expected configuration %v, got nil", c)
|
|
| 67 |
+ } |
|
| 68 |
+ if !loadedConfig.Debug {
|
|
| 69 |
+ t.Fatalf("expected debug mode, got false")
|
|
| 70 |
+ } |
|
| 71 |
+ if loadedConfig.LogLevel != "info" {
|
|
| 72 |
+ t.Fatalf("expected info log level, got %v", loadedConfig.LogLevel)
|
|
| 73 |
+ } |
|
| 74 |
+ if !loadedConfig.EnableSelinuxSupport {
|
|
| 75 |
+ t.Fatalf("expected enabled selinux support, got disabled")
|
|
| 76 |
+ } |
|
| 77 |
+ if loadedConfig.LogConfig.Type != "json-file" {
|
|
| 78 |
+ t.Fatalf("expected LogConfig type json-file, got %v", loadedConfig.LogConfig.Type)
|
|
| 79 |
+ } |
|
| 80 |
+ if maxSize := loadedConfig.LogConfig.Config["max-size"]; maxSize != "1k" {
|
|
| 81 |
+ t.Fatalf("expected log max-size `1k`, got %s", maxSize)
|
|
| 82 |
+ } |
|
| 83 |
+} |
|
| 84 |
+ |
|
| 38 | 85 |
func TestLoadDaemonCliConfigWithTLS(t *testing.T) {
|
| 39 | 86 |
c := &daemon.Config{}
|
| 40 | 87 |
common := &cli.CommonFlags{
|
| ... | ... |
@@ -432,69 +432,6 @@ func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) {
|
| 432 | 432 |
c.Assert(s.d.Start("--log-level=bogus"), check.NotNil, check.Commentf("Daemon shouldn't start with wrong log level"))
|
| 433 | 433 |
} |
| 434 | 434 |
|
| 435 |
-func (s *DockerSuite) TestDaemonStartWithDaemonCommand(c *check.C) {
|
|
| 436 |
- |
|
| 437 |
- type kind int |
|
| 438 |
- |
|
| 439 |
- const ( |
|
| 440 |
- common kind = iota |
|
| 441 |
- daemon |
|
| 442 |
- ) |
|
| 443 |
- |
|
| 444 |
- var flags = []map[kind][]string{
|
|
| 445 |
- {common: {"-l", "info"}, daemon: {"--selinux-enabled"}},
|
|
| 446 |
- {common: {"-D"}, daemon: {"--selinux-enabled", "-r"}},
|
|
| 447 |
- {common: {"-D"}, daemon: {"--restart"}},
|
|
| 448 |
- {common: {"--debug"}, daemon: {"--log-driver=json-file", "--log-opt=max-size=1k"}},
|
|
| 449 |
- } |
|
| 450 |
- |
|
| 451 |
- var invalidGlobalFlags = [][]string{
|
|
| 452 |
- //Invalid because you cannot pass daemon flags as global flags. |
|
| 453 |
- {"--selinux-enabled", "-l", "info"},
|
|
| 454 |
- {"-D", "-r"},
|
|
| 455 |
- {"--config", "/tmp"},
|
|
| 456 |
- } |
|
| 457 |
- |
|
| 458 |
- // `docker daemon -l info --selinux-enabled` |
|
| 459 |
- // should NOT error out |
|
| 460 |
- for _, f := range flags {
|
|
| 461 |
- d := NewDaemon(c) |
|
| 462 |
- args := append(f[common], f[daemon]...) |
|
| 463 |
- if err := d.Start(args...); err != nil {
|
|
| 464 |
- c.Fatalf("Daemon should have started successfully with %v: %v", args, err)
|
|
| 465 |
- } |
|
| 466 |
- d.Stop() |
|
| 467 |
- } |
|
| 468 |
- |
|
| 469 |
- // `docker -l info daemon --selinux-enabled` |
|
| 470 |
- // should error out |
|
| 471 |
- for _, f := range flags {
|
|
| 472 |
- d := NewDaemon(c) |
|
| 473 |
- d.GlobalFlags = f[common] |
|
| 474 |
- if err := d.Start(f[daemon]...); err == nil {
|
|
| 475 |
- d.Stop() |
|
| 476 |
- c.Fatalf("Daemon should have failed to start with docker %v daemon %v", d.GlobalFlags, f[daemon])
|
|
| 477 |
- } |
|
| 478 |
- } |
|
| 479 |
- |
|
| 480 |
- for _, f := range invalidGlobalFlags {
|
|
| 481 |
- cmd := exec.Command(dockerBinary, append(f, "daemon")...) |
|
| 482 |
- errch := make(chan error) |
|
| 483 |
- var err error |
|
| 484 |
- go func() {
|
|
| 485 |
- errch <- cmd.Run() |
|
| 486 |
- }() |
|
| 487 |
- select {
|
|
| 488 |
- case <-time.After(time.Second): |
|
| 489 |
- cmd.Process.Kill() |
|
| 490 |
- case err = <-errch: |
|
| 491 |
- } |
|
| 492 |
- if err == nil {
|
|
| 493 |
- c.Fatalf("Daemon should have failed to start with docker %v daemon", f)
|
|
| 494 |
- } |
|
| 495 |
- } |
|
| 496 |
-} |
|
| 497 |
- |
|
| 498 | 435 |
func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) {
|
| 499 | 436 |
if err := s.d.Start("--log-level=debug"); err != nil {
|
| 500 | 437 |
c.Fatal(err) |