mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-28 08:17:37 +00:00
kata_agent: Add unit tests
[ port from runtime commit 6be76fcd07a3d74ca5521af2feaf966dd6f2c344 ] This patch adds the unit test for 'handleDeviceBlockVolume()'. Signed-off-by: Bo Chen <chen.bo@intel.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
6da49a0418
commit
653df674d3
@ -39,8 +39,13 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
testKataProxyURLTempl = "unix://%s/kata-proxy-test.sock"
|
testKataProxyURLTempl = "unix://%s/kata-proxy-test.sock"
|
||||||
|
testBlkDriveFormat = "testBlkDriveFormat"
|
||||||
testBlockDeviceCtrPath = "testBlockDeviceCtrPath"
|
testBlockDeviceCtrPath = "testBlockDeviceCtrPath"
|
||||||
|
testDevNo = "testDevNo"
|
||||||
|
testNvdimmID = "testNvdimmID"
|
||||||
testPCIAddr = "04/02"
|
testPCIAddr = "04/02"
|
||||||
|
testSCSIAddr = "testSCSIAddr"
|
||||||
|
testVirtPath = "testVirtPath"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testGenerateKataProxySockDir() (string, error) {
|
func testGenerateKataProxySockDir() (string, error) {
|
||||||
@ -398,6 +403,110 @@ func TestHandleLocalStorage(t *testing.T) {
|
|||||||
assert.Equal(t, localMountPoint, expected)
|
assert.Equal(t, localMountPoint, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHandleDeviceBlockVolume(t *testing.T) {
|
||||||
|
k := kataAgent{}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
BlockDeviceDriver string
|
||||||
|
inputDev *drivers.BlockDevice
|
||||||
|
resultVol *pb.Storage
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
inputDev: &drivers.BlockDevice{
|
||||||
|
BlockDrive: &config.BlockDrive{
|
||||||
|
Pmem: true,
|
||||||
|
NvdimmID: testNvdimmID,
|
||||||
|
Format: testBlkDriveFormat,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resultVol: &pb.Storage{
|
||||||
|
Driver: kataNvdimmDevType,
|
||||||
|
Source: fmt.Sprintf("/dev/pmem%s", testNvdimmID),
|
||||||
|
Fstype: testBlkDriveFormat,
|
||||||
|
Options: []string{"dax"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BlockDeviceDriver: config.VirtioBlockCCW,
|
||||||
|
inputDev: &drivers.BlockDevice{
|
||||||
|
BlockDrive: &config.BlockDrive{
|
||||||
|
DevNo: testDevNo,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resultVol: &pb.Storage{
|
||||||
|
Driver: kataBlkCCWDevType,
|
||||||
|
Source: testDevNo,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BlockDeviceDriver: config.VirtioBlock,
|
||||||
|
inputDev: &drivers.BlockDevice{
|
||||||
|
BlockDrive: &config.BlockDrive{
|
||||||
|
PCIAddr: testPCIAddr,
|
||||||
|
VirtPath: testVirtPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resultVol: &pb.Storage{
|
||||||
|
Driver: kataBlkDevType,
|
||||||
|
Source: testPCIAddr,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BlockDeviceDriver: config.VirtioBlock,
|
||||||
|
inputDev: &drivers.BlockDevice{
|
||||||
|
BlockDrive: &config.BlockDrive{
|
||||||
|
VirtPath: testVirtPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resultVol: &pb.Storage{
|
||||||
|
Driver: kataBlkDevType,
|
||||||
|
Source: testVirtPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BlockDeviceDriver: config.VirtioMmio,
|
||||||
|
inputDev: &drivers.BlockDevice{
|
||||||
|
BlockDrive: &config.BlockDrive{
|
||||||
|
VirtPath: testVirtPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resultVol: &pb.Storage{
|
||||||
|
Driver: kataMmioBlkDevType,
|
||||||
|
Source: testVirtPath,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
BlockDeviceDriver: config.VirtioSCSI,
|
||||||
|
inputDev: &drivers.BlockDevice{
|
||||||
|
BlockDrive: &config.BlockDrive{
|
||||||
|
SCSIAddr: testSCSIAddr,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
resultVol: &pb.Storage{
|
||||||
|
Driver: kataSCSIDevType,
|
||||||
|
Source: testSCSIAddr,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
c := &Container{
|
||||||
|
sandbox: &Sandbox{
|
||||||
|
config: &SandboxConfig{
|
||||||
|
HypervisorConfig: HypervisorConfig{
|
||||||
|
BlockDeviceDriver: test.BlockDeviceDriver,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
vol, _ := k.handleDeviceBlockVolume(c, test.inputDev)
|
||||||
|
assert.True(t, reflect.DeepEqual(vol, test.resultVol),
|
||||||
|
"Volume didn't match: got %+v, expecting %+v",
|
||||||
|
vol, test.resultVol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestHandleBlockVolume(t *testing.T) {
|
func TestHandleBlockVolume(t *testing.T) {
|
||||||
k := kataAgent{}
|
k := kataAgent{}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user