runtime: Add unit tests

Add unit tests for the rootfs patch

Signed-off-by: Ganesh Maharaj Mahalingam <ganesh.mahalingam@intel.com>
This commit is contained in:
Ganesh Maharaj Mahalingam 2019-03-07 15:57:06 -08:00
parent 27a92f94c8
commit 45fe8700b8

View File

@ -275,6 +275,57 @@ func TestContainerAddDriveDir(t *testing.T) {
} }
} }
func TestContainerRootfsPath(t *testing.T) {
testRawFile, loopDev, fakeRootfs, err := testSetupFakeRootfs(t)
defer cleanupFakeRootfsSetup(testRawFile, loopDev, fakeRootfs)
assert.Nil(t, err)
truecheckstoragedriver := checkStorageDriver
checkStorageDriver = func(major, minor int) (bool, error) {
return true, nil
}
defer func() {
checkStorageDriver = truecheckstoragedriver
}()
sandbox := &Sandbox{
ctx: context.Background(),
id: "rootfstestsandbox",
agent: &noopAgent{},
hypervisor: &mockHypervisor{},
config: &SandboxConfig{
HypervisorConfig: HypervisorConfig{
DisableBlockDeviceUse: false,
},
},
}
vcstore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id)
sandbox.store = vcstore
assert.Nil(t, err)
container := Container{
id: "rootfstestcontainerid",
sandbox: sandbox,
rootFs: fakeRootfs,
rootfsSuffix: "rootfs",
}
cvcstore, err := store.NewVCContainerStore(context.Background(),
sandbox.id,
container.id)
assert.Nil(t, err)
container.store = cvcstore
container.hotplugDrive()
assert.Empty(t, container.rootfsSuffix)
// Reset the value to test the other case
container.rootFs = fakeRootfs + "/rootfs"
container.rootfsSuffix = "rootfs"
container.hotplugDrive()
assert.Equal(t, container.rootfsSuffix, "rootfs")
}
func TestCheckSandboxRunningEmptyCmdFailure(t *testing.T) { func TestCheckSandboxRunningEmptyCmdFailure(t *testing.T) {
c := &Container{} c := &Container{}
err := c.checkSandboxRunning("") err := c.checkSandboxRunning("")