Browse code

Clean-up after container unit test

Remove temp directories and close file loggers in container unit tests.

Signed-off-by: mnussbaum <michael.nussbaum@getbraintree.com>

mnussbaum authored on 2018/02/28 04:07:06
Showing 1 changed files
... ...
@@ -3,6 +3,7 @@ package container // import "github.com/docker/docker/container"
3 3
 import (
4 4
 	"fmt"
5 5
 	"io/ioutil"
6
+	"os"
6 7
 	"path/filepath"
7 8
 	"testing"
8 9
 
... ...
@@ -74,6 +75,7 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) {
74 74
 func TestContainerLogPathSetForJSONFileLogger(t *testing.T) {
75 75
 	containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForJSONFileLogger")
76 76
 	require.NoError(t, err)
77
+	defer os.RemoveAll(containerRoot)
77 78
 
78 79
 	c := &Container{
79 80
 		Config: &container.Config{},
... ...
@@ -86,8 +88,9 @@ func TestContainerLogPathSetForJSONFileLogger(t *testing.T) {
86 86
 		Root: containerRoot,
87 87
 	}
88 88
 
89
-	_, err = c.StartLogger()
89
+	logger, err := c.StartLogger()
90 90
 	require.NoError(t, err)
91
+	defer logger.Close()
91 92
 
92 93
 	expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID)))
93 94
 	require.NoError(t, err)
... ...
@@ -97,6 +100,7 @@ func TestContainerLogPathSetForJSONFileLogger(t *testing.T) {
97 97
 func TestContainerLogPathSetForRingLogger(t *testing.T) {
98 98
 	containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForRingLogger")
99 99
 	require.NoError(t, err)
100
+	defer os.RemoveAll(containerRoot)
100 101
 
101 102
 	c := &Container{
102 103
 		Config: &container.Config{},
... ...
@@ -112,8 +116,9 @@ func TestContainerLogPathSetForRingLogger(t *testing.T) {
112 112
 		Root: containerRoot,
113 113
 	}
114 114
 
115
-	_, err = c.StartLogger()
115
+	logger, err := c.StartLogger()
116 116
 	require.NoError(t, err)
117
+	defer logger.Close()
117 118
 
118 119
 	expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID)))
119 120
 	require.NoError(t, err)