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