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 <bergwolf@hyper.sh>
This commit is contained in:
Peng Tao 2019-10-08 09:32:45 -07:00
parent 6ab89e4549
commit dd21046072

View File

@ -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)