Browse code

Add missing defer to delete temp dir

Minor thing I just noticed

Signed-off-by: Doug Davis <dug@us.ibm.com>

Doug Davis authored on 2015/09/01 23:00:40
Showing 3 changed files
... ...
@@ -410,7 +410,12 @@ func TestJsonSaveWithNoFile(t *testing.T) {
410 410
 		t.Fatalf("Expected error. File should not have been able to save with no file name.")
411 411
 	}
412 412
 
413
-	tmpHome, _ := ioutil.TempDir("", "config-test")
413
+	tmpHome, err := ioutil.TempDir("", "config-test")
414
+	if err != nil {
415
+		t.Fatalf("Failed to create a temp dir: %q", err)
416
+	}
417
+	defer os.RemoveAll(tmpHome)
418
+
414 419
 	fn := filepath.Join(tmpHome, ConfigFileName)
415 420
 	f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
416 421
 	err = config.SaveToWriter(f)
... ...
@@ -433,7 +438,12 @@ func TestLegacyJsonSaveWithNoFile(t *testing.T) {
433 433
 		t.Fatalf("Expected error. File should not have been able to save with no file name.")
434 434
 	}
435 435
 
436
-	tmpHome, _ := ioutil.TempDir("", "config-test")
436
+	tmpHome, err := ioutil.TempDir("", "config-test")
437
+	if err != nil {
438
+		t.Fatalf("Failed to create a temp dir: %q", err)
439
+	}
440
+	defer os.RemoveAll(tmpHome)
441
+
437 442
 	fn := filepath.Join(tmpHome, ConfigFileName)
438 443
 	f, _ := os.OpenFile(fn, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
439 444
 	err = config.SaveToWriter(f)
... ...
@@ -4790,7 +4790,8 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) {
4790 4790
 		c.Fatalf("test4 should have used dFile, output:%s", out)
4791 4791
 	}
4792 4792
 
4793
-	dirWithNoDockerfile, _ := ioutil.TempDir(os.TempDir(), "test5")
4793
+	dirWithNoDockerfile, err := ioutil.TempDir(os.TempDir(), "test5")
4794
+	c.Assert(err, check.IsNil)
4794 4795
 	nonDockerfileFile := filepath.Join(dirWithNoDockerfile, "notDockerfile")
4795 4796
 	if _, err = os.Create(nonDockerfileFile); err != nil {
4796 4797
 		c.Fatal(err)
... ...
@@ -30,7 +30,8 @@ func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
30 30
 
31 31
 	homeKey := homedir.Key()
32 32
 	homeVal := homedir.Get()
33
-	tmpDir, _ := ioutil.TempDir("", "fake-home")
33
+	tmpDir, err := ioutil.TempDir("", "fake-home")
34
+	c.Assert(err, check.IsNil)
34 35
 	defer os.RemoveAll(tmpDir)
35 36
 
36 37
 	dotDocker := filepath.Join(tmpDir, ".docker")
... ...
@@ -44,7 +45,7 @@ func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
44 44
 		"HttpHeaders": { "MyHeader": "MyValue" }
45 45
 	}`
46 46
 
47
-	err := ioutil.WriteFile(tmpCfg, []byte(data), 0600)
47
+	err = ioutil.WriteFile(tmpCfg, []byte(data), 0600)
48 48
 	if err != nil {
49 49
 		c.Fatalf("Err creating file(%s): %v", tmpCfg, err)
50 50
 	}
... ...
@@ -66,7 +67,9 @@ func (s *DockerSuite) TestConfigHttpHeader(c *check.C) {
66 66
 }
67 67
 
68 68
 func (s *DockerSuite) TestConfigDir(c *check.C) {
69
-	cDir, _ := ioutil.TempDir("", "fake-home")
69
+	cDir, err := ioutil.TempDir("", "fake-home")
70
+	c.Assert(err, check.IsNil)
71
+	defer os.RemoveAll(cDir)
70 72
 
71 73
 	// First make sure pointing to empty dir doesn't generate an error
72 74
 	out, rc := dockerCmd(c, "--config", cDir, "ps")
... ...
@@ -78,7 +81,7 @@ func (s *DockerSuite) TestConfigDir(c *check.C) {
78 78
 	// Test with env var too
79 79
 	cmd := exec.Command(dockerBinary, "ps")
80 80
 	cmd.Env = append(os.Environ(), "DOCKER_CONFIG="+cDir)
81
-	out, rc, err := runCommandWithOutput(cmd)
81
+	out, rc, err = runCommandWithOutput(cmd)
82 82
 
83 83
 	if rc != 0 || err != nil {
84 84
 		c.Fatalf("ps2 didn't work:\nrc:%d\nout%s\nerr:%v", rc, out, err)