mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 09:13:29 +00:00
test: fix unit test
For experimental features, state.json won't be updated, so modify some unit test to skip. Signed-off-by: Wei Zhang <zhangwei555@huawei.com>
This commit is contained in:
parent
e40dcb9376
commit
02f21228dd
@ -57,6 +57,7 @@ type ProxyState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SandboxState contains state information of sandbox
|
// SandboxState contains state information of sandbox
|
||||||
|
// nolint: maligned
|
||||||
type SandboxState struct {
|
type SandboxState struct {
|
||||||
// PersistVersion of persist data format, can be used for keeping compatibility later
|
// PersistVersion of persist data format, can be used for keeping compatibility later
|
||||||
PersistVersion uint
|
PersistVersion uint
|
||||||
@ -64,20 +65,20 @@ type SandboxState struct {
|
|||||||
// State is sandbox running status
|
// State is sandbox running status
|
||||||
State string
|
State string
|
||||||
|
|
||||||
// SandboxContainer specifies which container is used to start the sandbox/vm
|
// GuestMemoryBlockSizeMB is the size of memory block of guestos
|
||||||
SandboxContainer string
|
GuestMemoryBlockSizeMB uint32
|
||||||
|
|
||||||
// GuestMemoryHotplugProbe determines whether guest kernel supports memory hotplug probe interface
|
// GuestMemoryHotplugProbe determines whether guest kernel supports memory hotplug probe interface
|
||||||
GuestMemoryHotplugProbe bool
|
GuestMemoryHotplugProbe bool
|
||||||
|
|
||||||
|
// SandboxContainer specifies which container is used to start the sandbox/vm
|
||||||
|
SandboxContainer string
|
||||||
|
|
||||||
// CgroupPath is the cgroup hierarchy where sandbox's processes
|
// CgroupPath is the cgroup hierarchy where sandbox's processes
|
||||||
// including the hypervisor are placed.
|
// including the hypervisor are placed.
|
||||||
// FIXME: sandbox can reuse "SandboxContainer"'s CgroupPath so we can remove this field.
|
// FIXME: sandbox can reuse "SandboxContainer"'s CgroupPath so we can remove this field.
|
||||||
CgroupPath string
|
CgroupPath string
|
||||||
|
|
||||||
// GuestMemoryBlockSizeMB is the size of memory block of guestos
|
|
||||||
GuestMemoryBlockSizeMB uint32
|
|
||||||
|
|
||||||
// Devices plugged to sandbox(hypervisor)
|
// Devices plugged to sandbox(hypervisor)
|
||||||
Devices []DeviceState
|
Devices []DeviceState
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ func TestSandboxRestore(t *testing.T) {
|
|||||||
assert.Equal(t, sandbox.state.State, types.StateString(""))
|
assert.Equal(t, sandbox.state.State, types.StateString(""))
|
||||||
assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(0))
|
assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(0))
|
||||||
assert.Equal(t, sandbox.state.BlockIndex, 0)
|
assert.Equal(t, sandbox.state.BlockIndex, 0)
|
||||||
assert.Equal(t, sandbox.state.Pid, 0)
|
|
||||||
|
|
||||||
// register callback function
|
// register callback function
|
||||||
sandbox.stateSaveCallback()
|
sandbox.stateSaveCallback()
|
||||||
@ -105,20 +104,18 @@ func TestSandboxRestore(t *testing.T) {
|
|||||||
sandbox.state.State = types.StateString("running")
|
sandbox.state.State = types.StateString("running")
|
||||||
sandbox.state.GuestMemoryBlockSizeMB = uint32(1024)
|
sandbox.state.GuestMemoryBlockSizeMB = uint32(1024)
|
||||||
sandbox.state.BlockIndex = 2
|
sandbox.state.BlockIndex = 2
|
||||||
sandbox.state.Pid = 10000
|
|
||||||
// flush data to disk
|
// flush data to disk
|
||||||
err = sandbox.newStore.ToDisk()
|
err = sandbox.newStore.ToDisk()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
||||||
// empty the sandbox
|
// empty the sandbox
|
||||||
sandbox.state = types.State{}
|
sandbox.state = types.SandboxState{}
|
||||||
|
|
||||||
// restore data from disk
|
// restore data from disk
|
||||||
err = sandbox.Restore()
|
err = sandbox.Restore()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, sandbox.state.State, types.StateString("running"))
|
assert.Equal(t, sandbox.state.State, types.StateString("running"))
|
||||||
assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(1024))
|
assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(1024))
|
||||||
assert.Equal(t, sandbox.state.Pid, 10000)
|
|
||||||
// require hvStateSaveCallback to make it savable
|
// require hvStateSaveCallback to make it savable
|
||||||
assert.Equal(t, sandbox.state.BlockIndex, 0)
|
assert.Equal(t, sandbox.state.BlockIndex, 0)
|
||||||
|
|
||||||
@ -131,7 +128,6 @@ func TestSandboxRestore(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, sandbox.state.State, types.StateString("running"))
|
assert.Equal(t, sandbox.state.State, types.StateString("running"))
|
||||||
assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(1024))
|
assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(1024))
|
||||||
assert.Equal(t, sandbox.state.Pid, 10000)
|
|
||||||
assert.Equal(t, sandbox.state.BlockIndex, 2)
|
assert.Equal(t, sandbox.state.BlockIndex, 2)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -762,15 +762,11 @@ func TestContainerStateSetFstype(t *testing.T) {
|
|||||||
|
|
||||||
hConfig := newHypervisorConfig(nil, nil)
|
hConfig := newHypervisorConfig(nil, nil)
|
||||||
sandbox, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NetworkConfig{}, containers, nil)
|
sandbox, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NetworkConfig{}, containers, nil)
|
||||||
if err != nil {
|
assert.Nil(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
vcStore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
|
vcStore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
|
||||||
if err != nil {
|
assert.Nil(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
sandbox.store = vcStore
|
sandbox.store = vcStore
|
||||||
|
|
||||||
c := sandbox.GetContainer("100")
|
c := sandbox.GetContainer("100")
|
||||||
@ -827,6 +823,11 @@ func TestContainerStateSetFstype(t *testing.T) {
|
|||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// experimental features doesn't write state.json
|
||||||
|
if sandbox.supportNewStore() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
var res types.ContainerState
|
var res types.ContainerState
|
||||||
err = json.Unmarshal([]byte(string(fileData)), &res)
|
err = json.Unmarshal([]byte(string(fileData)), &res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user