mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 04:34:27 +00:00
vc: fix up UT for CreateSandbox API change
Need to adapt the UT as well. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
578a9c25f0
commit
d085389127
@ -41,7 +41,7 @@ func TestCreateSandboxSuccess(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) {
|
||||||
return sandbox, nil
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ func TestCreateSandboxAnnotations(t *testing.T) {
|
|||||||
|
|
||||||
rootFs := vc.RootFs{Mounted: true}
|
rootFs := vc.RootFs{Mounted: true}
|
||||||
|
|
||||||
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
testingImpl.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) {
|
||||||
return &vcmock.Sandbox{
|
return &vcmock.Sandbox{
|
||||||
MockID: testSandboxID,
|
MockID: testSandboxID,
|
||||||
MockContainers: []*vcmock.Container{
|
MockContainers: []*vcmock.Container{
|
||||||
|
@ -145,7 +145,7 @@ func TestCreateSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
config := newTestSandboxConfigNoop()
|
config := newTestSandboxConfigNoop()
|
||||||
|
|
||||||
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
||||||
p, err := CreateSandbox(ctx, config, nil)
|
p, err := CreateSandbox(ctx, config, nil, nil)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
@ -178,7 +178,7 @@ func TestCreateSandboxKataAgentSuccessful(t *testing.T) {
|
|||||||
defer hybridVSockTTRPCMock.Stop()
|
defer hybridVSockTTRPCMock.Stop()
|
||||||
|
|
||||||
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
||||||
p, err := CreateSandbox(ctx, config, nil)
|
p, err := CreateSandbox(ctx, config, nil, nil)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(p)
|
assert.NotNil(p)
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ func TestCreateSandboxFailing(t *testing.T) {
|
|||||||
config := SandboxConfig{}
|
config := SandboxConfig{}
|
||||||
|
|
||||||
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
||||||
p, err := CreateSandbox(ctx, config, nil)
|
p, err := CreateSandbox(ctx, config, nil, nil)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.Nil(p.(*Sandbox))
|
assert.Nil(p.(*Sandbox))
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox V
|
|||||||
err error) {
|
err error) {
|
||||||
|
|
||||||
// Create sandbox
|
// Create sandbox
|
||||||
sandbox, err = CreateSandbox(ctx, config, nil)
|
sandbox, err = CreateSandbox(ctx, config, nil, nil)
|
||||||
if sandbox == nil || err != nil {
|
if sandbox == nil || err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
@ -260,7 +260,7 @@ func TestReleaseSandbox(t *testing.T) {
|
|||||||
config := newTestSandboxConfigNoop()
|
config := newTestSandboxConfigNoop()
|
||||||
|
|
||||||
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
ctx := WithNewAgentFunc(context.Background(), newMockAgent)
|
||||||
s, err := CreateSandbox(ctx, config, nil)
|
s, err := CreateSandbox(ctx, config, nil, nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, s)
|
assert.NotNil(t, s)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ func Example_createAndStartSandbox() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the sandbox
|
// Create the sandbox
|
||||||
s, err := vc.CreateSandbox(context.Background(), sandboxConfig, nil)
|
s, err := vc.CreateSandbox(context.Background(), sandboxConfig, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Could not create sandbox: %s", err)
|
fmt.Printf("Could not create sandbox: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -42,9 +42,9 @@ func (m *VCMock) SetFactory(ctx context.Context, factory vc.Factory) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateSandbox implements the VC function of the same name.
|
// CreateSandbox implements the VC function of the same name.
|
||||||
func (m *VCMock) CreateSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
func (m *VCMock) CreateSandbox(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) {
|
||||||
if m.CreateSandboxFunc != nil {
|
if m.CreateSandboxFunc != nil {
|
||||||
return m.CreateSandboxFunc(ctx, sandboxConfig)
|
return m.CreateSandboxFunc(ctx, sandboxConfig, hookFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig)
|
return nil, fmt.Errorf("%s: %s (%+v): sandboxConfig: %v", mockErrorPrefix, getSelf(), m, sandboxConfig)
|
||||||
|
@ -120,22 +120,22 @@ func TestVCMockCreateSandbox(t *testing.T) {
|
|||||||
assert.Nil(m.CreateSandboxFunc)
|
assert.Nil(m.CreateSandboxFunc)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err := m.CreateSandbox(ctx, vc.SandboxConfig{})
|
_, err := m.CreateSandbox(ctx, vc.SandboxConfig{}, nil)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(IsMockError(err))
|
assert.True(IsMockError(err))
|
||||||
|
|
||||||
m.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error) {
|
m.CreateSandboxFunc = func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error) {
|
||||||
return &Sandbox{}, nil
|
return &Sandbox{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox, err := m.CreateSandbox(ctx, vc.SandboxConfig{})
|
sandbox, err := m.CreateSandbox(ctx, vc.SandboxConfig{}, nil)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(sandbox, &Sandbox{})
|
assert.Equal(sandbox, &Sandbox{})
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
m.CreateSandboxFunc = nil
|
m.CreateSandboxFunc = nil
|
||||||
|
|
||||||
_, err = m.CreateSandbox(ctx, vc.SandboxConfig{})
|
_, err = m.CreateSandbox(ctx, vc.SandboxConfig{}, nil)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(IsMockError(err))
|
assert.True(IsMockError(err))
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,6 @@ type VCMock struct {
|
|||||||
SetLoggerFunc func(ctx context.Context, logger *logrus.Entry)
|
SetLoggerFunc func(ctx context.Context, logger *logrus.Entry)
|
||||||
SetFactoryFunc func(ctx context.Context, factory vc.Factory)
|
SetFactoryFunc func(ctx context.Context, factory vc.Factory)
|
||||||
|
|
||||||
CreateSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
CreateSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig, hookFunc func(context.Context) error) (vc.VCSandbox, error)
|
||||||
CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error
|
CleanupContainerFunc func(ctx context.Context, sandboxID, containerID string, force bool) error
|
||||||
}
|
}
|
||||||
|
@ -1348,7 +1348,7 @@ func TestSandboxCreationFromConfigRollbackFromCreateSandbox(t *testing.T) {
|
|||||||
// Ensure hypervisor doesn't exist
|
// Ensure hypervisor doesn't exist
|
||||||
assert.NoError(os.Remove(hConf.HypervisorPath))
|
assert.NoError(os.Remove(hConf.HypervisorPath))
|
||||||
|
|
||||||
_, err := createSandboxFromConfig(ctx, sConf, nil)
|
_, err := createSandboxFromConfig(ctx, sConf, nil, nil)
|
||||||
// Fail at createSandbox: QEMU path does not exist, it is expected. Then rollback is called
|
// Fail at createSandbox: QEMU path does not exist, it is expected. Then rollback is called
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user