From d1cb7d41c237dd72d8a3f4476687be3f3bd363d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Thu, 20 Jun 2024 14:53:23 +0200 Subject: [PATCH] cli/command: Don't copy fakeClient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The embedded `client.Client` has mutexes and it shouldn't be copied. Signed-off-by: Paweł Gronowski --- cli/command/container/exec_test.go | 9 +++++---- cli/command/container/logs_test.go | 6 +++--- cli/command/registry/login_test.go | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cli/command/container/exec_test.go b/cli/command/container/exec_test.go index fb8c5c7467..ed34e4777f 100644 --- a/cli/command/container/exec_test.go +++ b/cli/command/container/exec_test.go @@ -162,7 +162,7 @@ func TestRunExec(t *testing.T) { testcases := []struct { doc string options ExecOptions - client fakeClient + client *fakeClient expectedError string expectedOut string expectedErr string @@ -172,12 +172,12 @@ func TestRunExec(t *testing.T) { options: withDefaultOpts(ExecOptions{ Detach: true, }), - client: fakeClient{execCreateFunc: execCreateWithID}, + client: &fakeClient{execCreateFunc: execCreateWithID}, }, { doc: "inspect error", options: NewExecOptions(), - client: fakeClient{ + client: &fakeClient{ inspectFunc: func(string) (types.ContainerJSON, error) { return types.ContainerJSON{}, errors.New("failed inspect") }, @@ -188,12 +188,13 @@ func TestRunExec(t *testing.T) { doc: "missing exec ID", options: NewExecOptions(), expectedError: "exec ID empty", + client: &fakeClient{}, }, } for _, testcase := range testcases { t.Run(testcase.doc, func(t *testing.T) { - fakeCLI := test.NewFakeCli(&testcase.client) + fakeCLI := test.NewFakeCli(testcase.client) err := RunExec(context.TODO(), fakeCLI, "thecontainer", testcase.options) if testcase.expectedError != "" { diff --git a/cli/command/container/logs_test.go b/cli/command/container/logs_test.go index e1d238e6f9..4a27cfaf5d 100644 --- a/cli/command/container/logs_test.go +++ b/cli/command/container/logs_test.go @@ -30,7 +30,7 @@ func TestRunLogs(t *testing.T) { testcases := []struct { doc string options *logsOptions - client fakeClient + client *fakeClient expectedError string expectedOut string expectedErr string @@ -39,13 +39,13 @@ func TestRunLogs(t *testing.T) { doc: "successful logs", expectedOut: "foo", options: &logsOptions{}, - client: fakeClient{logFunc: logFn("foo"), inspectFunc: inspectFn}, + client: &fakeClient{logFunc: logFn("foo"), inspectFunc: inspectFn}, }, } for _, testcase := range testcases { t.Run(testcase.doc, func(t *testing.T) { - cli := test.NewFakeCli(&testcase.client) + cli := test.NewFakeCli(testcase.client) err := runLogs(context.TODO(), cli, testcase.options) if testcase.expectedError != "" { diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index db88af3117..9d87ad7667 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -29,11 +29,11 @@ type fakeClient struct { client.Client } -func (c fakeClient) Info(context.Context) (system.Info, error) { +func (c *fakeClient) Info(context.Context) (system.Info, error) { return system.Info{}, nil } -func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { +func (c *fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { if auth.Password == expiredPassword { return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password") }