mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 22:43:05 +00:00
virtcontainers: add unit tests for container.go
Fixes: #268 Signed-off-by: Amulyam24 <amulmek1@in.ibm.com>
This commit is contained in:
parent
9bbaa66f39
commit
d865c80986
@ -636,3 +636,71 @@ func TestMountSharedDirMounts(t *testing.T) {
|
|||||||
assert.Equal(updatedMounts[mountDestination].Source, expectedStorageDest)
|
assert.Equal(updatedMounts[mountDestination].Source, expectedStorageDest)
|
||||||
assert.Equal(updatedMounts[mountDestination].Destination, mountDestination)
|
assert.Equal(updatedMounts[mountDestination].Destination, mountDestination)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetContainerId(t *testing.T) {
|
||||||
|
containerIDs := []string{"abc", "foobar", "123"}
|
||||||
|
containers := [3]*Container{}
|
||||||
|
|
||||||
|
for i, id := range containerIDs {
|
||||||
|
c := &Container{id: id}
|
||||||
|
containers[i] = c
|
||||||
|
}
|
||||||
|
|
||||||
|
for id, container := range containers {
|
||||||
|
assert.Equal(t, containerIDs[id], container.ID())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContainerProcess(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
expectedProcess := Process{
|
||||||
|
Token: "foobar",
|
||||||
|
Pid: 123,
|
||||||
|
}
|
||||||
|
container := &Container{
|
||||||
|
process: expectedProcess,
|
||||||
|
}
|
||||||
|
|
||||||
|
process := container.Process()
|
||||||
|
assert.Exactly(process, expectedProcess)
|
||||||
|
|
||||||
|
token := container.GetToken()
|
||||||
|
assert.Exactly(token, "foobar")
|
||||||
|
|
||||||
|
pid := container.GetPid()
|
||||||
|
assert.Exactly(pid, 123)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigValid(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
//no config
|
||||||
|
config := ContainerConfig{}
|
||||||
|
result := config.valid()
|
||||||
|
assert.False(result)
|
||||||
|
|
||||||
|
//no container ID
|
||||||
|
config = newTestContainerConfigNoop("")
|
||||||
|
result = config.valid()
|
||||||
|
assert.False(result)
|
||||||
|
|
||||||
|
config = newTestContainerConfigNoop("foobar")
|
||||||
|
result = config.valid()
|
||||||
|
assert.True(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestStoreContainer(t *testing.T) {
|
||||||
|
hConfig := newHypervisorConfig(nil, nil)
|
||||||
|
sandbox, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NetworkConfig{}, nil, nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
container := &Container{
|
||||||
|
sandbox: sandbox,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = container.storeContainer()
|
||||||
|
assert.Nil(t, err, "store container should succeed")
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user