mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
runtime: Clear the VCMock 1.x API Methods from 2.0
Clear the 1.x branch api methods in the 2.0. Keep the same methods to the VC interface, like the VCImpl struct. Fixes: #751 Signed-off-by: Ychau Wang <wangyongchao.bj@inspur.com>
This commit is contained in:
parent
0bb3117a51
commit
1839dfd95a
@ -317,12 +317,12 @@ func TestCreateContainerConfigFail(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.CreateContainerFunc = func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
return sandbox, &vcmock.Container{}, nil
|
||||
sandbox.CreateContainerFunc = func(conf vc.ContainerConfig) (vc.VCContainer, error) {
|
||||
return &vcmock.Container{}, nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.CreateContainerFunc = nil
|
||||
sandbox.CreateContainerFunc = nil
|
||||
}()
|
||||
|
||||
tmpdir, err := ioutil.TempDir("", "")
|
||||
|
@ -7,12 +7,11 @@
|
||||
package containerdshim
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/cgroups"
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/vcmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -37,18 +36,21 @@ func TestStatNetworkMetric(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testingImpl.StatsContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
sandbox := &vcmock.Sandbox{
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
sandbox.StatsContainerFunc = func(contID string) (vc.ContainerStats, error) {
|
||||
return vc.ContainerStats{
|
||||
NetworkStats: mockNetwork,
|
||||
}, nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatsContainerFunc = nil
|
||||
sandbox.StatsContainerFunc = nil
|
||||
}()
|
||||
|
||||
ctx := namespaces.WithNamespace(context.Background(), "UnitTest")
|
||||
resp, err := testingImpl.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
resp, err := sandbox.StatsContainer(testContainerID)
|
||||
assert.NoError(err)
|
||||
|
||||
metrics := statsToMetrics(&resp)
|
||||
|
@ -28,14 +28,14 @@ func TestPauseContainerSuccess(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.PauseContainerFunc = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
sandbox.PauseContainerFunc = func(contID string) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.PauseContainerFunc = nil
|
||||
sandbox.PauseContainerFunc = nil
|
||||
}()
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: make(map[string]string),
|
||||
@ -45,7 +45,7 @@ func TestPauseContainerSuccess(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
@ -76,14 +76,14 @@ func TestPauseContainerFail(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.PauseContainerFunc = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
sandbox.PauseContainerFunc = func(contID string) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.PauseContainerFunc = nil
|
||||
sandbox.PauseContainerFunc = nil
|
||||
}()
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: make(map[string]string),
|
||||
@ -93,7 +93,7 @@ func TestPauseContainerFail(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
@ -119,14 +119,14 @@ func TestResumeContainerSuccess(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.ResumeContainerFunc = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
sandbox.ResumeContainerFunc = func(contID string) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.ResumeContainerFunc = nil
|
||||
sandbox.ResumeContainerFunc = nil
|
||||
}()
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: make(map[string]string),
|
||||
@ -137,7 +137,7 @@ func TestResumeContainerSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
@ -168,13 +168,13 @@ func TestResumeContainerFail(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.ResumeContainerFunc = func(ctx context.Context, sandboxID, containerID string) error {
|
||||
sandbox.ResumeContainerFunc = func(contID string) error {
|
||||
return nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.ResumeContainerFunc = nil
|
||||
sandbox.ResumeContainerFunc = nil
|
||||
}()
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: make(map[string]string),
|
||||
@ -184,7 +184,7 @@ func TestResumeContainerFail(t *testing.T) {
|
||||
}, nil
|
||||
}
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
|
@ -28,7 +28,7 @@ func TestStartStartSandboxSuccess(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{
|
||||
@ -38,7 +38,7 @@ func TestStartStartSandboxSuccess(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
@ -58,12 +58,12 @@ func TestStartStartSandboxSuccess(t *testing.T) {
|
||||
ID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
sandbox.StartFunc = func() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StartSandboxFunc = nil
|
||||
sandbox.StartFunc = nil
|
||||
}()
|
||||
|
||||
ctx := namespaces.WithNamespace(context.Background(), "UnitTest")
|
||||
@ -79,7 +79,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
||||
MockID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: sandbox.ID(),
|
||||
Annotations: map[string]string{},
|
||||
@ -87,7 +87,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
@ -107,12 +107,12 @@ func TestStartMissingAnnotation(t *testing.T) {
|
||||
ID: testSandboxID,
|
||||
}
|
||||
|
||||
testingImpl.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return sandbox, nil
|
||||
sandbox.StartFunc = func() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StartSandboxFunc = nil
|
||||
sandbox.StartFunc = nil
|
||||
}()
|
||||
|
||||
_, err = s.Start(s.ctx, reqStart)
|
||||
@ -135,7 +135,7 @@ func TestStartStartContainerSucess(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
testingImpl.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
sandbox.StatusContainerFunc = func(contID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{
|
||||
ID: testContainerID,
|
||||
Annotations: map[string]string{
|
||||
@ -145,15 +145,15 @@ func TestStartStartContainerSucess(t *testing.T) {
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StatusContainerFunc = nil
|
||||
sandbox.StatusContainerFunc = nil
|
||||
}()
|
||||
|
||||
testingImpl.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
sandbox.StartContainerFunc = func(contID string) (vc.VCContainer, error) {
|
||||
return sandbox.MockContainers[0], nil
|
||||
}
|
||||
|
||||
defer func() {
|
||||
testingImpl.StartContainerFunc = nil
|
||||
sandbox.StartContainerFunc = nil
|
||||
}()
|
||||
|
||||
s := &service{
|
||||
|
@ -18,14 +18,7 @@ package vcmock
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"syscall"
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -56,240 +49,6 @@ func (m *VCMock) CreateSandbox(ctx context.Context, sandboxConfig vc.SandboxConf
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig)
|
||||
}
|
||||
|
||||
// DeleteSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) DeleteSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.DeleteSandboxFunc != nil {
|
||||
return m.DeleteSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// FetchSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) FetchSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.FetchSandboxFunc != nil {
|
||||
return m.FetchSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// StartSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StartSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
if m.StartSandboxFunc != nil {
|
||||
return m.StartSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// StopSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StopSandbox(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) {
|
||||
if m.StopSandboxFunc != nil {
|
||||
return m.StopSandboxFunc(ctx, sandboxID, force)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// RunSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) RunSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
if m.RunSandboxFunc != nil {
|
||||
return m.RunSandboxFunc(ctx, sandboxConfig)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig)
|
||||
}
|
||||
|
||||
// ListSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) ListSandbox(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
if m.ListSandboxFunc != nil {
|
||||
return m.ListSandboxFunc(ctx)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s", mockErrorPrefix, getSelf())
|
||||
}
|
||||
|
||||
// StatusSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StatusSandbox(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
if m.StatusSandboxFunc != nil {
|
||||
return m.StatusSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return vc.SandboxStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// CreateContainer implements the VC function of the same name.
|
||||
func (m *VCMock) CreateContainer(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
if m.CreateContainerFunc != nil {
|
||||
return m.CreateContainerFunc(ctx, sandboxID, containerConfig)
|
||||
}
|
||||
|
||||
return nil, nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerConfig: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerConfig)
|
||||
}
|
||||
|
||||
// DeleteContainer implements the VC function of the same name.
|
||||
func (m *VCMock) DeleteContainer(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
if m.DeleteContainerFunc != nil {
|
||||
return m.DeleteContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StartContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StartContainer(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
if m.StartContainerFunc != nil {
|
||||
return m.StartContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StopContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StopContainer(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
if m.StopContainerFunc != nil {
|
||||
return m.StopContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// EnterContainer implements the VC function of the same name.
|
||||
func (m *VCMock) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
if m.EnterContainerFunc != nil {
|
||||
return m.EnterContainerFunc(ctx, sandboxID, containerID, cmd)
|
||||
}
|
||||
|
||||
return nil, nil, nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v, cmd: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID, cmd)
|
||||
}
|
||||
|
||||
// StatusContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StatusContainer(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
if m.StatusContainerFunc != nil {
|
||||
return m.StatusContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return vc.ContainerStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StatsContainer implements the VC function of the same name.
|
||||
func (m *VCMock) StatsContainer(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
if m.StatsContainerFunc != nil {
|
||||
return m.StatsContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return vc.ContainerStats{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// StatsSandbox implements the VC function of the same name.
|
||||
func (m *VCMock) StatsSandbox(ctx context.Context, sandboxID string) (vc.SandboxStats, []vc.ContainerStats, error) {
|
||||
if m.StatsContainerFunc != nil {
|
||||
return m.StatsSandboxFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return vc.SandboxStats{}, []vc.ContainerStats{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// KillContainer implements the VC function of the same name.
|
||||
func (m *VCMock) KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
if m.KillContainerFunc != nil {
|
||||
return m.KillContainerFunc(ctx, sandboxID, containerID, signal, all)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v, signal: %v, all: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID, signal, all)
|
||||
}
|
||||
|
||||
// ProcessListContainer implements the VC function of the same name.
|
||||
func (m *VCMock) ProcessListContainer(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
if m.ProcessListContainerFunc != nil {
|
||||
return m.ProcessListContainerFunc(ctx, sandboxID, containerID, options)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// UpdateContainer implements the VC function of the same name.
|
||||
func (m *VCMock) UpdateContainer(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
|
||||
if m.UpdateContainerFunc != nil {
|
||||
return m.UpdateContainerFunc(ctx, sandboxID, containerID, resources)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// PauseContainer implements the VC function of the same name.
|
||||
func (m *VCMock) PauseContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
if m.PauseContainerFunc != nil {
|
||||
return m.PauseContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// ResumeContainer implements the VC function of the same name.
|
||||
func (m *VCMock) ResumeContainer(ctx context.Context, sandboxID, containerID string) error {
|
||||
if m.ResumeContainerFunc != nil {
|
||||
return m.ResumeContainerFunc(ctx, sandboxID, containerID)
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %s (%+v): sandboxID: %v, containerID: %v", mockErrorPrefix, getSelf(), m, sandboxID, containerID)
|
||||
}
|
||||
|
||||
// AddDevice implements the VC function of the same name.
|
||||
func (m *VCMock) AddDevice(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) {
|
||||
if m.AddDeviceFunc != nil {
|
||||
return m.AddDeviceFunc(ctx, sandboxID, info)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// AddInterface implements the VC function of the same name.
|
||||
func (m *VCMock) AddInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
if m.AddInterfaceFunc != nil {
|
||||
return m.AddInterfaceFunc(ctx, sandboxID, inf)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// RemoveInterface implements the VC function of the same name.
|
||||
func (m *VCMock) RemoveInterface(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
if m.RemoveInterfaceFunc != nil {
|
||||
return m.RemoveInterfaceFunc(ctx, sandboxID, inf)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// ListInterfaces implements the VC function of the same name.
|
||||
func (m *VCMock) ListInterfaces(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error) {
|
||||
if m.ListInterfacesFunc != nil {
|
||||
return m.ListInterfacesFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// UpdateRoutes implements the VC function of the same name.
|
||||
func (m *VCMock) UpdateRoutes(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
if m.UpdateRoutesFunc != nil {
|
||||
return m.UpdateRoutesFunc(ctx, sandboxID, routes)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
// ListRoutes implements the VC function of the same name.
|
||||
func (m *VCMock) ListRoutes(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error) {
|
||||
if m.ListRoutesFunc != nil {
|
||||
return m.ListRoutesFunc(ctx, sandboxID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||
}
|
||||
|
||||
func (m *VCMock) CleanupContainer(ctx context.Context, sandboxID, containerID string, force bool) error {
|
||||
if m.CleanupContainerFunc != nil {
|
||||
return m.CleanupContainerFunc(ctx, sandboxID, containerID, true)
|
||||
|
@ -8,13 +8,10 @@ package vcmock
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
vc "github.com/kata-containers/kata-containers/src/runtime/virtcontainers"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/factory"
|
||||
pbTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
|
||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@ -143,514 +140,6 @@ func TestVCMockCreateSandbox(t *testing.T) {
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockDeleteSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.DeleteSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.DeleteSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.DeleteSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.DeleteSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.DeleteSandboxFunc = nil
|
||||
|
||||
_, err = m.DeleteSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockListSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.ListSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.ListSandbox(ctx)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListSandboxFunc = func(ctx context.Context) ([]vc.SandboxStatus, error) {
|
||||
return []vc.SandboxStatus{}, nil
|
||||
}
|
||||
|
||||
sandboxes, err := m.ListSandbox(ctx)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandboxes, []vc.SandboxStatus{})
|
||||
|
||||
// reset
|
||||
m.ListSandboxFunc = nil
|
||||
|
||||
_, err = m.ListSandbox(ctx)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockRunSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.RunSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.RunSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.RunSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.RunSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.RunSandboxFunc = nil
|
||||
|
||||
_, err = m.RunSandbox(ctx, vc.SandboxConfig{})
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockStartSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StartSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StartSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StartSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.StartSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.StartSandboxFunc = nil
|
||||
|
||||
_, err = m.StartSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockStatusSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StatusSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StatusSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StatusSandboxFunc = func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) {
|
||||
return vc.SandboxStatus{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.StatusSandbox(ctx, testSandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, vc.SandboxStatus{})
|
||||
|
||||
// reset
|
||||
m.StatusSandboxFunc = nil
|
||||
|
||||
_, err = m.StatusSandbox(ctx, testSandboxID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockStopSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StopSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StopSandbox(ctx, testSandboxID, false)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StopSandboxFunc = func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.StopSandbox(ctx, testSandboxID, false)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.StopSandboxFunc = nil
|
||||
|
||||
_, err = m.StopSandbox(ctx, testSandboxID, false)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockCreateContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.CreateContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
config := vc.ContainerConfig{}
|
||||
_, _, err := m.CreateContainer(ctx, testSandboxID, config)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.CreateContainerFunc = func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||
return &Sandbox{}, &Container{}, nil
|
||||
}
|
||||
|
||||
sandbox, container, err := m.CreateContainer(ctx, testSandboxID, config)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.CreateContainerFunc = nil
|
||||
|
||||
_, _, err = m.CreateContainer(ctx, testSandboxID, config)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockDeleteContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.DeleteContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.DeleteContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.DeleteContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
container, err := m.DeleteContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.DeleteContainerFunc = nil
|
||||
|
||||
_, err = m.DeleteContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockEnterContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.EnterContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
cmd := types.Cmd{}
|
||||
_, _, _, err := m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.EnterContainerFunc = func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error) {
|
||||
return &Sandbox{}, &Container{}, &vc.Process{}, nil
|
||||
}
|
||||
|
||||
sandbox, container, process, err := m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
assert.Equal(container, &Container{})
|
||||
assert.Equal(process, &vc.Process{})
|
||||
|
||||
// reset
|
||||
m.EnterContainerFunc = nil
|
||||
|
||||
_, _, _, err = m.EnterContainer(ctx, testSandboxID, testContainerID, cmd)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockKillContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.KillContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
sig := syscall.SIGTERM
|
||||
|
||||
for _, all := range []bool{true, false} {
|
||||
err := m.KillContainer(ctx, testSandboxID, testContainerID, sig, all)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
m.KillContainerFunc = func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, all := range []bool{true, false} {
|
||||
err := m.KillContainer(ctx, testSandboxID, testContainerID, sig, all)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
// reset
|
||||
m.KillContainerFunc = nil
|
||||
|
||||
for _, all := range []bool{true, false} {
|
||||
err := m.KillContainer(ctx, testSandboxID, testContainerID, sig, all)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
}
|
||||
|
||||
func TestVCMockStartContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StartContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StartContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StartContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
container, err := m.StartContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.StartContainerFunc = nil
|
||||
|
||||
_, err = m.StartContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockStatusContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StatusContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StatusContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StatusContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error) {
|
||||
return vc.ContainerStatus{}, nil
|
||||
}
|
||||
|
||||
status, err := m.StatusContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(status, vc.ContainerStatus{})
|
||||
|
||||
// reset
|
||||
m.StatusContainerFunc = nil
|
||||
|
||||
_, err = m.StatusContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockStatsContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StatsContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StatsContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) {
|
||||
return vc.ContainerStats{}, nil
|
||||
}
|
||||
|
||||
stats, err := m.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(stats, vc.ContainerStats{})
|
||||
|
||||
// reset
|
||||
m.StatsContainerFunc = nil
|
||||
|
||||
_, err = m.StatsContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockStopContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.StopContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.StopContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.StopContainerFunc = func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error) {
|
||||
return &Container{}, nil
|
||||
}
|
||||
|
||||
container, err := m.StopContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(container, &Container{})
|
||||
|
||||
// reset
|
||||
m.StopContainerFunc = nil
|
||||
|
||||
_, err = m.StopContainer(ctx, testSandboxID, testContainerID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockProcessListContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
assert.Nil(m.ProcessListContainerFunc)
|
||||
|
||||
options := vc.ProcessListOptions{
|
||||
Format: "json",
|
||||
Args: []string{"-ef"},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.ProcessListContainer(ctx, testSandboxID, testContainerID, options)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
processList := vc.ProcessList("hi")
|
||||
|
||||
m.ProcessListContainerFunc = func(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error) {
|
||||
return processList, nil
|
||||
}
|
||||
|
||||
pList, err := m.ProcessListContainer(ctx, testSandboxID, testContainerID, options)
|
||||
assert.NoError(err)
|
||||
assert.Equal(pList, processList)
|
||||
|
||||
// reset
|
||||
m.ProcessListContainerFunc = nil
|
||||
|
||||
_, err = m.ProcessListContainer(ctx, testSandboxID, testContainerID, options)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockFetchSandbox(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.FetchSandboxFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.FetchSandbox(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.FetchSandboxFunc = func(ctx context.Context, id string) (vc.VCSandbox, error) {
|
||||
return &Sandbox{}, nil
|
||||
}
|
||||
|
||||
sandbox, err := m.FetchSandbox(ctx, config.ID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(sandbox, &Sandbox{})
|
||||
|
||||
// reset
|
||||
m.FetchSandboxFunc = nil
|
||||
|
||||
_, err = m.FetchSandbox(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
}
|
||||
|
||||
func TestVCMockPauseContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.PauseContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
err := m.PauseContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.PauseContainerFunc = func(ctx context.Context, sid, cid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = m.PauseContainer(ctx, config.ID, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.PauseContainerFunc = nil
|
||||
|
||||
err = m.PauseContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockResumeContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.ResumeContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
err := m.ResumeContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ResumeContainerFunc = func(ctx context.Context, sid, cid string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
err = m.ResumeContainer(ctx, config.ID, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.ResumeContainerFunc = nil
|
||||
|
||||
err = m.ResumeContainer(ctx, config.ID, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockSetVMFactory(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@ -682,137 +171,54 @@ func TestVCMockSetVMFactory(t *testing.T) {
|
||||
assert.Equal(factoryTriggered, 1)
|
||||
}
|
||||
|
||||
func TestVCMockAddInterface(t *testing.T) {
|
||||
func TestVCMockCleanupContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.AddInterfaceFunc)
|
||||
assert.Nil(m.CleanupContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.AddInterface(ctx, config.ID, nil)
|
||||
err := m.CleanupContainer(ctx, testSandboxID, testContainerID, false)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.AddInterfaceFunc = func(ctx context.Context, sid string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
m.CleanupContainerFunc = func(ctx context.Context, sandboxID, containerID string, force bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = m.AddInterface(ctx, config.ID, nil)
|
||||
err = m.CleanupContainer(ctx, testSandboxID, testContainerID, false)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.AddInterfaceFunc = nil
|
||||
m.CleanupContainerFunc = nil
|
||||
|
||||
_, err = m.AddInterface(ctx, config.ID, nil)
|
||||
err = m.CleanupContainer(ctx, testSandboxID, testContainerID, false)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockRemoveInterface(t *testing.T) {
|
||||
func TestVCMockForceCleanupContainer(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.RemoveInterfaceFunc)
|
||||
assert.Nil(m.CleanupContainerFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.RemoveInterface(ctx, config.ID, nil)
|
||||
err := m.CleanupContainer(ctx, testSandboxID, testContainerID, true)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.RemoveInterfaceFunc = func(ctx context.Context, sid string, inf *pbTypes.Interface) (*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
m.CleanupContainerFunc = func(ctx context.Context, sandboxID, containerID string, force bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = m.RemoveInterface(ctx, config.ID, nil)
|
||||
err = m.CleanupContainer(ctx, testSandboxID, testContainerID, true)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.RemoveInterfaceFunc = nil
|
||||
m.CleanupContainerFunc = nil
|
||||
|
||||
_, err = m.RemoveInterface(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockListInterfaces(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.ListInterfacesFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.ListInterfaces(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListInterfacesFunc = func(ctx context.Context, sid string) ([]*pbTypes.Interface, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.ListInterfaces(ctx, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.ListInterfacesFunc = nil
|
||||
|
||||
_, err = m.ListInterfaces(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockUpdateRoutes(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.UpdateRoutesFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.UpdateRoutes(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.UpdateRoutesFunc = func(ctx context.Context, sid string, routes []*pbTypes.Route) ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.UpdateRoutes(ctx, config.ID, nil)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.UpdateRoutesFunc = nil
|
||||
|
||||
_, err = m.UpdateRoutes(ctx, config.ID, nil)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
||||
func TestVCMockListRoutes(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
m := &VCMock{}
|
||||
config := &vc.SandboxConfig{}
|
||||
assert.Nil(m.ListRoutesFunc)
|
||||
|
||||
ctx := context.Background()
|
||||
_, err := m.ListRoutes(ctx, config.ID)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
|
||||
m.ListRoutesFunc = func(ctx context.Context, sid string) ([]*pbTypes.Route, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
_, err = m.ListRoutes(ctx, config.ID)
|
||||
assert.NoError(err)
|
||||
|
||||
// reset
|
||||
m.ListRoutesFunc = nil
|
||||
|
||||
_, err = m.ListRoutes(ctx, config.ID)
|
||||
err = m.CleanupContainer(ctx, testSandboxID, testContainerID, true)
|
||||
assert.Error(err)
|
||||
assert.True(IsMockError(err))
|
||||
}
|
||||
|
@ -87,34 +87,5 @@ type VCMock struct {
|
||||
SetFactoryFunc func(ctx context.Context, factory vc.Factory)
|
||||
|
||||
CreateSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||
DeleteSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
ListSandboxFunc func(ctx context.Context) ([]vc.SandboxStatus, error)
|
||||
FetchSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
RunSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||
StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||
StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error)
|
||||
StatsContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error)
|
||||
StatsSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStats, []vc.ContainerStats, error)
|
||||
StopSandboxFunc func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error)
|
||||
|
||||
CreateContainerFunc func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error)
|
||||
DeleteContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||
EnterContainerFunc func(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (vc.VCSandbox, vc.VCContainer, *vc.Process, error)
|
||||
KillContainerFunc func(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error
|
||||
StartContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||
StatusContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStatus, error)
|
||||
StopContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||
ProcessListContainerFunc func(ctx context.Context, sandboxID, containerID string, options vc.ProcessListOptions) (vc.ProcessList, error)
|
||||
UpdateContainerFunc func(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error
|
||||
PauseContainerFunc func(ctx context.Context, sandboxID, containerID string) error
|
||||
ResumeContainerFunc func(ctx context.Context, sandboxID, containerID string) error
|
||||
|
||||
AddDeviceFunc func(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error)
|
||||
|
||||
AddInterfaceFunc func(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
RemoveInterfaceFunc func(ctx context.Context, sandboxID string, inf *pbTypes.Interface) (*pbTypes.Interface, error)
|
||||
ListInterfacesFunc func(ctx context.Context, sandboxID string) ([]*pbTypes.Interface, error)
|
||||
UpdateRoutesFunc func(ctx context.Context, sandboxID string, routes []*pbTypes.Route) ([]*pbTypes.Route, error)
|
||||
ListRoutesFunc func(ctx context.Context, sandboxID string) ([]*pbTypes.Route, error)
|
||||
CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user