mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 01:02:33 +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",
|
"nested": "Y",
|
||||||
"unrestricted_guest": "Y",
|
"unrestricted_guest": "Y",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,6 +256,7 @@ func TestCheckCheckKernelModulesNoUnrestrictedGuest(t *testing.T) {
|
|||||||
"nested": "Y",
|
"nested": "Y",
|
||||||
"unrestricted_guest": "Y",
|
"unrestricted_guest": "Y",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -502,6 +502,7 @@ func TestCheckCheckKernelModules(t *testing.T) {
|
|||||||
"foo": {
|
"foo": {
|
||||||
desc: "desc",
|
desc: "desc",
|
||||||
parameters: map[string]string{},
|
parameters: map[string]string{},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
desc: "desc",
|
desc: "desc",
|
||||||
@ -511,6 +512,7 @@ func TestCheckCheckKernelModules(t *testing.T) {
|
|||||||
"param3": "a",
|
"param3": "a",
|
||||||
"param4": ".",
|
"param4": ".",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -570,6 +572,7 @@ func TestCheckCheckKernelModulesUnreadableFile(t *testing.T) {
|
|||||||
parameters: map[string]string{
|
parameters: map[string]string{
|
||||||
"param1": "wibble",
|
"param1": "wibble",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,6 +620,7 @@ func TestCheckCheckKernelModulesInvalidFileContents(t *testing.T) {
|
|||||||
parameters: map[string]string{
|
parameters: map[string]string{
|
||||||
"param1": "wibble",
|
"param1": "wibble",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -713,6 +717,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
|||||||
"foo": {
|
"foo": {
|
||||||
desc: "desc",
|
desc: "desc",
|
||||||
parameters: map[string]string{},
|
parameters: map[string]string{},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
desc: "desc",
|
desc: "desc",
|
||||||
@ -720,6 +725,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
|||||||
"param1": "hello",
|
"param1": "hello",
|
||||||
"param2": "world",
|
"param2": "world",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -731,6 +737,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
|||||||
parameters: map[string]string{
|
parameters: map[string]string{
|
||||||
"param1": "moo",
|
"param1": "moo",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,6 +747,7 @@ func TestCheckKernelParamHandler(t *testing.T) {
|
|||||||
parameters: map[string]string{
|
parameters: map[string]string{
|
||||||
"param1": "bar",
|
"param1": "bar",
|
||||||
},
|
},
|
||||||
|
required: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,13 +719,10 @@ func TestMinimalRuntimeConfigWithVsock(t *testing.T) {
|
|||||||
[agent.kata]
|
[agent.kata]
|
||||||
`
|
`
|
||||||
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
||||||
orgVSockDevicePath := utils.VSockDevicePath
|
|
||||||
defer func() {
|
defer func() {
|
||||||
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
|
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||||
utils.VSockDevicePath = orgVSockDevicePath
|
|
||||||
}()
|
}()
|
||||||
utils.VHostVSockDevicePath = "/dev/null"
|
utils.VHostVSockDevicePath = "/dev/null"
|
||||||
utils.VSockDevicePath = "/dev/null"
|
|
||||||
|
|
||||||
configPath := path.Join(dir, "runtime.toml")
|
configPath := path.Join(dir, "runtime.toml")
|
||||||
err = createConfig(configPath, runtimeMinimalConfig)
|
err = createConfig(configPath, runtimeMinimalConfig)
|
||||||
@ -765,13 +762,10 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
|
|||||||
disableBlock := true
|
disableBlock := true
|
||||||
enableIOThreads := true
|
enableIOThreads := true
|
||||||
hotplugVFIOOnRootBus := true
|
hotplugVFIOOnRootBus := true
|
||||||
orgVSockDevicePath := utils.VSockDevicePath
|
|
||||||
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
||||||
defer func() {
|
defer func() {
|
||||||
utils.VSockDevicePath = orgVSockDevicePath
|
|
||||||
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
|
utils.VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||||
}()
|
}()
|
||||||
utils.VSockDevicePath = "/dev/abc/xyz"
|
|
||||||
utils.VHostVSockDevicePath = "/dev/abc/xyz"
|
utils.VHostVSockDevicePath = "/dev/abc/xyz"
|
||||||
|
|
||||||
hypervisor := hypervisor{
|
hypervisor := hypervisor{
|
||||||
@ -808,7 +802,6 @@ func TestNewQemuHypervisorConfig(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.VSockDevicePath = "/dev/null"
|
|
||||||
utils.VHostVSockDevicePath = "/dev/null"
|
utils.VHostVSockDevicePath = "/dev/null"
|
||||||
|
|
||||||
// all paths exist now
|
// all paths exist now
|
||||||
|
@ -298,25 +298,14 @@ func TestBuildSocketPath(t *testing.T) {
|
|||||||
func TestSupportsVsocks(t *testing.T) {
|
func TestSupportsVsocks(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
orgVSockDevicePath := VSockDevicePath
|
|
||||||
orgVHostVSockDevicePath := VHostVSockDevicePath
|
orgVHostVSockDevicePath := VHostVSockDevicePath
|
||||||
defer func() {
|
defer func() {
|
||||||
VSockDevicePath = orgVSockDevicePath
|
|
||||||
VHostVSockDevicePath = orgVHostVSockDevicePath
|
VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||||
}()
|
}()
|
||||||
|
|
||||||
VSockDevicePath = "/abc/xyz/123"
|
|
||||||
VHostVSockDevicePath = "/abc/xyz/123"
|
VHostVSockDevicePath = "/abc/xyz/123"
|
||||||
assert.False(SupportsVsocks())
|
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")
|
vHostVSockFile, err := ioutil.TempFile("", "vhost-vsock")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
defer os.Remove(vHostVSockFile.Name())
|
defer os.Remove(vHostVSockFile.Name())
|
||||||
|
Loading…
Reference in New Issue
Block a user