Files
kata-containers/virtcontainers/factory/cache/cache_test.go
Wei Zhang 4a298cb9b7 persist: address comments
Address some comments.

Signed-off-by: Wei Zhang <weizhang555@gmail.com>
2020-01-08 10:03:56 +08:00

71 lines
1.4 KiB
Go

// Copyright (c) 2018 HyperHQ Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package cache
import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
vc "github.com/kata-containers/runtime/virtcontainers"
"github.com/kata-containers/runtime/virtcontainers/factory/direct"
"github.com/kata-containers/runtime/virtcontainers/persist/fs"
)
var rootPathSave = fs.StorageRootPath()
func TestTemplateFactory(t *testing.T) {
assert := assert.New(t)
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
fs.TestSetStorageRootPath(filepath.Join(testDir, "vc"))
defer func() {
os.RemoveAll(testDir)
fs.TestSetStorageRootPath(rootPathSave)
}()
hyperConfig := vc.HypervisorConfig{
KernelPath: testDir,
ImagePath: testDir,
}
vmConfig := vc.VMConfig{
HypervisorType: vc.MockHypervisor,
AgentType: vc.NoopAgentType,
ProxyType: vc.NoopProxyType,
HypervisorConfig: hyperConfig,
}
ctx := context.Background()
runPathSave := fs.RunStoragePath()
fs.TestSetRunStoragePath(filepath.Join(testDir, "vc", "run"))
// allow the tests to run without affecting the host system.
defer func() {
fs.TestSetRunStoragePath(runPathSave)
}()
// New
f := New(ctx, 2, direct.New(ctx, vmConfig))
// Config
assert.Equal(f.Config(), vmConfig)
// GetBaseVM
vm, err := f.GetBaseVM(ctx, vmConfig)
assert.Nil(err)
err = vm.Stop()
assert.Nil(err)
// CloseFactory
f.CloseFactory(ctx)
}