From dd2104607244c86d7c5b68d1c1b771b677087258 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Tue, 8 Oct 2019 09:32:45 -0700 Subject: [PATCH] vc/store: fix TestStoreVCNewVCSandboxStore/TestStoreVCNewVCContainerStore They both need to set a temporary test dir in order to run as non-root. Signed-off-by: Peng Tao --- virtcontainers/store/vc_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/virtcontainers/store/vc_test.go b/virtcontainers/store/vc_test.go index 754b0f210b..38f327fd5e 100644 --- a/virtcontainers/store/vc_test.go +++ b/virtcontainers/store/vc_test.go @@ -8,6 +8,8 @@ package store import ( "context" "fmt" + "io/ioutil" + "os" "testing" "github.com/stretchr/testify/assert" @@ -99,6 +101,17 @@ func TestStoreVCSandboxFileNegative(t *testing.T) { } func TestStoreVCNewVCSandboxStore(t *testing.T) { + testDir, _ := ioutil.TempDir("", "vmfactory-tmp-") + defer func() { + os.RemoveAll(testDir) + }() + + var savedStorePath = VCStorePrefix + VCStorePrefix = testDir + defer func() { + VCStorePrefix = savedStorePath + }() + _, err := NewVCSandboxStore(context.Background(), testSandboxID) assert.Nil(t, err) @@ -107,6 +120,17 @@ func TestStoreVCNewVCSandboxStore(t *testing.T) { } func TestStoreVCNewVCContainerStore(t *testing.T) { + testDir, _ := ioutil.TempDir("", "vmfactory-tmp-") + defer func() { + os.RemoveAll(testDir) + }() + + var savedStorePath = VCStorePrefix + VCStorePrefix = testDir + defer func() { + VCStorePrefix = savedStorePath + }() + _, err := NewVCContainerStore(context.Background(), testSandboxID, "foobar") assert.Nil(t, err)