From 9d73826e6fd7327689ead6f64c62eebe95421ea3 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Mon, 13 Aug 2018 21:32:50 -0700 Subject: [PATCH] Proposed refactoring of test mocks The changes one of the test client mocks from using a function pointer based model to a derived type model. Signed-off-by: Daniel Hiltgen --- internal/containerizedengine/client_test.go | 43 +--- .../containerizedengine/containerd_test.go | 23 ++- internal/containerizedengine/engine_test.go | 185 +++++++++--------- internal/containerizedengine/update_test.go | 154 ++++++++------- 4 files changed, 197 insertions(+), 208 deletions(-) diff --git a/internal/containerizedengine/client_test.go b/internal/containerizedengine/client_test.go index 9c2b4aa8b290..ba917a1ab509 100644 --- a/internal/containerizedengine/client_test.go +++ b/internal/containerizedengine/client_test.go @@ -18,15 +18,8 @@ import ( ) type ( - fakeContainerdClient struct { - containersFunc func(ctx context.Context, filters ...string) ([]containerd.Container, error) - newContainerFunc func(ctx context.Context, id string, opts ...containerd.NewContainerOpts) (containerd.Container, error) - pullFunc func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) - getImageFunc func(ctx context.Context, ref string) (containerd.Image, error) - contentStoreFunc func() content.Store - containerServiceFunc func() containers.Store - } - fakeContainer struct { + testContainerdClient struct{} + fakeContainer struct { idFunc func() string infoFunc func(context.Context) (containers.Container, error) deleteFunc func(context.Context, ...containerd.DeleteOpts) error @@ -75,43 +68,25 @@ type ( } ) -func (w *fakeContainerdClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { - if w.containersFunc != nil { - return w.containersFunc(ctx, filters...) - } +func (w *testContainerdClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { return []containerd.Container{}, nil } -func (w *fakeContainerdClient) NewContainer(ctx context.Context, id string, opts ...containerd.NewContainerOpts) (containerd.Container, error) { - if w.newContainerFunc != nil { - return w.newContainerFunc(ctx, id, opts...) - } +func (w *testContainerdClient) NewContainer(ctx context.Context, id string, opts ...containerd.NewContainerOpts) (containerd.Container, error) { return nil, nil } -func (w *fakeContainerdClient) Pull(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { - if w.pullFunc != nil { - return w.pullFunc(ctx, ref, opts...) - } +func (w *testContainerdClient) Pull(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { return nil, nil } -func (w *fakeContainerdClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { - if w.getImageFunc != nil { - return w.getImageFunc(ctx, ref) - } +func (w *testContainerdClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { return nil, nil } -func (w *fakeContainerdClient) ContentStore() content.Store { - if w.contentStoreFunc != nil { - return w.contentStoreFunc() - } +func (w *testContainerdClient) ContentStore() content.Store { return nil } -func (w *fakeContainerdClient) ContainerService() containers.Store { - if w.containerServiceFunc != nil { - return w.containerServiceFunc() - } +func (w *testContainerdClient) ContainerService() containers.Store { return nil } -func (w *fakeContainerdClient) Close() error { +func (w *testContainerdClient) Close() error { return nil } diff --git a/internal/containerizedengine/containerd_test.go b/internal/containerizedengine/containerd_test.go index 1b48c77bc116..9cee019eca21 100644 --- a/internal/containerizedengine/containerd_test.go +++ b/internal/containerizedengine/containerd_test.go @@ -10,15 +10,19 @@ import ( "gotest.tools/assert" ) +type localTestPullWithAuthPullFailClient struct { + testContainerdClient +} + +func (c *localTestPullWithAuthPullFailClient) Pull(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { + return nil, fmt.Errorf("pull failure") +} + func TestPullWithAuthPullFail(t *testing.T) { ctx := context.Background() - client := baseClient{ - cclient: &fakeContainerdClient{ - pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { - return nil, fmt.Errorf("pull failure") - }, - }, + client := baseClient{ + cclient: &localTestPullWithAuthPullFailClient{}, } imageName := "testnamegoeshere" @@ -29,12 +33,7 @@ func TestPullWithAuthPullFail(t *testing.T) { func TestPullWithAuthPullPass(t *testing.T) { ctx := context.Background() client := baseClient{ - cclient: &fakeContainerdClient{ - pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { - return nil, nil - - }, - }, + cclient: &testContainerdClient{}, } imageName := "testnamegoeshere" diff --git a/internal/containerizedengine/engine_test.go b/internal/containerizedengine/engine_test.go index 8e6a8d2147bd..0748caef96ef 100644 --- a/internal/containerizedengine/engine_test.go +++ b/internal/containerizedengine/engine_test.go @@ -23,6 +23,15 @@ func healthfnError(ctx context.Context) error { return fmt.Errorf("ping failure") } +type localClientWithGetContainer struct { + testContainerdClient + container *fakeContainer +} + +func (c *localClientWithGetContainer) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return []containerd.Container{c.container}, nil +} + func TestInitGetEngineFail(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -31,19 +40,26 @@ func TestInitGetEngineFail(t *testing.T) { ConfigFile: "/tmp/configfilegoeshere", EngineImage: CommunityEngineImage, } - container := &fakeContainer{} client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: &fakeContainer{}}, } err := client.InitEngine(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) assert.Assert(t, err == ErrEngineAlreadyPresent) } +type localTestInitCheckImageFailClient struct { + testContainerdClient +} + +func (c *localTestInitCheckImageFailClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return []containerd.Container{}, nil +} + +func (c *localTestInitCheckImageFailClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, fmt.Errorf("something went wrong") +} + func TestInitCheckImageFail(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -53,15 +69,7 @@ func TestInitCheckImageFail(t *testing.T) { EngineImage: CommunityEngineImage, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, fmt.Errorf("something went wrong") - - }, - }, + cclient: &localTestInitCheckImageFailClient{}, } err := client.InitEngine(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) @@ -69,6 +77,18 @@ func TestInitCheckImageFail(t *testing.T) { assert.ErrorContains(t, err, "something went wrong") } +type localTestInitPullFailClient struct { + localTestInitCheckImageFailClient +} + +func (c *localTestInitPullFailClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, errdefs.ErrNotFound +} + +func (c *localTestInitPullFailClient) Pull(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { + return nil, fmt.Errorf("pull failure") +} + func TestInitPullFail(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -78,18 +98,7 @@ func TestInitPullFail(t *testing.T) { EngineImage: CommunityEngineImage, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, errdefs.ErrNotFound - - }, - pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { - return nil, fmt.Errorf("pull failure") - }, - }, + cclient: &localTestInitPullFailClient{}, } err := client.InitEngine(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) @@ -97,6 +106,14 @@ func TestInitPullFail(t *testing.T) { assert.ErrorContains(t, err, "pull failure") } +type localTestInitStartFailClient struct { + localTestInitPullFailClient +} + +func (c *localTestInitStartFailClient) Pull(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { + return nil, nil +} + func TestInitStartFail(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -106,46 +123,43 @@ func TestInitStartFail(t *testing.T) { EngineImage: CommunityEngineImage, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, errdefs.ErrNotFound - - }, - pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { - return nil, nil - }, - }, + cclient: &localTestInitStartFailClient{}, } err := client.InitEngine(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) assert.ErrorContains(t, err, "failed to create docker daemon") } +type localTestGetEngineFailClient struct { + testContainerdClient +} + +func (c *localTestGetEngineFailClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return nil, fmt.Errorf("container failure") +} + func TestGetEngineFail(t *testing.T) { ctx := context.Background() client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return nil, fmt.Errorf("container failure") - }, - }, + cclient: &localTestGetEngineFailClient{}, } _, err := client.GetEngine(ctx) assert.ErrorContains(t, err, "failure") } +type localClientNoContainers struct { + testContainerdClient +} + +func (c *localClientNoContainers) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return []containerd.Container{}, nil +} + func TestGetEngineNotPresent(t *testing.T) { ctx := context.Background() client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - }, + cclient: &localClientNoContainers{}, } _, err := client.GetEngine(ctx) @@ -156,11 +170,7 @@ func TestGetEngineFound(t *testing.T) { ctx := context.Background() container := &fakeContainer{} client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } c, err := client.GetEngine(ctx) @@ -203,11 +213,7 @@ func TestWaitForEngineNeverShowsUp(t *testing.T) { defer cancel() engineWaitInterval = 1 * time.Millisecond client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - }, + cclient: &localClientNoContainers{}, } err := client.waitForEngine(ctx, &testOutStream{}, healthfnError) @@ -220,11 +226,7 @@ func TestWaitForEnginePingFail(t *testing.T) { engineWaitInterval = 1 * time.Millisecond container := &fakeContainer{} client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } err := client.waitForEngine(ctx, &testOutStream{}, healthfnError) @@ -237,11 +239,7 @@ func TestWaitForEngineHealthy(t *testing.T) { engineWaitInterval = 1 * time.Millisecond container := &fakeContainer{} client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } err := client.waitForEngine(ctx, &testOutStream{}, healthfnHappy) @@ -393,38 +391,53 @@ func TestRemoveEngineTaskKillTimeout(t *testing.T) { assert.Assert(t, err == ErrEngineShutdownTimeout) } +type localTestStartEngineOnContainerdImageErrClient struct { + testContainerdClient +} + +func (c *localTestStartEngineOnContainerdImageErrClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, fmt.Errorf("some image lookup failure") +} + func TestStartEngineOnContainerdImageErr(t *testing.T) { ctx := context.Background() imageName := "testnamegoeshere" configFile := "/tmp/configfilegoeshere" client := baseClient{ - cclient: &fakeContainerdClient{ - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, fmt.Errorf("some image lookup failure") - - }, - }, + cclient: &localTestStartEngineOnContainerdImageErrClient{}, } err := client.startEngineOnContainerd(ctx, imageName, configFile) assert.ErrorContains(t, err, "some image lookup failure") } +type localTestStartEngineOnContainerdImageNotFoundClient struct { + testContainerdClient +} + +func (c *localTestStartEngineOnContainerdImageNotFoundClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, errdefs.ErrNotFound +} + func TestStartEngineOnContainerdImageNotFound(t *testing.T) { ctx := context.Background() imageName := "testnamegoeshere" configFile := "/tmp/configfilegoeshere" client := baseClient{ - cclient: &fakeContainerdClient{ - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, errdefs.ErrNotFound - - }, - }, + cclient: &localTestStartEngineOnContainerdImageNotFoundClient{}, } err := client.startEngineOnContainerd(ctx, imageName, configFile) assert.ErrorContains(t, err, "engine image missing") } +type localClientWithNewContainer struct { + testContainerdClient + container *fakeContainer +} + +func (c *localClientWithNewContainer) NewContainer(ctx context.Context, id string, opts ...containerd.NewContainerOpts) (containerd.Container, error) { + return c.container, nil +} + func TestStartEngineOnContainerdHappy(t *testing.T) { ctx := context.Background() imageName := "testnamegoeshere" @@ -449,15 +462,7 @@ func TestStartEngineOnContainerdHappy(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, nil - - }, - newContainerFunc: func(ctx context.Context, id string, opts ...containerd.NewContainerOpts) (containerd.Container, error) { - return container, nil - }, - }, + cclient: &localClientWithNewContainer{container: container}, } err := client.startEngineOnContainerd(ctx, imageName, configFile) assert.NilError(t, err) diff --git a/internal/containerizedengine/update_test.go b/internal/containerizedengine/update_test.go index 2eb1a416b2c8..906ea918e951 100644 --- a/internal/containerizedengine/update_test.go +++ b/internal/containerizedengine/update_test.go @@ -25,11 +25,7 @@ func TestGetCurrentEngineVersionHappy(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } opts, err := client.GetCurrentEngineVersion(ctx) @@ -52,11 +48,7 @@ func TestGetCurrentEngineVersionEnterpriseHappy(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } opts, err := client.GetCurrentEngineVersion(ctx) @@ -66,28 +58,39 @@ func TestGetCurrentEngineVersionEnterpriseHappy(t *testing.T) { assert.Equal(t, opts.RegistryPrefix, "docker.io/docker") } +type localTestGetCurrentEngineVersionNoEngineClient struct { + testContainerdClient +} + +func (c *localTestGetCurrentEngineVersionNoEngineClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return []containerd.Container{}, nil +} + func TestGetCurrentEngineVersionNoEngine(t *testing.T) { ctx := context.Background() client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - }, + cclient: &localTestGetCurrentEngineVersionNoEngineClient{}, } _, err := client.GetCurrentEngineVersion(ctx) assert.ErrorContains(t, err, "failed to find existing engine") } +type localTestGetCurrentEngineVersionMiscEngineErrorClient struct { + testContainerdClient + expectedError error +} + +func (c *localTestGetCurrentEngineVersionMiscEngineErrorClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return nil, c.expectedError +} + func TestGetCurrentEngineVersionMiscEngineError(t *testing.T) { ctx := context.Background() expectedError := fmt.Errorf("some container lookup error") client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return nil, expectedError - }, + cclient: &localTestGetCurrentEngineVersionMiscEngineErrorClient{ + expectedError: expectedError, }, } @@ -103,11 +106,7 @@ func TestGetCurrentEngineVersionImageFailure(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } _, err := client.GetCurrentEngineVersion(ctx) @@ -127,25 +126,25 @@ func TestGetCurrentEngineVersionMalformed(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } _, err := client.GetCurrentEngineVersion(ctx) assert.Assert(t, err == ErrEngineImageMissingTag) } +type localTestActivateNoEngineClient struct { + testContainerdClient +} + +func (c *localTestActivateNoEngineClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return []containerd.Container{}, nil +} + func TestActivateNoEngine(t *testing.T) { ctx := context.Background() client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - }, + cclient: &localTestActivateNoEngineClient{}, } opts := EngineInitOptions{ EngineVersion: "engineversiongoeshere", @@ -175,11 +174,7 @@ func TestActivateNoChange(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - }, + cclient: &localClientWithGetContainer{container: container}, } opts := EngineInitOptions{ EngineVersion: "engineversiongoeshere", @@ -192,6 +187,20 @@ func TestActivateNoChange(t *testing.T) { assert.NilError(t, err) } +type localTestActivateDoUpdateFailClient struct { + testContainerdClient + container *fakeContainer +} + +func (c *localTestActivateDoUpdateFailClient) Containers(ctx context.Context, filters ...string) ([]containerd.Container, error) { + return []containerd.Container{c.container}, nil +} + +func (c *localTestActivateDoUpdateFailClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, fmt.Errorf("something went wrong") + +} + func TestActivateDoUpdateFail(t *testing.T) { ctx := context.Background() registryPrefix := "registryprefixgoeshere" @@ -206,15 +215,7 @@ func TestActivateDoUpdateFail(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{container}, nil - }, - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, fmt.Errorf("something went wrong") - - }, - }, + cclient: &localTestActivateDoUpdateFailClient{container: container}, } opts := EngineInitOptions{ EngineVersion: "engineversiongoeshere", @@ -241,6 +242,15 @@ func TestDoUpdateNoVersion(t *testing.T) { assert.ErrorContains(t, err, "please pick the version you") } +type localTestDoUpdateImageMiscErrorClient struct { + testContainerdClient +} + +func (c *localTestDoUpdateImageMiscErrorClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, fmt.Errorf("something went wrong") + +} + func TestDoUpdateImageMiscError(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -250,18 +260,25 @@ func TestDoUpdateImageMiscError(t *testing.T) { EngineImage: "testnamegoeshere", } client := baseClient{ - cclient: &fakeContainerdClient{ - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, fmt.Errorf("something went wrong") - - }, - }, + cclient: &localTestDoUpdateImageMiscErrorClient{}, } err := client.DoUpdate(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) assert.ErrorContains(t, err, "check for image") assert.ErrorContains(t, err, "something went wrong") } +type localTestDoUpdatePullFailClient struct { + testContainerdClient +} + +func (c *localTestDoUpdatePullFailClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return nil, errdefs.ErrNotFound +} + +func (c *localTestDoUpdatePullFailClient) Pull(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { + return nil, fmt.Errorf("pull failure") +} + func TestDoUpdatePullFail(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -271,21 +288,22 @@ func TestDoUpdatePullFail(t *testing.T) { EngineImage: "testnamegoeshere", } client := baseClient{ - cclient: &fakeContainerdClient{ - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return nil, errdefs.ErrNotFound - - }, - pullFunc: func(ctx context.Context, ref string, opts ...containerd.RemoteOpt) (containerd.Image, error) { - return nil, fmt.Errorf("pull failure") - }, - }, + cclient: &localTestDoUpdatePullFailClient{}, } err := client.DoUpdate(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) assert.ErrorContains(t, err, "unable to pull") assert.ErrorContains(t, err, "pull failure") } +type localTestDoUpdateEngineMissingClient struct { + testContainerdClient + image *fakeImage +} + +func (c *localTestDoUpdateEngineMissingClient) GetImage(ctx context.Context, ref string) (containerd.Image, error) { + return c.image, nil +} + func TestDoUpdateEngineMissing(t *testing.T) { ctx := context.Background() opts := EngineInitOptions{ @@ -300,15 +318,7 @@ func TestDoUpdateEngineMissing(t *testing.T) { }, } client := baseClient{ - cclient: &fakeContainerdClient{ - getImageFunc: func(ctx context.Context, ref string) (containerd.Image, error) { - return image, nil - - }, - containersFunc: func(ctx context.Context, filters ...string) ([]containerd.Container, error) { - return []containerd.Container{}, nil - }, - }, + cclient: &localTestDoUpdateEngineMissingClient{image: image}, } err := client.DoUpdate(ctx, opts, &testOutStream{}, &types.AuthConfig{}, healthfnHappy) assert.ErrorContains(t, err, "unable to find existing engine")