cli/command: Don't copy fakeClient

The embedded `client.Client` has mutexes and it shouldn't be copied.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2024-06-20 14:53:23 +02:00
parent 34d42bdf0c
commit d1cb7d41c2
No known key found for this signature in database
GPG Key ID: B85EFCFE26DEF92A
3 changed files with 10 additions and 9 deletions

View File

@ -162,7 +162,7 @@ func TestRunExec(t *testing.T) {
testcases := []struct { testcases := []struct {
doc string doc string
options ExecOptions options ExecOptions
client fakeClient client *fakeClient
expectedError string expectedError string
expectedOut string expectedOut string
expectedErr string expectedErr string
@ -172,12 +172,12 @@ func TestRunExec(t *testing.T) {
options: withDefaultOpts(ExecOptions{ options: withDefaultOpts(ExecOptions{
Detach: true, Detach: true,
}), }),
client: fakeClient{execCreateFunc: execCreateWithID}, client: &fakeClient{execCreateFunc: execCreateWithID},
}, },
{ {
doc: "inspect error", doc: "inspect error",
options: NewExecOptions(), options: NewExecOptions(),
client: fakeClient{ client: &fakeClient{
inspectFunc: func(string) (types.ContainerJSON, error) { inspectFunc: func(string) (types.ContainerJSON, error) {
return types.ContainerJSON{}, errors.New("failed inspect") return types.ContainerJSON{}, errors.New("failed inspect")
}, },
@ -188,12 +188,13 @@ func TestRunExec(t *testing.T) {
doc: "missing exec ID", doc: "missing exec ID",
options: NewExecOptions(), options: NewExecOptions(),
expectedError: "exec ID empty", expectedError: "exec ID empty",
client: &fakeClient{},
}, },
} }
for _, testcase := range testcases { for _, testcase := range testcases {
t.Run(testcase.doc, func(t *testing.T) { 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) err := RunExec(context.TODO(), fakeCLI, "thecontainer", testcase.options)
if testcase.expectedError != "" { if testcase.expectedError != "" {

View File

@ -30,7 +30,7 @@ func TestRunLogs(t *testing.T) {
testcases := []struct { testcases := []struct {
doc string doc string
options *logsOptions options *logsOptions
client fakeClient client *fakeClient
expectedError string expectedError string
expectedOut string expectedOut string
expectedErr string expectedErr string
@ -39,13 +39,13 @@ func TestRunLogs(t *testing.T) {
doc: "successful logs", doc: "successful logs",
expectedOut: "foo", expectedOut: "foo",
options: &logsOptions{}, options: &logsOptions{},
client: fakeClient{logFunc: logFn("foo"), inspectFunc: inspectFn}, client: &fakeClient{logFunc: logFn("foo"), inspectFunc: inspectFn},
}, },
} }
for _, testcase := range testcases { for _, testcase := range testcases {
t.Run(testcase.doc, func(t *testing.T) { 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) err := runLogs(context.TODO(), cli, testcase.options)
if testcase.expectedError != "" { if testcase.expectedError != "" {

View File

@ -29,11 +29,11 @@ type fakeClient struct {
client.Client client.Client
} }
func (c fakeClient) Info(context.Context) (system.Info, error) { func (c *fakeClient) Info(context.Context) (system.Info, error) {
return system.Info{}, nil 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 { if auth.Password == expiredPassword {
return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password") return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password")
} }