Browse code

Change related test from DockerSuite to DockerDaemonSuite in `docker_cli_daemon_test.go`

This fix is a follow-up of 26154. I did a grep on `integration-cli` and
found out that there are several tests in `docker_cli_daemon_test.go`
that still use `NewDaemon` instread of `DockerDaemonSuite`.

This fix changes related tests from DockerSuite to DockerDaemonSuite in
`docker_cli_daemon_test.go`.

With this fix, now `NewDaemon` is only called from `SetUpTest` on
various DockerXXXSuite. That should help maintain the test code base.

This fix is related to the comments in:
26115
24533.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>

Yong Tang authored on 2016/08/31 06:25:16
Showing 1 changed files
... ...
@@ -349,17 +349,15 @@ func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) {
349 349
 
350 350
 // TestDaemonIPv6Enabled checks that when the daemon is started with --ipv6=true that the docker0 bridge
351 351
 // has the fe80::1 address and that a container is assigned a link-local address
352
-func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) {
352
+func (s *DockerDaemonSuite) TestDaemonIPv6Enabled(c *check.C) {
353 353
 	testRequires(c, IPv6)
354 354
 
355 355
 	setupV6(c)
356 356
 	defer teardownV6(c)
357
-	d := NewDaemon(c)
358 357
 
359
-	if err := d.StartWithBusybox("--ipv6"); err != nil {
358
+	if err := s.d.StartWithBusybox("--ipv6"); err != nil {
360 359
 		c.Fatal(err)
361 360
 	}
362
-	defer d.Stop()
363 361
 
364 362
 	iface, err := net.InterfaceByName("docker0")
365 363
 	if err != nil {
... ...
@@ -385,11 +383,11 @@ func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) {
385 385
 		c.Fatalf("Bridge does not have an IPv6 Address")
386 386
 	}
387 387
 
388
-	if out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil {
388
+	if out, err := s.d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil {
389 389
 		c.Fatalf("Could not run container: %s, %v", out, err)
390 390
 	}
391 391
 
392
-	out, err := d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.LinkLocalIPv6Address}}'", "ipv6test")
392
+	out, err := s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.LinkLocalIPv6Address}}'", "ipv6test")
393 393
 	out = strings.Trim(out, " \r\n'")
394 394
 
395 395
 	if err != nil {
... ...
@@ -400,7 +398,7 @@ func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) {
400 400
 		c.Fatalf("Container should have a link-local IPv6 address")
401 401
 	}
402 402
 
403
-	out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}'", "ipv6test")
403
+	out, err = s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.Networks.bridge.GlobalIPv6Address}}'", "ipv6test")
404 404
 	out = strings.Trim(out, " \r\n'")
405 405
 
406 406
 	if err != nil {
... ...
@@ -890,19 +888,16 @@ func (s *DockerDaemonSuite) TestDaemonDefaultNetworkInvalidClusterConfig(c *chec
890 890
 	defaultNetworkBridge := "docker0"
891 891
 	deleteInterface(c, defaultNetworkBridge)
892 892
 
893
-	d := NewDaemon(c)
894 893
 	discoveryBackend := "consul://consuladdr:consulport/some/path"
895
-	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend))
894
+	err := s.d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend))
896 895
 	c.Assert(err, checker.IsNil)
897 896
 
898 897
 	// Start daemon with docker0 bridge
899 898
 	result := icmd.RunCommand("ifconfig", defaultNetworkBridge)
900 899
 	c.Assert(result, icmd.Matches, icmd.Success)
901 900
 
902
-	err = d.Restart(fmt.Sprintf("--cluster-store=%s", discoveryBackend))
901
+	err = s.d.Restart(fmt.Sprintf("--cluster-store=%s", discoveryBackend))
903 902
 	c.Assert(err, checker.IsNil)
904
-
905
-	d.Stop()
906 903
 }
907 904
 
908 905
 func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) {
... ...
@@ -1948,9 +1943,7 @@ func (s *DockerDaemonSuite) TestDaemonNoSpaceLeftOnDeviceError(c *check.C) {
1948 1948
 
1949 1949
 // Test daemon restart with container links + auto restart
1950 1950
 func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) {
1951
-	d := NewDaemon(c)
1952
-	defer d.Stop()
1953
-	err := d.StartWithBusybox()
1951
+	err := s.d.StartWithBusybox()
1954 1952
 	c.Assert(err, checker.IsNil)
1955 1953
 
1956 1954
 	parent1Args := []string{}
... ...
@@ -1970,7 +1963,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) {
1970 1970
 		}
1971 1971
 
1972 1972
 		go func() {
1973
-			_, err = d.Cmd("run", "-d", "--name", name, "--restart=always", "busybox", "top")
1973
+			_, err = s.d.Cmd("run", "-d", "--name", name, "--restart=always", "busybox", "top")
1974 1974
 			chErr <- err
1975 1975
 			wg.Done()
1976 1976
 		}()
... ...
@@ -1987,24 +1980,24 @@ func (s *DockerDaemonSuite) TestDaemonRestartContainerLinksRestart(c *check.C) {
1987 1987
 	parent2Args = append([]string{"run", "-d"}, parent2Args...)
1988 1988
 	parent2Args = append(parent2Args, []string{"--name=parent2", "--restart=always", "busybox", "top"}...)
1989 1989
 
1990
-	_, err = d.Cmd(parent1Args...)
1990
+	_, err = s.d.Cmd(parent1Args...)
1991 1991
 	c.Assert(err, check.IsNil)
1992
-	_, err = d.Cmd(parent2Args...)
1992
+	_, err = s.d.Cmd(parent2Args...)
1993 1993
 	c.Assert(err, check.IsNil)
1994 1994
 
1995
-	err = d.Stop()
1995
+	err = s.d.Stop()
1996 1996
 	c.Assert(err, check.IsNil)
1997 1997
 	// clear the log file -- we don't need any of it but may for the next part
1998 1998
 	// can ignore the error here, this is just a cleanup
1999
-	os.Truncate(d.LogFileName(), 0)
2000
-	err = d.Start()
1999
+	os.Truncate(s.d.LogFileName(), 0)
2000
+	err = s.d.Start()
2001 2001
 	c.Assert(err, check.IsNil)
2002 2002
 
2003 2003
 	for _, num := range []string{"1", "2"} {
2004
-		out, err := d.Cmd("inspect", "-f", "{{ .State.Running }}", "parent"+num)
2004
+		out, err := s.d.Cmd("inspect", "-f", "{{ .State.Running }}", "parent"+num)
2005 2005
 		c.Assert(err, check.IsNil)
2006 2006
 		if strings.TrimSpace(out) != "true" {
2007
-			log, _ := ioutil.ReadFile(d.LogFileName())
2007
+			log, _ := ioutil.ReadFile(s.d.LogFileName())
2008 2008
 			c.Fatalf("parent container is not running\n%s", string(log))
2009 2009
 		}
2010 2010
 	}
... ...
@@ -2299,7 +2292,6 @@ func (s *DockerDaemonSuite) TestRunLinksChanged(c *check.C) {
2299 2299
 
2300 2300
 func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
2301 2301
 	testRequires(c, DaemonIsLinux, NotPpc64le)
2302
-	newD := NewDaemon(c)
2303 2302
 
2304 2303
 	infoLog := "\x1b[34mINFO\x1b"
2305 2304
 
... ...
@@ -2314,21 +2306,20 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutColors(c *check.C) {
2314 2314
 	go io.Copy(b, p)
2315 2315
 
2316 2316
 	// Enable coloring explicitly
2317
-	newD.StartWithLogFile(tty, "--raw-logs=false")
2318
-	newD.Stop()
2317
+	s.d.StartWithLogFile(tty, "--raw-logs=false")
2318
+	s.d.Stop()
2319 2319
 	c.Assert(b.String(), checker.Contains, infoLog)
2320 2320
 
2321 2321
 	b.Reset()
2322 2322
 
2323 2323
 	// Disable coloring explicitly
2324
-	newD.StartWithLogFile(tty, "--raw-logs=true")
2325
-	newD.Stop()
2324
+	s.d.StartWithLogFile(tty, "--raw-logs=true")
2325
+	s.d.Stop()
2326 2326
 	c.Assert(b.String(), check.Not(checker.Contains), infoLog)
2327 2327
 }
2328 2328
 
2329 2329
 func (s *DockerDaemonSuite) TestDaemonDebugLog(c *check.C) {
2330 2330
 	testRequires(c, DaemonIsLinux, NotPpc64le)
2331
-	newD := NewDaemon(c)
2332 2331
 
2333 2332
 	debugLog := "\x1b[37mDEBU\x1b"
2334 2333
 
... ...
@@ -2342,12 +2333,12 @@ func (s *DockerDaemonSuite) TestDaemonDebugLog(c *check.C) {
2342 2342
 	b := bytes.NewBuffer(nil)
2343 2343
 	go io.Copy(b, p)
2344 2344
 
2345
-	newD.StartWithLogFile(tty, "--debug")
2346
-	newD.Stop()
2345
+	s.d.StartWithLogFile(tty, "--debug")
2346
+	s.d.Stop()
2347 2347
 	c.Assert(b.String(), checker.Contains, debugLog)
2348 2348
 }
2349 2349
 
2350
-func (s *DockerSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
2350
+func (s *DockerDaemonSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
2351 2351
 	testRequires(c, SameHostDaemon, DaemonIsLinux)
2352 2352
 
2353 2353
 	// daemon config file
... ...
@@ -2363,12 +2354,10 @@ func (s *DockerSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
2363 2363
 	_, err = configFile.Write([]byte(daemonConfig))
2364 2364
 	c.Assert(err, checker.IsNil)
2365 2365
 
2366
-	d := NewDaemon(c)
2367 2366
 	// --log-level needs to be set so that d.Start() doesn't add --debug causing
2368 2367
 	// a conflict with the config
2369
-	err = d.Start("--config-file", configFilePath, "--log-level=info")
2368
+	err = s.d.Start("--config-file", configFilePath, "--log-level=info")
2370 2369
 	c.Assert(err, checker.IsNil)
2371
-	defer d.Stop()
2372 2370
 
2373 2371
 	// daemon config file
2374 2372
 	daemonConfig = `{
... ...
@@ -2385,10 +2374,10 @@ func (s *DockerSuite) TestDaemonDiscoveryBackendConfigReload(c *check.C) {
2385 2385
 	_, err = configFile.Write([]byte(daemonConfig))
2386 2386
 	c.Assert(err, checker.IsNil)
2387 2387
 
2388
-	err = d.reloadConfig()
2388
+	err = s.d.reloadConfig()
2389 2389
 	c.Assert(err, checker.IsNil, check.Commentf("error reloading daemon config"))
2390 2390
 
2391
-	out, err := d.Cmd("info")
2391
+	out, err := s.d.Cmd("info")
2392 2392
 	c.Assert(err, checker.IsNil)
2393 2393
 
2394 2394
 	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster Store: consul://consuladdr:consulport/some/path"))