Browse code

pkg/system: fix cleanup in tests

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/11/21 02:33:15
Showing 3 changed files
... ...
@@ -1,11 +1,13 @@
1 1
 package system
2 2
 
3 3
 import (
4
+	"os"
4 5
 	"testing"
5 6
 )
6 7
 
7 8
 func TestLstat(t *testing.T) {
8
-	file, invalid, _ := prepareFiles(t)
9
+	file, invalid, _, dir := prepareFiles(t)
10
+	defer os.RemoveAll(dir)
9 11
 
10 12
 	statFile, err := Lstat(file)
11 13
 	if err != nil {
... ...
@@ -1,12 +1,14 @@
1 1
 package system
2 2
 
3 3
 import (
4
+	"os"
4 5
 	"syscall"
5 6
 	"testing"
6 7
 )
7 8
 
8 9
 func TestFromStatT(t *testing.T) {
9
-	file, _, _ := prepareFiles(t)
10
+	file, _, _, dir := prepareFiles(t)
11
+	defer os.RemoveAll(dir)
10 12
 
11 13
 	stat := &syscall.Stat_t{}
12 14
 	err := syscall.Lstat(file, stat)
... ...
@@ -8,7 +8,7 @@ import (
8 8
 	"testing"
9 9
 )
10 10
 
11
-func prepareFiles(t *testing.T) (string, string, string) {
11
+func prepareFiles(t *testing.T) (string, string, string, string) {
12 12
 	dir, err := ioutil.TempDir("", "docker-system-test")
13 13
 	if err != nil {
14 14
 		t.Fatal(err)
... ...
@@ -26,11 +26,12 @@ func prepareFiles(t *testing.T) (string, string, string) {
26 26
 		t.Fatal(err)
27 27
 	}
28 28
 
29
-	return file, invalid, symlink
29
+	return file, invalid, symlink, dir
30 30
 }
31 31
 
32 32
 func TestLUtimesNano(t *testing.T) {
33
-	file, invalid, symlink := prepareFiles(t)
33
+	file, invalid, symlink, dir := prepareFiles(t)
34
+	defer os.RemoveAll(dir)
34 35
 
35 36
 	before, err := os.Stat(file)
36 37
 	if err != nil {