mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-11-27 23:41:19 +00:00
runtime: move all code to src/runtime
To prepare for merging into kata-containers repository. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
175
src/runtime/cli/pause_test.go
Normal file
175
src/runtime/cli/pause_test.go
Normal file
@@ -0,0 +1,175 @@
|
||||
// Copyright (c) 2017 Intel Corporation
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
vc "github.com/kata-containers/runtime/virtcontainers"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
)
|
||||
|
||||
var (
|
||||
testPauseContainerFuncReturnNil = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
testResumeContainerFuncReturnNil = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
return nil
|
||||
}
|
||||
)
|
||||
|
||||
func TestPauseCLIFunctionSuccessful(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := types.ContainerState{
|
||||
State: types.StateRunning,
|
||||
}
|
||||
|
||||
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.PauseContainerFunc = nil
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, pauseCLICommand, set, false)
|
||||
}
|
||||
|
||||
func TestPauseCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testingImpl.PauseContainerFunc = testPauseContainerFuncReturnNil
|
||||
|
||||
path, err := ioutil.TempDir("", "containers-mapping")
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
ctrsMapTreePath = path
|
||||
|
||||
defer func() {
|
||||
testingImpl.PauseContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, pauseCLICommand, set, true)
|
||||
}
|
||||
|
||||
func TestPauseCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := types.ContainerState{
|
||||
State: types.StateRunning,
|
||||
}
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, pauseCLICommand, set, true)
|
||||
}
|
||||
|
||||
func TestResumeCLIFunctionSuccessful(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := types.ContainerState{
|
||||
State: types.StateRunning,
|
||||
}
|
||||
|
||||
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.ResumeContainerFunc = nil
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, resumeCLICommand, set, false)
|
||||
}
|
||||
|
||||
func TestResumeCLIFunctionContainerNotExistFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
testingImpl.ResumeContainerFunc = testResumeContainerFuncReturnNil
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
defer func() {
|
||||
testingImpl.ResumeContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, resumeCLICommand, set, true)
|
||||
}
|
||||
|
||||
func TestResumeCLIFunctionPauseContainerFailure(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
state := types.ContainerState{
|
||||
State: types.StateRunning,
|
||||
}
|
||||
|
||||
path, err := createTempContainerIDMapping(testContainerID, testSandboxID)
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(path)
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return newSingleContainerStatus(testContainerID, state, map[string]string{}, &specs.Spec{}), nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
set := flag.NewFlagSet("", 0)
|
||||
set.Parse([]string{testContainerID})
|
||||
|
||||
execCLICommandFunc(assert, resumeCLICommand, set, true)
|
||||
}
|
||||
Reference in New Issue
Block a user