mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-14 15:44:58 +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>
(cherry picked from commit 1719a8b491
)
Signed-off-by: Fabiano Fidêncio <fabiano.fidencio@intel.com>
This commit is contained in:
parent
c49084f303
commit
e1c4f57c35
@ -13,14 +13,12 @@ import (
|
|||||||
|
|
||||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
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/factory/direct"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTemplateFactory(t *testing.T) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir := fs.MockStorageRootPath()
|
testDir := t.TempDir()
|
||||||
defer fs.MockStorageDestroy()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
@ -12,14 +12,12 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
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) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir := fs.MockStorageRootPath()
|
testDir := t.TempDir()
|
||||||
defer fs.MockStorageDestroy()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
@ -12,7 +12,6 @@ import (
|
|||||||
|
|
||||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
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/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/pkg/mock"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -39,10 +38,10 @@ func TestNewFactory(t *testing.T) {
|
|||||||
_, err = NewFactory(ctx, config, false)
|
_, err = NewFactory(ctx, config, false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
defer fs.MockStorageDestroy()
|
testDir := t.TempDir()
|
||||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||||
KernelPath: fs.MockStorageRootPath(),
|
KernelPath: testDir,
|
||||||
ImagePath: fs.MockStorageRootPath(),
|
ImagePath: testDir,
|
||||||
}
|
}
|
||||||
|
|
||||||
// direct
|
// direct
|
||||||
@ -69,7 +68,7 @@ func TestNewFactory(t *testing.T) {
|
|||||||
defer hybridVSockTTRPCMock.Stop()
|
defer hybridVSockTTRPCMock.Stop()
|
||||||
|
|
||||||
config.Template = true
|
config.Template = true
|
||||||
config.TemplatePath = fs.MockStorageRootPath()
|
config.TemplatePath = testDir
|
||||||
f, err = NewFactory(ctx, config, false)
|
f, err = NewFactory(ctx, config, false)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
f.CloseFactory(ctx)
|
f.CloseFactory(ctx)
|
||||||
@ -134,8 +133,7 @@ func TestCheckVMConfig(t *testing.T) {
|
|||||||
err = checkVMConfig(config1, config2)
|
err = checkVMConfig(config1, config2)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
testDir := fs.MockStorageRootPath()
|
testDir := t.TempDir()
|
||||||
defer fs.MockStorageDestroy()
|
|
||||||
|
|
||||||
config1.HypervisorConfig = vc.HypervisorConfig{
|
config1.HypervisorConfig = vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
@ -155,8 +153,7 @@ func TestCheckVMConfig(t *testing.T) {
|
|||||||
func TestFactoryGetVM(t *testing.T) {
|
func TestFactoryGetVM(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir := fs.MockStorageRootPath()
|
testDir := t.TempDir()
|
||||||
defer fs.MockStorageDestroy()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
@ -321,8 +318,7 @@ func TestDeepCompare(t *testing.T) {
|
|||||||
config.VMConfig = vc.VMConfig{
|
config.VMConfig = vc.VMConfig{
|
||||||
HypervisorType: vc.MockHypervisor,
|
HypervisorType: vc.MockHypervisor,
|
||||||
}
|
}
|
||||||
testDir := fs.MockStorageRootPath()
|
testDir := t.TempDir()
|
||||||
defer fs.MockStorageDestroy()
|
|
||||||
|
|
||||||
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
config.VMConfig.HypervisorConfig = vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
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"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -32,8 +31,7 @@ func TestTemplateFactory(t *testing.T) {
|
|||||||
|
|
||||||
templateWaitForAgent = 1 * time.Microsecond
|
templateWaitForAgent = 1 * time.Microsecond
|
||||||
|
|
||||||
testDir := fs.MockStorageRootPath()
|
testDir := t.TempDir()
|
||||||
defer fs.MockStorageDestroy()
|
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
|
@ -30,10 +30,6 @@ func MockRunVMStoragePath() string {
|
|||||||
return filepath.Join(MockStorageRootPath(), vmPathSuffix)
|
return filepath.Join(MockStorageRootPath(), vmPathSuffix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MockStorageDestroy() {
|
|
||||||
os.RemoveAll(MockStorageRootPath())
|
|
||||||
}
|
|
||||||
|
|
||||||
func MockFSInit() (persistapi.PersistDriver, error) {
|
func MockFSInit() (persistapi.PersistDriver, error) {
|
||||||
driver, err := Init()
|
driver, err := Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user