mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
runtime: Don't abuse MockStorageRootPath() for factory tests
A number of unit tests under virtcontainers/factory use MockStorageRootPath() as a general purpose temporary directory. This doesn't make sense: the mockfs driver isn't even in use here since we only call EnableMockTesting for the pase virtcontainers package, not the subpackages. Instead use t.TempDir() which is for exactly this purpose. As a bonus it also handles the cleanup, so we don't need MockStorageDestroy any more. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
bec59f9e39
commit
1719a8b491
@ -13,14 +13,12 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/factory/direct"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs"
|
||||
)
|
||||
|
||||
func TestTemplateFactory(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testDir := fs.MockStorageRootPath()
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
|
||||
hyperConfig := vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
|
@ -12,14 +12,12 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs"
|
||||
)
|
||||
|
||||
func TestTemplateFactory(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testDir := fs.MockStorageRootPath()
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
|
||||
hyperConfig := vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/factory/base"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -39,10 +38,10 @@ func TestNewFactory(t *testing.T) {
|
||||
_, err = NewFactory(ctx, config, false)
|
||||
assert.Error(err)
|
||||
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||
KernelPath: fs.MockStorageRootPath(),
|
||||
ImagePath: fs.MockStorageRootPath(),
|
||||
KernelPath: testDir,
|
||||
ImagePath: testDir,
|
||||
}
|
||||
|
||||
// direct
|
||||
@ -69,7 +68,7 @@ func TestNewFactory(t *testing.T) {
|
||||
defer hybridVSockTTRPCMock.Stop()
|
||||
|
||||
config.Template = true
|
||||
config.TemplatePath = fs.MockStorageRootPath()
|
||||
config.TemplatePath = testDir
|
||||
f, err = NewFactory(ctx, config, false)
|
||||
assert.Nil(err)
|
||||
f.CloseFactory(ctx)
|
||||
@ -134,8 +133,7 @@ func TestCheckVMConfig(t *testing.T) {
|
||||
err = checkVMConfig(config1, config2)
|
||||
assert.Nil(err)
|
||||
|
||||
testDir := fs.MockStorageRootPath()
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
|
||||
config1.HypervisorConfig = vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
@ -155,8 +153,7 @@ func TestCheckVMConfig(t *testing.T) {
|
||||
func TestFactoryGetVM(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testDir := fs.MockStorageRootPath()
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
|
||||
hyperConfig := vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
@ -321,8 +318,7 @@ func TestDeepCompare(t *testing.T) {
|
||||
config.VMConfig = vc.VMConfig{
|
||||
HypervisorType: vc.MockHypervisor,
|
||||
}
|
||||
testDir := fs.MockStorageRootPath()
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
|
||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
|
||||
)
|
||||
|
||||
@ -32,8 +31,7 @@ func TestTemplateFactory(t *testing.T) {
|
||||
|
||||
templateWaitForAgent = 1 * time.Microsecond
|
||||
|
||||
testDir := fs.MockStorageRootPath()
|
||||
defer fs.MockStorageDestroy()
|
||||
testDir := t.TempDir()
|
||||
|
||||
hyperConfig := vc.HypervisorConfig{
|
||||
KernelPath: testDir,
|
||||
|
@ -30,10 +30,6 @@ func MockRunVMStoragePath() string {
|
||||
return filepath.Join(MockStorageRootPath(), vmPathSuffix)
|
||||
}
|
||||
|
||||
func MockStorageDestroy() {
|
||||
os.RemoveAll(MockStorageRootPath())
|
||||
}
|
||||
|
||||
func MockFSInit() (persistapi.PersistDriver, error) {
|
||||
driver, err := Init()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user