Skip to content

Commit 0495fec

Browse files
danail-branekovTom Godkin
authored andcommitted
Ensure container tests do not write on the host
TestGetContainerStateAfterUpdate creates its state.json file on the current directory which turns out to be the host runc directory. Thus whenever the test completes it leaves the state.json file behind thus a) poluting the local git repository b) changing the host file system violating the principle of doing everything in an isolated container environment This change would create a new temporary (in-container) directory and use it as linuxContainer.root Signed-off-by: Tom Godkin <[email protected]>
1 parent fb6ec65 commit 0495fec

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

libcontainer/container_linux_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package libcontainer
44

55
import (
66
"fmt"
7+
"io/ioutil"
78
"os"
89
"testing"
910

@@ -281,8 +282,16 @@ func TestGetContainerStateAfterUpdate(t *testing.T) {
281282
if err != nil {
282283
t.Fatal(err)
283284
}
285+
286+
rootDir, err := ioutil.TempDir("", "TestGetContainerStateAfterUpdate")
287+
if err != nil {
288+
t.Fatal(err)
289+
}
290+
defer os.RemoveAll(rootDir)
291+
284292
container := &linuxContainer{
285-
id: "myid",
293+
root: rootDir,
294+
id: "myid",
286295
config: &configs.Config{
287296
Namespaces: []configs.Namespace{
288297
{Type: configs.NEWPID},

0 commit comments

Comments
 (0)