mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 00:37:24 +00:00
unit-test: refine unit test
We should refine unit test which involves func SupportsVsocks and newly reconstructed struct kernelModule. Fixes: #1512 Signed-off-by: Penny Zheng <penny.zheng@arm.com>
This commit is contained in:
parent
9b23d4f143
commit
bce0d604e1
@ -171,6 +171,7 @@ func TestCheckCheckKernelModulesNoNesting(t *testing.T) {
|
||||
"nested": "Y",
|
||||
"unrestricted_guest": "Y",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -255,6 +256,7 @@ func TestCheckCheckKernelModulesNoUnrestrictedGuest(t *testing.T) {
|
||||
"nested": "Y",
|
||||
"unrestricted_guest": "Y",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -502,6 +502,7 @@ func TestCheckCheckKernelModules(t *testing.T) {
|
||||
"foo": {
|
||||
desc: "desc",
|
||||
parameters: map[string]string{},
|
||||
required: true,
|
||||
},
|
||||
"bar": {
|
||||
desc: "desc",
|
||||
@ -511,6 +512,7 @@ func TestCheckCheckKernelModules(t *testing.T) {
|
||||
"param3": "a",
|
||||
"param4": ".",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -570,6 +572,7 @@ func TestCheckCheckKernelModulesUnreadableFile(t *testing.T) {
|
||||
parameters: map[string]string{
|
||||
"param1": "wibble",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -617,6 +620,7 @@ func TestCheckCheckKernelModulesInvalidFileContents(t *testing.T) {
|
||||
parameters: map[string]string{
|
||||
"param1": "wibble",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -713,6 +717,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
||||
"foo": {
|
||||
desc: "desc",
|
||||
parameters: map[string]string{},
|
||||
required: true,
|
||||
},
|
||||
"bar": {
|
||||
desc: "desc",
|
||||
@ -720,6 +725,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
||||
"param1": "hello",
|
||||
"param2": "world",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -731,6 +737,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
||||
parameters: map[string]string{
|
||||
"param1": "moo",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
@ -740,6 +747,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
||||
parameters: map[string]string{
|
||||
"param1": "bar",
|
||||
},
|
||||
required: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -719,13 +719,10 @@ func TestMinimalRuntimeConfigWithVsock(t *testing.T) {
|
||||
[agent.kata]
|
||||
`
|
||||
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
||||
orgVSockDevicePath := utils.VSockDevicePath
|
||||
defer func() {
|
||||
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||
utils.VSockDevicePath = orgVSockDevicePath
|
||||
}()
|
||||
utils.VHostVSockDevicePath = "/dev/null"
|
||||
utils.VSockDevicePath = "/dev/null"
|
||||
|
||||
configPath := path.Join(dir, "runtime.toml")
|
||||
err = createConfig(configPath, runtimeMinimalConfig)
|
||||
@ -765,13 +762,10 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
|
||||
disableBlock := true
|
||||
enableIOThreads := true
|
||||
hotplugVFIOOnRootBus := true
|
||||
orgVSockDevicePath := utils.VSockDevicePath
|
||||
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
||||
defer func() {
|
||||
utils.VSockDevicePath = orgVSockDevicePath
|
||||
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||
}()
|
||||
utils.VSockDevicePath = "/dev/abc/xyz"
|
||||
utils.VHostVSockDevicePath = "/dev/abc/xyz"
|
||||
|
||||
hypervisor := hypervisor{
|
||||
@ -808,7 +802,6 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
utils.VSockDevicePath = "/dev/null"
|
||||
utils.VHostVSockDevicePath = "/dev/null"
|
||||
|
||||
// all paths exist now
|
||||
|
@ -298,25 +298,14 @@ func TestBuildSocketPath(t *testing.T) {
|
||||
func TestSupportsVsocks(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
orgVSockDevicePath := VSockDevicePath
|
||||
orgVHostVSockDevicePath := VHostVSockDevicePath
|
||||
defer func() {
|
||||
VSockDevicePath = orgVSockDevicePath
|
||||
VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||
}()
|
||||
|
||||
VSockDevicePath = "/abc/xyz/123"
|
||||
VHostVSockDevicePath = "/abc/xyz/123"
|
||||
assert.False(SupportsVsocks())
|
||||
|
||||
vSockDeviceFile, err := ioutil.TempFile("", "vsock")
|
||||
assert.NoError(err)
|
||||
defer os.Remove(vSockDeviceFile.Name())
|
||||
defer vSockDeviceFile.Close()
|
||||
VSockDevicePath = vSockDeviceFile.Name()
|
||||
|
||||
assert.False(SupportsVsocks())
|
||||
|
||||
vHostVSockFile, err := ioutil.TempFile("", "vhost-vsock")
|
||||
assert.NoError(err)
|
||||
defer os.Remove(vHostVSockFile.Name())
|
||||
|
Loading…
Reference in New Issue
Block a user