From 0495fece57dc9f66b18bf828e47fee642098358d Mon Sep 17 00:00:00 2001 From: Danail Branekov Date: Mon, 27 Nov 2017 10:43:10 +0200 Subject: [PATCH] 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 --- libcontainer/container_linux_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libcontainer/container_linux_test.go b/libcontainer/container_linux_test.go index 3c9143ab514..e90b4b5e48e 100644 --- a/libcontainer/container_linux_test.go +++ b/libcontainer/container_linux_test.go @@ -4,6 +4,7 @@ package libcontainer import ( "fmt" + "io/ioutil" "os" "testing" @@ -281,8 +282,16 @@ func TestGetContainerStateAfterUpdate(t *testing.T) { if err != nil { t.Fatal(err) } + + rootDir, err := ioutil.TempDir("", "TestGetContainerStateAfterUpdate") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(rootDir) + container := &linuxContainer{ - id: "myid", + root: rootDir, + id: "myid", config: &configs.Config{ Namespaces: []configs.Namespace{ {Type: configs.NEWPID},