mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-18 07:58:36 +00:00
commit
3ea3d3201b
@ -160,7 +160,9 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
// Make sure we have the opportunity to flush the coverage report to disk when
|
// Make sure we have the opportunity to flush the coverage report to disk when
|
||||||
// terminating the process.
|
// terminating the process.
|
||||||
atexit(cover.FlushProfiles)
|
defer func() {
|
||||||
|
cover.FlushProfiles()
|
||||||
|
}()
|
||||||
|
|
||||||
// If the test binary name is kata-runtime.coverage, we've are being asked to
|
// If the test binary name is kata-runtime.coverage, we've are being asked to
|
||||||
// run the coverage-instrumented kata-runtime.
|
// run the coverage-instrumented kata-runtime.
|
||||||
|
@ -8,17 +8,26 @@ package direct
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
|
"github.com/kata-containers/runtime/virtcontainers/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTemplateFactory(t *testing.T) {
|
func TestTemplateFactory(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
testDir, err := ioutil.TempDir("", "vmfactory-tmp-")
|
||||||
|
assert.Nil(err)
|
||||||
|
store.VCStorePrefix = testDir
|
||||||
|
defer func() {
|
||||||
|
os.RemoveAll(testDir)
|
||||||
|
store.VCStorePrefix = ""
|
||||||
|
}()
|
||||||
|
|
||||||
hyperConfig := vc.HypervisorConfig{
|
hyperConfig := vc.HypervisorConfig{
|
||||||
KernelPath: testDir,
|
KernelPath: testDir,
|
||||||
ImagePath: testDir,
|
ImagePath: testDir,
|
||||||
|
@ -7,6 +7,7 @@ package fs
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -32,6 +33,13 @@ func TestFsLock(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, fs)
|
assert.NotNil(t, fs)
|
||||||
|
|
||||||
|
testDir, err := ioutil.TempDir("", "fs-tmp-")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
TestSetRunStoragePath(testDir)
|
||||||
|
defer func() {
|
||||||
|
os.RemoveAll(testDir)
|
||||||
|
}()
|
||||||
|
|
||||||
fs.sandboxState.SandboxContainer = "test-fs-driver"
|
fs.sandboxState.SandboxContainer = "test-fs-driver"
|
||||||
sandboxDir, err := fs.sandboxDir()
|
sandboxDir, err := fs.sandboxDir()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
@ -51,6 +59,13 @@ func TestFsDriver(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, fs)
|
assert.NotNil(t, fs)
|
||||||
|
|
||||||
|
testDir, err := ioutil.TempDir("", "fs-tmp-")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
TestSetRunStoragePath(testDir)
|
||||||
|
defer func() {
|
||||||
|
os.RemoveAll(testDir)
|
||||||
|
}()
|
||||||
|
|
||||||
ss := persistapi.SandboxState{}
|
ss := persistapi.SandboxState{}
|
||||||
cs := make(map[string]persistapi.ContainerState)
|
cs := make(map[string]persistapi.ContainerState)
|
||||||
// missing sandbox container id
|
// missing sandbox container id
|
||||||
|
@ -18,10 +18,14 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
ktu "github.com/kata-containers/runtime/pkg/katatestutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const testPID = 12345
|
const testPID = 12345
|
||||||
|
|
||||||
|
var tu = ktu.NewTestConstraint(true)
|
||||||
|
|
||||||
func TestGetNSPathFromPID(t *testing.T) {
|
func TestGetNSPathFromPID(t *testing.T) {
|
||||||
for nsType := range CloneFlagsTable {
|
for nsType := range CloneFlagsTable {
|
||||||
expectedPath := fmt.Sprintf("/proc/%d/ns/%s", testPID, nsType)
|
expectedPath := fmt.Sprintf("/proc/%d/ns/%s", testPID, nsType)
|
||||||
@ -165,6 +169,9 @@ func TestNsEnterEmptyNamespaceListSuccess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNsEnterSuccessful(t *testing.T) {
|
func TestNsEnterSuccessful(t *testing.T) {
|
||||||
|
if tu.NotValid(ktu.NeedRoot()) {
|
||||||
|
t.Skip(ktu.TestDisabledNeedRoot)
|
||||||
|
}
|
||||||
nsList := supportedNamespaces()
|
nsList := supportedNamespaces()
|
||||||
sleepDuration := 60
|
sleepDuration := 60
|
||||||
|
|
||||||
|
@ -20,7 +20,11 @@ type TestNoopStructure struct {
|
|||||||
Field2 string
|
Field2 string
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootPath = "/tmp/root1/"
|
var rootPath = func() string {
|
||||||
|
dir, _ := ioutil.TempDir("", "")
|
||||||
|
return dir
|
||||||
|
}()
|
||||||
|
|
||||||
var expectedFilesystemData = "{\"Field1\":\"value1\",\"Field2\":\"value2\"}"
|
var expectedFilesystemData = "{\"Field1\":\"value1\",\"Field2\":\"value2\"}"
|
||||||
|
|
||||||
func TestStoreFilesystemStore(t *testing.T) {
|
func TestStoreFilesystemStore(t *testing.T) {
|
||||||
|
@ -23,14 +23,17 @@ var sandboxDirState = ""
|
|||||||
var sandboxDirLock = ""
|
var sandboxDirLock = ""
|
||||||
var sandboxFileState = ""
|
var sandboxFileState = ""
|
||||||
var sandboxFileLock = ""
|
var sandboxFileLock = ""
|
||||||
var storeRoot = "file:///tmp/root1/"
|
var storeRoot, storeRootDir = func() (string, string) {
|
||||||
|
dir, _ := ioutil.TempDir("", "")
|
||||||
|
return "file://" + dir, dir
|
||||||
|
}()
|
||||||
|
|
||||||
func TestNewStore(t *testing.T) {
|
func TestNewStore(t *testing.T) {
|
||||||
s, err := New(context.Background(), storeRoot)
|
s, err := New(context.Background(), storeRoot)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, s.scheme, "file")
|
assert.Equal(t, s.scheme, "file")
|
||||||
assert.Equal(t, s.host, "")
|
assert.Equal(t, s.host, "")
|
||||||
assert.Equal(t, s.path, "/tmp/root1/")
|
assert.Equal(t, s.path, storeRootDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteStore(t *testing.T) {
|
func TestDeleteStore(t *testing.T) {
|
||||||
|
@ -57,19 +57,28 @@ var testVirtiofsdPath = ""
|
|||||||
var testHyperstartCtlSocket = ""
|
var testHyperstartCtlSocket = ""
|
||||||
var testHyperstartTtySocket = ""
|
var testHyperstartTtySocket = ""
|
||||||
|
|
||||||
|
var savedRunVMStoragePathFunc func() string
|
||||||
|
|
||||||
// cleanUp Removes any stale sandbox/container state that can affect
|
// cleanUp Removes any stale sandbox/container state that can affect
|
||||||
// the next test to run.
|
// the next test to run.
|
||||||
func cleanUp() {
|
func cleanUp() {
|
||||||
globalSandboxList.removeSandbox(testSandboxID)
|
globalSandboxList.removeSandbox(testSandboxID)
|
||||||
store.DeleteAll()
|
store.DeleteAll()
|
||||||
os.RemoveAll(testDir)
|
os.RemoveAll(testDir)
|
||||||
os.MkdirAll(testDir, store.DirMode)
|
store.VCStorePrefix = ""
|
||||||
|
store.RunVMStoragePath = savedRunVMStoragePathFunc
|
||||||
|
|
||||||
setup()
|
setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func setup() {
|
func setup() {
|
||||||
os.Mkdir(filepath.Join(testDir, testBundle), store.DirMode)
|
store.VCStorePrefix = testDir
|
||||||
|
savedRunVMStoragePathFunc = store.RunVMStoragePath
|
||||||
|
store.RunVMStoragePath = func() string {
|
||||||
|
return filepath.Join("testDir", "vm")
|
||||||
|
}
|
||||||
|
os.MkdirAll(store.RunVMStoragePath(), store.DirMode)
|
||||||
|
os.MkdirAll(filepath.Join(testDir, testBundle), store.DirMode)
|
||||||
|
|
||||||
for _, filename := range []string{testQemuKernelPath, testQemuInitrdPath, testQemuImagePath, testQemuPath} {
|
for _, filename := range []string{testQemuKernelPath, testQemuInitrdPath, testQemuImagePath, testQemuPath} {
|
||||||
_, err := os.Create(filename)
|
_, err := os.Create(filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user