mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-01 08:56:32 +00:00
Merge pull request #256 from sboeuf/improve_container_search_CLI
cli: Optimize container research
This commit is contained in:
@@ -239,6 +239,10 @@ func createSandbox(ociSpec oci.CompatOCISpec, runtimeConfig oci.RuntimeConfig,
|
|||||||
return vc.Process{}, fmt.Errorf("BUG: Container list from sandbox is wrong, expecting only one container, found %d containers", len(containers))
|
return vc.Process{}, fmt.Errorf("BUG: Container list from sandbox is wrong, expecting only one container, found %d containers", len(containers))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := addContainerIDMapping(containerID, sandbox.ID()); err != nil {
|
||||||
|
return vc.Process{}, err
|
||||||
|
}
|
||||||
|
|
||||||
return containers[0].Process(), nil
|
return containers[0].Process(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,6 +264,10 @@ func createContainer(ociSpec oci.CompatOCISpec, containerID, bundlePath,
|
|||||||
return vc.Process{}, err
|
return vc.Process{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := addContainerIDMapping(containerID, sandboxID); err != nil {
|
||||||
|
return vc.Process{}, err
|
||||||
|
}
|
||||||
|
|
||||||
return c.Process(), nil
|
return c.Process(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -305,14 +305,13 @@ func TestCreateInvalidArgs(t *testing.T) {
|
|||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
@@ -355,14 +354,10 @@ func TestCreateInvalidArgs(t *testing.T) {
|
|||||||
func TestCreateInvalidConfigJSON(t *testing.T) {
|
func TestCreateInvalidConfigJSON(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -393,20 +388,17 @@ func TestCreateInvalidConfigJSON(t *testing.T) {
|
|||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.Errorf(err, "%+v", detach)
|
assert.Errorf(err, "%+v", detach)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateInvalidContainerType(t *testing.T) {
|
func TestCreateInvalidContainerType(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -440,20 +432,17 @@ func TestCreateInvalidContainerType(t *testing.T) {
|
|||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.Errorf(err, "%+v", detach)
|
assert.Errorf(err, "%+v", detach)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateContainerInvalid(t *testing.T) {
|
func TestCreateContainerInvalid(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -488,6 +477,7 @@ func TestCreateContainerInvalid(t *testing.T) {
|
|||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.Errorf(err, "%+v", detach)
|
assert.Errorf(err, "%+v", detach)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,17 +491,16 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -578,6 +567,7 @@ func TestCreateProcessCgroupsPathSuccessful(t *testing.T) {
|
|||||||
for _, detach := range []bool{true, false} {
|
for _, detach := range []bool{true, false} {
|
||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, detach, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, detach, runtimeConfig)
|
||||||
assert.NoError(err, "detached: %+v", detach)
|
assert.NoError(err, "detached: %+v", detach)
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,17 +586,16 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -663,6 +652,7 @@ func TestCreateCreateCgroupsFilesFail(t *testing.T) {
|
|||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.Errorf(err, "%+v", detach)
|
assert.Errorf(err, "%+v", detach)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,17 +671,16 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -739,6 +728,7 @@ func TestCreateCreateCreatePidFileFail(t *testing.T) {
|
|||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.Errorf(err, "%+v", detach)
|
assert.Errorf(err, "%+v", detach)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -752,17 +742,16 @@ func TestCreate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
testingImpl.CreateSandboxFunc = func(sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -804,20 +793,17 @@ func TestCreate(t *testing.T) {
|
|||||||
for detach := range []bool{true, false} {
|
for detach := range []bool{true, false} {
|
||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.NoError(err, "%+v", detach)
|
assert.NoError(err, "%+v", detach)
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateInvalidKernelParams(t *testing.T) {
|
func TestCreateInvalidKernelParams(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -865,20 +851,17 @@ func TestCreateInvalidKernelParams(t *testing.T) {
|
|||||||
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
err := create(testContainerID, bundlePath, testConsole, pidFilePath, true, runtimeConfig)
|
||||||
assert.Errorf(err, "%+v", detach)
|
assert.Errorf(err, "%+v", detach)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateSandboxConfigFail(t *testing.T) {
|
func TestCreateSandboxConfigFail(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -918,14 +901,10 @@ func TestCreateSandboxConfigFail(t *testing.T) {
|
|||||||
func TestCreateCreateSandboxFail(t *testing.T) {
|
func TestCreateCreateSandboxFail(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -953,14 +932,10 @@ func TestCreateCreateSandboxFail(t *testing.T) {
|
|||||||
func TestCreateCreateContainerContainerConfigFail(t *testing.T) {
|
func TestCreateCreateContainerContainerConfigFail(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -991,20 +966,17 @@ func TestCreateCreateContainerContainerConfigFail(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
assert.True(strings.Contains(err.Error(), containerType))
|
assert.True(strings.Contains(err.Error(), containerType))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateCreateContainerFail(t *testing.T) {
|
func TestCreateCreateContainerFail(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
tmpdir, err := ioutil.TempDir("", "")
|
tmpdir, err := ioutil.TempDir("", "")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -1034,23 +1006,23 @@ func TestCreateCreateContainerFail(t *testing.T) {
|
|||||||
_, err = createContainer(spec, testContainerID, bundlePath, testConsole, disableOutput)
|
_, err = createContainer(spec, testContainerID, bundlePath, testConsole, disableOutput)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(err))
|
assert.True(vcmock.IsMockError(err))
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateCreateContainer(t *testing.T) {
|
func TestCreateCreateContainer(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// No pre-existing sandboxes
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{}, nil
|
defer os.RemoveAll(path)
|
||||||
}
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
testingImpl.CreateContainerFunc = func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
testingImpl.CreateContainerFunc = func(sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||||
return &vcmock.Sandbox{}, &vcmock.Container{}, nil
|
return &vcmock.Sandbox{}, &vcmock.Container{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
testingImpl.CreateContainerFunc = nil
|
testingImpl.CreateContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -1081,6 +1053,7 @@ func TestCreateCreateContainer(t *testing.T) {
|
|||||||
for _, disableOutput := range []bool{true, false} {
|
for _, disableOutput := range []bool{true, false} {
|
||||||
_, err = createContainer(spec, testContainerID, bundlePath, testConsole, disableOutput)
|
_, err = createContainer(spec, testContainerID, bundlePath, testConsole, disableOutput)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
os.RemoveAll(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -101,6 +101,10 @@ func delete(containerID string, force bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := delContainerIDMapping(containerID); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return removeCgroupsPath(containerID, cgroupsPathList)
|
return removeCgroupsPath(containerID, cgroupsPathList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -54,18 +54,10 @@ func TestDeleteInvalidContainer(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
// Mock Listsandbox error
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
err = delete(testContainerID, false)
|
assert.NoError(err)
|
||||||
assert.Error(err)
|
defer os.RemoveAll(path)
|
||||||
assert.True(vcmock.IsMockError(err))
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return []vc.SandboxStatus{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Container missing in ListSandbox
|
// Container missing in ListSandbox
|
||||||
err = delete(testContainerID, false)
|
err = delete(testContainerID, false)
|
||||||
@@ -80,25 +72,22 @@ func TestDeleteMissingContainerTypeAnnotation(t *testing.T) {
|
|||||||
MockID: testSandboxID,
|
MockID: testSandboxID,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := delete(sandbox.ID(), false)
|
err = delete(sandbox.ID(), false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
}
|
}
|
||||||
@@ -110,27 +99,24 @@ func TestDeleteInvalidConfig(t *testing.T) {
|
|||||||
MockID: testSandboxID,
|
MockID: testSandboxID,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := delete(sandbox.ID(), false)
|
err = delete(sandbox.ID(), false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
}
|
}
|
||||||
@@ -164,28 +150,25 @@ func TestDeleteSandbox(t *testing.T) {
|
|||||||
configJSON, err := readOCIConfigJSON(configPath)
|
configJSON, err := readOCIConfigJSON(configPath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
vcAnnotations.ConfigJSONKey: configJSON,
|
vcAnnotations.ConfigJSONKey: configJSON,
|
||||||
},
|
},
|
||||||
State: vc.State{
|
State: vc.State{
|
||||||
State: "ready",
|
State: "ready",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = delete(sandbox.ID(), false)
|
err = delete(sandbox.ID(), false)
|
||||||
@@ -244,28 +227,25 @@ func TestDeleteInvalidContainerType(t *testing.T) {
|
|||||||
configJSON, err := readOCIConfigJSON(configPath)
|
configJSON, err := readOCIConfigJSON(configPath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: "InvalidType",
|
vcAnnotations.ContainerTypeKey: "InvalidType",
|
||||||
vcAnnotations.ConfigJSONKey: configJSON,
|
vcAnnotations.ConfigJSONKey: configJSON,
|
||||||
},
|
},
|
||||||
State: vc.State{
|
State: vc.State{
|
||||||
State: "created",
|
State: "created",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Delete an invalid container type
|
// Delete an invalid container type
|
||||||
@@ -285,28 +265,25 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
|||||||
configJSON, err := readOCIConfigJSON(configPath)
|
configJSON, err := readOCIConfigJSON(configPath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
vcAnnotations.ConfigJSONKey: configJSON,
|
vcAnnotations.ConfigJSONKey: configJSON,
|
||||||
},
|
},
|
||||||
State: vc.State{
|
State: vc.State{
|
||||||
State: "running",
|
State: "running",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Delete on a running sandbox should fail
|
// Delete on a running sandbox should fail
|
||||||
@@ -367,28 +344,25 @@ func TestDeleteRunningContainer(t *testing.T) {
|
|||||||
configJSON, err := readOCIConfigJSON(configPath)
|
configJSON, err := readOCIConfigJSON(configPath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.MockContainers[0].ID(),
|
ID: sandbox.MockContainers[0].ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
vcAnnotations.ConfigJSONKey: configJSON,
|
vcAnnotations.ConfigJSONKey: configJSON,
|
||||||
},
|
},
|
||||||
State: vc.State{
|
State: vc.State{
|
||||||
State: "running",
|
State: "running",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Delete on a running container should fail.
|
// Delete on a running container should fail.
|
||||||
@@ -396,6 +370,10 @@ func TestDeleteRunningContainer(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
|
path, err = createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
// force delete
|
// force delete
|
||||||
err = delete(sandbox.MockContainers[0].ID(), true)
|
err = delete(sandbox.MockContainers[0].ID(), true)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
@@ -406,6 +384,10 @@ func TestDeleteRunningContainer(t *testing.T) {
|
|||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
path, err = createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
err = delete(sandbox.MockContainers[0].ID(), true)
|
err = delete(sandbox.MockContainers[0].ID(), true)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(err))
|
assert.True(vcmock.IsMockError(err))
|
||||||
@@ -418,6 +400,10 @@ func TestDeleteRunningContainer(t *testing.T) {
|
|||||||
testingImpl.DeleteContainerFunc = nil
|
testingImpl.DeleteContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
path, err = createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
err = delete(sandbox.MockContainers[0].ID(), true)
|
err = delete(sandbox.MockContainers[0].ID(), true)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
@@ -440,34 +426,35 @@ func TestDeleteContainer(t *testing.T) {
|
|||||||
configJSON, err := readOCIConfigJSON(configPath)
|
configJSON, err := readOCIConfigJSON(configPath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.MockContainers[0].ID(),
|
ID: sandbox.MockContainers[0].ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
vcAnnotations.ConfigJSONKey: configJSON,
|
vcAnnotations.ConfigJSONKey: configJSON,
|
||||||
},
|
},
|
||||||
State: vc.State{
|
State: vc.State{
|
||||||
State: "ready",
|
State: "ready",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = delete(sandbox.MockContainers[0].ID(), false)
|
err = delete(sandbox.MockContainers[0].ID(), false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(err))
|
assert.True(vcmock.IsMockError(err))
|
||||||
|
|
||||||
|
path, err = createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
@@ -485,6 +472,10 @@ func TestDeleteContainer(t *testing.T) {
|
|||||||
testingImpl.DeleteContainerFunc = nil
|
testingImpl.DeleteContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
path, err = createTempContainerIDMapping(sandbox.MockContainers[0].ID(), sandbox.MockContainers[0].ID())
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
err = delete(sandbox.MockContainers[0].ID(), false)
|
err = delete(sandbox.MockContainers[0].ID(), false)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
@@ -505,6 +496,10 @@ func TestDeleteCLIFunction(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
|
path, err := createTempContainerIDMapping("xyz", "xyz")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
|
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
|
||||||
flagSet.Parse([]string{"xyz"})
|
flagSet.Parse([]string{"xyz"})
|
||||||
ctx = cli.NewContext(app, flagSet, nil)
|
ctx = cli.NewContext(app, flagSet, nil)
|
||||||
@@ -532,22 +527,19 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
|||||||
configJSON, err := readOCIConfigJSON(configPath)
|
configJSON, err := readOCIConfigJSON(configPath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
vcAnnotations.ConfigJSONKey: configJSON,
|
vcAnnotations.ConfigJSONKey: configJSON,
|
||||||
},
|
},
|
||||||
State: vc.State{
|
State: vc.State{
|
||||||
State: "ready",
|
State: "ready",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -570,7 +562,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.StopSandboxFunc = nil
|
testingImpl.StopSandboxFunc = nil
|
||||||
testingImpl.DeleteSandboxFunc = nil
|
testingImpl.DeleteSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
@@ -36,6 +36,10 @@ func TestExecCLIFunction(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
|
path, err := createTempContainerIDMapping("xyz", "xyz")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
// pass container-id
|
// pass container-id
|
||||||
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
|
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
|
||||||
flagSet.Parse([]string{"xyz"})
|
flagSet.Parse([]string{"xyz"})
|
||||||
@@ -57,7 +61,11 @@ func TestExecuteErrors(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
// ListSandbox error
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
// StatusSandbox error
|
||||||
flagSet.Parse([]string{testContainerID})
|
flagSet.Parse([]string{testContainerID})
|
||||||
err = execute(ctx)
|
err = execute(ctx)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
@@ -68,12 +76,12 @@ func TestExecuteErrors(t *testing.T) {
|
|||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, vc.State{}, annotations), nil
|
return newSingleContainerStatus(testContainerID, vc.State{}, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = execute(ctx)
|
err = execute(ctx)
|
||||||
@@ -91,8 +99,8 @@ func TestExecuteErrors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
containerState := vc.State{}
|
containerState := vc.State{}
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, containerState, annotations), nil
|
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = execute(ctx)
|
err = execute(ctx)
|
||||||
@@ -103,8 +111,8 @@ func TestExecuteErrors(t *testing.T) {
|
|||||||
containerState = vc.State{
|
containerState = vc.State{
|
||||||
State: vc.StatePaused,
|
State: vc.StatePaused,
|
||||||
}
|
}
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, containerState, annotations), nil
|
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = execute(ctx)
|
err = execute(ctx)
|
||||||
@@ -115,8 +123,8 @@ func TestExecuteErrors(t *testing.T) {
|
|||||||
containerState = vc.State{
|
containerState = vc.State{
|
||||||
State: vc.StateStopped,
|
State: vc.StateStopped,
|
||||||
}
|
}
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, vc.State{}, containerState, annotations), nil
|
return newSingleContainerStatus(testContainerID, containerState, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = execute(ctx)
|
err = execute(ctx)
|
||||||
@@ -152,12 +160,16 @@ func TestExecuteErrorReadingProcessJson(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Note: flags can only be tested with the CLI command function
|
// Note: flags can only be tested with the CLI command function
|
||||||
@@ -196,12 +208,16 @@ func TestExecuteErrorOpeningConsole(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Note: flags can only be tested with the CLI command function
|
// Note: flags can only be tested with the CLI command function
|
||||||
@@ -258,12 +274,16 @@ func TestExecuteWithFlags(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fn, ok := execCLICommand.Action.(func(context *cli.Context) error)
|
fn, ok := execCLICommand.Action.(func(context *cli.Context) error)
|
||||||
@@ -342,12 +362,16 @@ func TestExecuteWithFlagsDetached(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
testingImpl.EnterContainerFunc = func(sandboxID, containerID string, cmd vc.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||||
@@ -416,12 +440,16 @@ func TestExecuteWithInvalidProcessJson(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fn, ok := execCLICommand.Action.(func(context *cli.Context) error)
|
fn, ok := execCLICommand.Action.(func(context *cli.Context) error)
|
||||||
@@ -463,12 +491,16 @@ func TestExecuteWithValidProcessJson(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
processJSON := `{
|
processJSON := `{
|
||||||
@@ -555,12 +587,16 @@ func TestExecuteWithInvalidEnvironment(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
processJSON := `{
|
processJSON := `{
|
||||||
|
128
cli/kill_test.go
128
cli/kill_test.go
@@ -8,6 +8,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -72,13 +73,19 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
|
|||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -90,11 +97,12 @@ func testKillCLIFunctionTerminationSignalSuccessful(t *testing.T, sig string) {
|
|||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
|
}
|
||||||
|
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
testingImpl.StopSandboxFunc = testStopSandboxFuncReturnNil
|
testingImpl.StopSandboxFunc = testStopSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.StopSandboxFunc = nil
|
testingImpl.StopSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
@@ -118,12 +126,18 @@ func TestKillCLIFunctionNotTerminationSignalSuccessful(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -145,13 +159,19 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
|
|||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -163,11 +183,12 @@ func TestKillCLIFunctionNoSignalSuccessful(t *testing.T) {
|
|||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
|
}
|
||||||
|
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
testingImpl.StopSandboxFunc = testStopSandboxFuncReturnNil
|
testingImpl.StopSandboxFunc = testStopSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.StopSandboxFunc = nil
|
testingImpl.StopSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
@@ -194,13 +215,19 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
testingImpl.StopContainerFunc = testStopContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -213,11 +240,12 @@ func TestKillCLIFunctionEnableAllSuccessful(t *testing.T) {
|
|||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, annotations), nil
|
||||||
|
}
|
||||||
|
|
||||||
testingImpl.StopContainerFunc = nil
|
testingImpl.StopContainerFunc = nil
|
||||||
testingImpl.StopSandboxFunc = testStopSandboxFuncReturnNil
|
testingImpl.StopSandboxFunc = testStopSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, annotations), nil
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.StopSandboxFunc = nil
|
testingImpl.StopSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
@@ -237,12 +265,17 @@ func TestKillCLIFunctionContainerNotExistFailure(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return []vc.SandboxStatus{}, nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -259,12 +292,18 @@ func TestKillCLIFunctionInvalidSignalFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -281,12 +320,18 @@ func TestKillCLIFunctionInvalidStatePausedFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -303,12 +348,18 @@ func TestKillCLIFunctionInvalidStateStoppedFailure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
testingImpl.KillContainerFunc = testKillContainerFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.KillContainerFunc = nil
|
testingImpl.KillContainerFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -324,11 +375,16 @@ func TestKillCLIFunctionKillContainerFailure(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
|
@@ -438,19 +438,11 @@ func writeOCIConfigFile(spec oci.CompatOCISpec, configPath string) error {
|
|||||||
return ioutil.WriteFile(configPath, bytes, testFileMode)
|
return ioutil.WriteFile(configPath, bytes, testFileMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSingleContainerSandboxStatusList(sandboxID, containerID string, sandboxState, containerState vc.State, annotations map[string]string) []vc.SandboxStatus {
|
func newSingleContainerStatus(containerID string, containerState vc.State, annotations map[string]string) vc.ContainerStatus {
|
||||||
return []vc.SandboxStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: containerID,
|
||||||
ID: sandboxID,
|
State: containerState,
|
||||||
State: sandboxState,
|
Annotations: annotations,
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
|
||||||
{
|
|
||||||
ID: containerID,
|
|
||||||
State: containerState,
|
|
||||||
Annotations: annotations,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1102,3 +1094,18 @@ func TestMainResetCLIGlobals(t *testing.T) {
|
|||||||
assert.NotNil(cli.VersionPrinter)
|
assert.NotNil(cli.VersionPrinter)
|
||||||
assert.NotNil(savedCLIVersionPrinter)
|
assert.NotNil(savedCLIVersionPrinter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func createTempContainerIDMapping(containerID, sandboxID string) (string, error) {
|
||||||
|
tmpDir, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
ctrsMapTreePath = tmpDir
|
||||||
|
|
||||||
|
path := filepath.Join(ctrsMapTreePath, containerID, sandboxID)
|
||||||
|
if err := os.MkdirAll(path, 0750); err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmpDir, nil
|
||||||
|
}
|
||||||
|
99
cli/oci.go
99
cli/oci.go
@@ -9,6 +9,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -24,10 +25,11 @@ import (
|
|||||||
|
|
||||||
// Contants related to cgroup memory directory
|
// Contants related to cgroup memory directory
|
||||||
const (
|
const (
|
||||||
cgroupsTasksFile = "tasks"
|
cgroupsTasksFile = "tasks"
|
||||||
cgroupsProcsFile = "cgroup.procs"
|
cgroupsProcsFile = "cgroup.procs"
|
||||||
cgroupsDirMode = os.FileMode(0750)
|
cgroupsDirMode = os.FileMode(0750)
|
||||||
cgroupsFileMode = os.FileMode(0640)
|
cgroupsFileMode = os.FileMode(0640)
|
||||||
|
ctrsMappingDirMode = os.FileMode(0750)
|
||||||
|
|
||||||
// Filesystem type corresponding to CGROUP_SUPER_MAGIC as listed
|
// Filesystem type corresponding to CGROUP_SUPER_MAGIC as listed
|
||||||
// here: http://man7.org/linux/man-pages/man2/statfs.2.html
|
// here: http://man7.org/linux/man-pages/man2/statfs.2.html
|
||||||
@@ -40,6 +42,8 @@ var cgroupsDirPath string
|
|||||||
|
|
||||||
var procMountInfo = "/proc/self/mountinfo"
|
var procMountInfo = "/proc/self/mountinfo"
|
||||||
|
|
||||||
|
var ctrsMapTreePath = "/var/run/kata-containers/containers-mapping"
|
||||||
|
|
||||||
// getContainerInfo returns the container status and its sandbox ID.
|
// getContainerInfo returns the container status and its sandbox ID.
|
||||||
func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
||||||
// container ID MUST be provided.
|
// container ID MUST be provided.
|
||||||
@@ -47,23 +51,23 @@ func getContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
|||||||
return vc.ContainerStatus{}, "", fmt.Errorf("Missing container ID")
|
return vc.ContainerStatus{}, "", fmt.Errorf("Missing container ID")
|
||||||
}
|
}
|
||||||
|
|
||||||
sandboxStatusList, err := vci.ListSandbox()
|
sandboxID, err := fetchContainerIDMapping(containerID)
|
||||||
|
if err != nil {
|
||||||
|
return vc.ContainerStatus{}, "", err
|
||||||
|
}
|
||||||
|
if sandboxID == "" {
|
||||||
|
// Not finding a container should not trigger an error as
|
||||||
|
// getContainerInfo is used for checking the existence and
|
||||||
|
// the absence of a container ID.
|
||||||
|
return vc.ContainerStatus{}, "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrStatus, err := vci.StatusContainer(sandboxID, containerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return vc.ContainerStatus{}, "", err
|
return vc.ContainerStatus{}, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sandboxStatus := range sandboxStatusList {
|
return ctrStatus, sandboxID, nil
|
||||||
for _, containerStatus := range sandboxStatus.ContainersStatus {
|
|
||||||
if containerStatus.ID == containerID {
|
|
||||||
return containerStatus, sandboxStatus.ID, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not finding a container should not trigger an error as
|
|
||||||
// getContainerInfo is used for checking the existence and
|
|
||||||
// the absence of a container ID.
|
|
||||||
return vc.ContainerStatus{}, "", nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExistingContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
func getExistingContainerInfo(containerID string) (vc.ContainerStatus, string, error) {
|
||||||
@@ -339,3 +343,64 @@ func getCgroupsDirPath(mountInfoFile string) (string, error) {
|
|||||||
|
|
||||||
return cgroupRootPath, nil
|
return cgroupRootPath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function assumes it should find only one file inside the container
|
||||||
|
// ID directory. If there are several files, we could not determine which
|
||||||
|
// file name corresponds to the sandbox ID associated, and this would throw
|
||||||
|
// an error.
|
||||||
|
func fetchContainerIDMapping(containerID string) (string, error) {
|
||||||
|
if containerID == "" {
|
||||||
|
return "", fmt.Errorf("Missing container ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
dirPath := filepath.Join(ctrsMapTreePath, containerID)
|
||||||
|
|
||||||
|
files, err := ioutil.ReadDir(dirPath)
|
||||||
|
if err != nil {
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(files) != 1 {
|
||||||
|
return "", fmt.Errorf("Too many files (%d) in %q", len(files), dirPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return files[0].Name(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addContainerIDMapping(containerID, sandboxID string) error {
|
||||||
|
if containerID == "" {
|
||||||
|
return fmt.Errorf("Missing container ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
if sandboxID == "" {
|
||||||
|
return fmt.Errorf("Missing sandbox ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
parentPath := filepath.Join(ctrsMapTreePath, containerID)
|
||||||
|
|
||||||
|
if err := os.RemoveAll(parentPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(parentPath, sandboxID)
|
||||||
|
|
||||||
|
if err := os.MkdirAll(path, ctrsMappingDirMode); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func delContainerIDMapping(containerID string) error {
|
||||||
|
if containerID == "" {
|
||||||
|
return fmt.Errorf("Missing container ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(ctrsMapTreePath, containerID)
|
||||||
|
|
||||||
|
return os.RemoveAll(path)
|
||||||
|
}
|
||||||
|
247
cli/oci_test.go
247
cli/oci_test.go
@@ -87,17 +87,16 @@ func TestGetContainerInfo(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(containerID, testSandboxID)
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{containerStatus},
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
},
|
return containerStatus, nil
|
||||||
}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
status, sandboxID, err := getContainerInfo(testContainerID)
|
status, sandboxID, err := getContainerInfo(testContainerID)
|
||||||
@@ -106,40 +105,6 @@ func TestGetContainerInfo(t *testing.T) {
|
|||||||
assert.Equal(status, containerStatus)
|
assert.Equal(status, containerStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetContainerInfoMismatch(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
sandbox := &vcmock.Sandbox{
|
|
||||||
MockID: testSandboxID,
|
|
||||||
}
|
|
||||||
|
|
||||||
containerID := testContainerID + testContainerID
|
|
||||||
|
|
||||||
containerStatus := vc.ContainerStatus{
|
|
||||||
ID: containerID,
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return []vc.SandboxStatus{
|
|
||||||
{
|
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{containerStatus},
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, sandboxID, err := getContainerInfo(testContainerID)
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(sandboxID, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidCreateParamsContainerIDEmptyFailure(t *testing.T) {
|
func TestValidCreateParamsContainerIDEmptyFailure(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
_, err := validCreateParams("", "")
|
_, err := validCreateParams("", "")
|
||||||
@@ -159,75 +124,16 @@ func TestGetExistingContainerInfoContainerIDEmptyFailure(t *testing.T) {
|
|||||||
func TestValidCreateParamsContainerIDNotUnique(t *testing.T) {
|
func TestValidCreateParamsContainerIDNotUnique(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
containerID := testContainerID + testContainerID
|
testSandboxID2 := testSandboxID + "2"
|
||||||
|
|
||||||
sandbox := &vcmock.Sandbox{
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
MockID: testSandboxID,
|
assert.NoError(err)
|
||||||
}
|
defer os.RemoveAll(path)
|
||||||
|
err = os.MkdirAll(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID2), 0750)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
_, err = validCreateParams(testContainerID, "")
|
||||||
return []vc.SandboxStatus{
|
|
||||||
{
|
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
|
||||||
// 2 containers with same ID
|
|
||||||
{
|
|
||||||
ID: containerID,
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
ID: containerID,
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err := validCreateParams(testContainerID, "")
|
|
||||||
|
|
||||||
assert.Error(err)
|
|
||||||
assert.False(vcmock.IsMockError(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidCreateParamsContainerIDNotUnique2(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
containerID := testContainerID + testContainerID
|
|
||||||
|
|
||||||
sandbox := &vcmock.Sandbox{
|
|
||||||
MockID: testSandboxID,
|
|
||||||
}
|
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return []vc.SandboxStatus{
|
|
||||||
{
|
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
|
||||||
{
|
|
||||||
ID: containerID,
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err := validCreateParams(testContainerID, "")
|
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
}
|
}
|
||||||
@@ -241,13 +147,10 @@ func TestValidCreateParamsInvalidBundle(t *testing.T) {
|
|||||||
|
|
||||||
bundlePath := filepath.Join(tmpdir, "bundle")
|
bundlePath := filepath.Join(tmpdir, "bundle")
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
return []vc.SandboxStatus{}, nil
|
assert.NoError(err)
|
||||||
}
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = validCreateParams(testContainerID, bundlePath)
|
_, err = validCreateParams(testContainerID, bundlePath)
|
||||||
// bundle is ENOENT
|
// bundle is ENOENT
|
||||||
@@ -266,13 +169,10 @@ func TestValidCreateParamsBundleIsAFile(t *testing.T) {
|
|||||||
err = createEmptyFile(bundlePath)
|
err = createEmptyFile(bundlePath)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
return []vc.SandboxStatus{}, nil
|
assert.NoError(err)
|
||||||
}
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
defer func() {
|
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = validCreateParams(testContainerID, bundlePath)
|
_, err = validCreateParams(testContainerID, bundlePath)
|
||||||
// bundle exists as a file, not a directory
|
// bundle exists as a file, not a directory
|
||||||
@@ -612,3 +512,106 @@ func TestGetCgroupsDirPath(t *testing.T) {
|
|||||||
assert.Equal(d.expectedResult, path)
|
assert.Equal(d.expectedResult, path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFetchContainerIDMappingContainerIDEmptyFailure(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
sandboxID, err := fetchContainerIDMapping("")
|
||||||
|
assert.Error(err)
|
||||||
|
assert.Empty(sandboxID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFetchContainerIDMappingEmptyMappingSuccess(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
sandboxID, err := fetchContainerIDMapping(testContainerID)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Empty(sandboxID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFetchContainerIDMappingTooManyFilesFailure(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
err = os.MkdirAll(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID+"2"), ctrsMappingDirMode)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
sandboxID, err := fetchContainerIDMapping(testContainerID)
|
||||||
|
assert.Error(err)
|
||||||
|
assert.Empty(sandboxID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFetchContainerIDMappingSuccess(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
sandboxID, err := fetchContainerIDMapping(testContainerID)
|
||||||
|
assert.NoError(err)
|
||||||
|
assert.Equal(sandboxID, testSandboxID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddContainerIDMappingContainerIDEmptyFailure(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
err := addContainerIDMapping("", testSandboxID)
|
||||||
|
assert.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddContainerIDMappingSandboxIDEmptyFailure(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
err := addContainerIDMapping(testContainerID, "")
|
||||||
|
assert.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddContainerIDMappingSuccess(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
_, err = os.Stat(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID))
|
||||||
|
assert.True(os.IsNotExist(err))
|
||||||
|
|
||||||
|
err = addContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
_, err = os.Stat(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID))
|
||||||
|
assert.NoError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDelContainerIDMappingContainerIDEmptyFailure(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
err := delContainerIDMapping("")
|
||||||
|
assert.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDelContainerIDMappingSuccess(t *testing.T) {
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
_, err = os.Stat(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID))
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
err = delContainerIDMapping(testContainerID)
|
||||||
|
assert.NoError(err)
|
||||||
|
|
||||||
|
_, err = os.Stat(filepath.Join(ctrsMapTreePath, testContainerID, testSandboxID))
|
||||||
|
assert.True(os.IsNotExist(err))
|
||||||
|
}
|
||||||
|
@@ -7,6 +7,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
@@ -32,12 +34,18 @@ func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil
|
testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.PauseSandboxFunc = nil
|
testingImpl.PauseSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -50,12 +58,14 @@ func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil
|
testingImpl.PauseSandboxFunc = testPauseSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return []vc.SandboxStatus{}, nil
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
}
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.PauseSandboxFunc = nil
|
testingImpl.PauseSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -71,11 +81,16 @@ func TestPauseCLIFunctionPauseSandboxFailure(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -92,12 +107,18 @@ func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil
|
testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ResumeSandboxFunc = nil
|
testingImpl.ResumeSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -110,12 +131,13 @@ func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil
|
testingImpl.ResumeSandboxFunc = testResumeSandboxFuncReturnNil
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
|
||||||
return []vc.SandboxStatus{}, nil
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
}
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ResumeSandboxFunc = nil
|
testingImpl.ResumeSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
@@ -131,11 +153,16 @@ func TestResumeCLIFunctionPauseSandboxFailure(t *testing.T) {
|
|||||||
State: vc.StateRunning,
|
State: vc.StateRunning,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return newSingleContainerSandboxStatusList(testSandboxID, testContainerID, state, state, map[string]string{}), nil
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return newSingleContainerStatus(testContainerID, state, map[string]string{}), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
set := flag.NewFlagSet("", 0)
|
set := flag.NewFlagSet("", 0)
|
||||||
|
@@ -7,6 +7,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
@@ -47,29 +48,25 @@ func TestPSFailure(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
// return a sandboxStatus with the container status
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{
|
defer os.RemoveAll(path)
|
||||||
{
|
|
||||||
ID: sandbox.ID(),
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: sandbox.ID(),
|
||||||
ID: sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
Annotations: map[string]string{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// inexistent container
|
// inexistent container
|
||||||
err := ps("xyz123abc", "json", []string{"-ef"})
|
err = ps("xyz123abc", "json", []string{"-ef"})
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
// container is not running
|
// container is not running
|
||||||
@@ -91,22 +88,18 @@ func TestPSSuccessful(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
// return a sandboxStatus with the container status
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{
|
defer os.RemoveAll(path)
|
||||||
{
|
|
||||||
ID: sandbox.ID(),
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
State: vc.State{
|
||||||
State: vc.State{
|
State: vc.StateRunning,
|
||||||
State: vc.StateRunning,
|
},
|
||||||
},
|
ID: sandbox.ID(),
|
||||||
ID: sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
Annotations: map[string]string{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -116,10 +109,10 @@ func TestPSSuccessful(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.ProcessListContainerFunc = nil
|
testingImpl.ProcessListContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := ps(sandbox.ID(), "json", []string{})
|
err = ps(sandbox.ID(), "json", []string{})
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
|
190
cli/run_test.go
190
cli/run_test.go
@@ -74,14 +74,14 @@ func TestRunInvalidArgs(t *testing.T) {
|
|||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
return []vc.SandboxStatus{}, nil
|
assert.NoError(err)
|
||||||
}
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// temporal dir to place container files
|
// temporal dir to place container files
|
||||||
@@ -237,25 +237,23 @@ func TestRunContainerSuccessful(t *testing.T) {
|
|||||||
return d.sandbox, nil
|
return d.sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
// return an empty list on create
|
// return an empty list on create
|
||||||
if !flagCreate {
|
if !flagCreate {
|
||||||
return []vc.SandboxStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a sandboxStatus with the container status
|
// return a sandboxStatus with the container status
|
||||||
return []vc.SandboxStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: d.sandbox.ID(),
|
||||||
ID: d.sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
{
|
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||||
ID: d.sandbox.ID(),
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -279,13 +277,13 @@ func TestRunContainerSuccessful(t *testing.T) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.StartContainerFunc = nil
|
testingImpl.StartContainerFunc = nil
|
||||||
testingImpl.DeleteSandboxFunc = nil
|
testingImpl.DeleteSandboxFunc = nil
|
||||||
testingImpl.DeleteContainerFunc = nil
|
testingImpl.DeleteContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
||||||
|
|
||||||
// should return ExitError with the message and exit code
|
// should return ExitError with the message and exit code
|
||||||
e, ok := err.(*cli.ExitError)
|
e, ok := err.(*cli.ExitError)
|
||||||
@@ -313,25 +311,23 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
|||||||
return d.sandbox, nil
|
return d.sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
// return an empty list on create
|
// return an empty list on create
|
||||||
if !flagCreate {
|
if !flagCreate {
|
||||||
return []vc.SandboxStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a sandboxStatus with the container status
|
// return a sandboxStatus with the container status
|
||||||
return []vc.SandboxStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: d.sandbox.ID(),
|
||||||
ID: d.sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
{
|
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||||
ID: d.sandbox.ID(),
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -355,13 +351,13 @@ func TestRunContainerDetachSuccessful(t *testing.T) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.StartContainerFunc = nil
|
testingImpl.StartContainerFunc = nil
|
||||||
testingImpl.DeleteSandboxFunc = nil
|
testingImpl.DeleteSandboxFunc = nil
|
||||||
testingImpl.DeleteContainerFunc = nil
|
testingImpl.DeleteContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, true, d.runtimeConfig)
|
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, true, d.runtimeConfig)
|
||||||
|
|
||||||
// should not return ExitError
|
// should not return ExitError
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
@@ -386,25 +382,23 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
|||||||
return d.sandbox, nil
|
return d.sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
// return an empty list on create
|
// return an empty list on create
|
||||||
if !flagCreate {
|
if !flagCreate {
|
||||||
return []vc.SandboxStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a sandboxStatus with the container status
|
// return a sandboxStatus with the container status
|
||||||
return []vc.SandboxStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: d.sandbox.ID(),
|
||||||
ID: d.sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
{
|
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||||
ID: d.sandbox.ID(),
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -430,13 +424,13 @@ func TestRunContainerDeleteFail(t *testing.T) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.StartContainerFunc = nil
|
testingImpl.StartContainerFunc = nil
|
||||||
testingImpl.DeleteSandboxFunc = nil
|
testingImpl.DeleteSandboxFunc = nil
|
||||||
testingImpl.DeleteContainerFunc = nil
|
testingImpl.DeleteContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
||||||
|
|
||||||
// should not return ExitError
|
// should not return ExitError
|
||||||
err, ok := err.(*cli.ExitError)
|
err, ok := err.(*cli.ExitError)
|
||||||
@@ -462,25 +456,23 @@ func TestRunContainerWaitFail(t *testing.T) {
|
|||||||
return d.sandbox, nil
|
return d.sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
// return an empty list on create
|
// return an empty list on create
|
||||||
if !flagCreate {
|
if !flagCreate {
|
||||||
return []vc.SandboxStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a sandboxStatus with the container status
|
// return a sandboxStatus with the container status
|
||||||
return []vc.SandboxStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: d.sandbox.ID(),
|
||||||
ID: d.sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
{
|
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||||
ID: d.sandbox.ID(),
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -509,13 +501,13 @@ func TestRunContainerWaitFail(t *testing.T) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.StartContainerFunc = nil
|
testingImpl.StartContainerFunc = nil
|
||||||
testingImpl.DeleteSandboxFunc = nil
|
testingImpl.DeleteSandboxFunc = nil
|
||||||
testingImpl.DeleteContainerFunc = nil
|
testingImpl.DeleteContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
||||||
|
|
||||||
// should not return ExitError
|
// should not return ExitError
|
||||||
err, ok := err.(*cli.ExitError)
|
err, ok := err.(*cli.ExitError)
|
||||||
@@ -546,25 +538,23 @@ func TestRunContainerStartFail(t *testing.T) {
|
|||||||
return nil, fmt.Errorf("StartSandbox")
|
return nil, fmt.Errorf("StartSandbox")
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
// return an empty list on create
|
// return an empty list on create
|
||||||
if !flagCreate {
|
if !flagCreate {
|
||||||
return []vc.SandboxStatus{}, nil
|
return vc.ContainerStatus{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a sandboxStatus with the container status
|
// return a sandboxStatus with the container status
|
||||||
return []vc.SandboxStatus{
|
return vc.ContainerStatus{
|
||||||
{
|
ID: d.sandbox.ID(),
|
||||||
ID: d.sandbox.ID(),
|
Annotations: map[string]string{
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
{
|
vcAnnotations.ConfigJSONKey: d.configJSON,
|
||||||
ID: d.sandbox.ID(),
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
|
||||||
vcAnnotations.ConfigJSONKey: d.configJSON,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -572,7 +562,7 @@ func TestRunContainerStartFail(t *testing.T) {
|
|||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
||||||
@@ -582,11 +572,9 @@ func TestRunContainerStartFail(t *testing.T) {
|
|||||||
assert.False(ok, "error should not be a cli.ExitError: %s", err)
|
assert.False(ok, "error should not be a cli.ExitError: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRunContainerStartFailNoContainers(t *testing.T) {
|
func TestRunContainerStartFailExistingContainer(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
listCallCount := 0
|
|
||||||
|
|
||||||
d := testRunContainerSetup(t)
|
d := testRunContainerSetup(t)
|
||||||
defer os.RemoveAll(d.tmpDir)
|
defer os.RemoveAll(d.tmpDir)
|
||||||
|
|
||||||
@@ -601,24 +589,16 @@ func TestRunContainerStartFailNoContainers(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, sandbox.ID())
|
||||||
listCallCount++
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
if listCallCount == 1 {
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
return []vc.SandboxStatus{}, nil
|
// return the container status
|
||||||
}
|
return vc.ContainerStatus{
|
||||||
|
ID: testContainerID,
|
||||||
return []vc.SandboxStatus{
|
Annotations: map[string]string{
|
||||||
{
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
|
||||||
{
|
|
||||||
ID: testContainerID,
|
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -635,12 +615,12 @@ func TestRunContainerStartFailNoContainers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.CreateSandboxFunc = nil
|
testingImpl.CreateSandboxFunc = nil
|
||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
err = run(d.sandbox.ID(), d.bundlePath, d.consolePath, "", d.pidFilePath, false, d.runtimeConfig)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
@@ -24,20 +26,21 @@ func TestStartInvalidArgs(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
// Mock Listsandbox error
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
|
// Mock StatusContainer error
|
||||||
_, err = start(testContainerID)
|
_, err = start(testContainerID)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(err))
|
assert.True(vcmock.IsMockError(err))
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err = ioutil.TempDir("", "containers-mapping")
|
||||||
return []vc.SandboxStatus{}, nil
|
assert.NoError(err)
|
||||||
}
|
defer os.RemoveAll(path)
|
||||||
|
ctrsMapTreePath = path
|
||||||
|
|
||||||
defer func() {
|
// Container missing in container mapping
|
||||||
testingImpl.ListSandboxFunc = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Container missing in ListSandbox
|
|
||||||
_, err = start(testContainerID)
|
_, err = start(testContainerID)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
@@ -50,27 +53,24 @@ func TestStartSandbox(t *testing.T) {
|
|||||||
MockID: testSandboxID,
|
MockID: testSandboxID,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
vcAnnotations.ContainerTypeKey: string(vc.PodSandbox),
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_, err := start(sandbox.ID())
|
_, err = start(sandbox.ID())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(err))
|
assert.True(vcmock.IsMockError(err))
|
||||||
|
|
||||||
@@ -93,25 +93,22 @@ func TestStartMissingAnnotation(t *testing.T) {
|
|||||||
MockID: testSandboxID,
|
MockID: testSandboxID,
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(sandbox.ID(), sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: sandbox.ID(),
|
ID: sandbox.ID(),
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_, err := start(sandbox.ID())
|
_, err = start(sandbox.ID())
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
}
|
}
|
||||||
@@ -130,27 +127,24 @@ func TestStartContainerSucessFailure(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, sandbox.ID())
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: testContainerID,
|
ID: testContainerID,
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_, err := start(testContainerID)
|
_, err = start(testContainerID)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(err))
|
assert.True(vcmock.IsMockError(err))
|
||||||
|
|
||||||
@@ -182,6 +176,10 @@ func TestStartCLIFunction(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
|
|
||||||
|
path, err := createTempContainerIDMapping("xyz", "xyz")
|
||||||
|
assert.NoError(err)
|
||||||
|
defer os.RemoveAll(path)
|
||||||
|
|
||||||
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
|
flagSet = flag.NewFlagSet("container-id", flag.ContinueOnError)
|
||||||
flagSet.Parse([]string{"xyz"})
|
flagSet.Parse([]string{"xyz"})
|
||||||
ctx = cli.NewContext(app, flagSet, nil)
|
ctx = cli.NewContext(app, flagSet, nil)
|
||||||
@@ -205,18 +203,15 @@ func TestStartCLIFunctionSuccess(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||||
return []vc.SandboxStatus{
|
assert.NoError(err)
|
||||||
{
|
defer os.RemoveAll(path)
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
{
|
return vc.ContainerStatus{
|
||||||
ID: testContainerID,
|
ID: testContainerID,
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@@ -226,7 +221,7 @@ func TestStartCLIFunctionSuccess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
testingImpl.StartContainerFunc = nil
|
testingImpl.StartContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -240,6 +235,6 @@ func TestStartCLIFunctionSuccess(t *testing.T) {
|
|||||||
ctx := cli.NewContext(app, flagSet, nil)
|
ctx := cli.NewContext(app, flagSet, nil)
|
||||||
assert.NotNil(ctx)
|
assert.NotNil(ctx)
|
||||||
|
|
||||||
err := fn(ctx)
|
err = fn(ctx)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
|
@@ -7,6 +7,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||||
@@ -51,31 +53,32 @@ func TestStateSuccessful(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.ListSandboxFunc = func() ([]vc.SandboxStatus, error) {
|
path, err := ioutil.TempDir("", "containers-mapping")
|
||||||
// return a sandboxStatus with the container status
|
assert.NoError(err)
|
||||||
return []vc.SandboxStatus{
|
defer os.RemoveAll(path)
|
||||||
{
|
ctrsMapTreePath = path
|
||||||
ID: sandbox.ID(),
|
|
||||||
ContainersStatus: []vc.ContainerStatus{
|
// trying with an inexistent id
|
||||||
{
|
err = state("123456789")
|
||||||
ID: sandbox.ID(),
|
assert.Error(err)
|
||||||
Annotations: map[string]string{
|
|
||||||
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
path, err = createTempContainerIDMapping(testContainerID, sandbox.ID())
|
||||||
},
|
assert.NoError(err)
|
||||||
},
|
defer os.RemoveAll(path)
|
||||||
},
|
|
||||||
|
testingImpl.StatusContainerFunc = func(sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||||
|
return vc.ContainerStatus{
|
||||||
|
ID: testContainerID,
|
||||||
|
Annotations: map[string]string{
|
||||||
|
vcAnnotations.ContainerTypeKey: string(vc.PodContainer),
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
testingImpl.ListSandboxFunc = nil
|
testingImpl.StatusContainerFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// trying with an inexistent id
|
err = state(testContainerID)
|
||||||
err := state("123456789")
|
|
||||||
assert.Error(err)
|
|
||||||
|
|
||||||
err = state(sandbox.ID())
|
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user