From 66c66bdce75569f6dae69d79335a05c0eaeae641 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 30 Mar 2023 16:14:47 +0200 Subject: [PATCH] cli/command/config: fakeClient: include context in fake client (revive) I could either remove the name for these contexts, or make the fake functions more accurately reflect the actual implementation (decided to go for the latter one) . cli/command/config/client_test.go:19:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) func (c *fakeClient) ConfigCreate(ctx context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { ^ cli/command/config/client_test.go:26:43: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) { ^ cli/command/config/client_test.go:33:33: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) func (c *fakeClient) ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { ^ cli/command/config/client_test.go:40:35: unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive) func (c *fakeClient) ConfigRemove(ctx context.Context, name string) error { ^ Signed-off-by: Sebastiaan van Stijn --- cli/command/config/client_test.go | 14 +++++++------- cli/command/config/create_test.go | 11 ++++++----- cli/command/config/inspect_test.go | 21 +++++++++++---------- cli/command/config/ls_test.go | 15 ++++++++------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/cli/command/config/client_test.go b/cli/command/config/client_test.go index 2e19b77521..c3c938a7be 100644 --- a/cli/command/config/client_test.go +++ b/cli/command/config/client_test.go @@ -10,34 +10,34 @@ import ( type fakeClient struct { client.Client - configCreateFunc func(swarm.ConfigSpec) (types.ConfigCreateResponse, error) - configInspectFunc func(string) (swarm.Config, []byte, error) - configListFunc func(types.ConfigListOptions) ([]swarm.Config, error) + configCreateFunc func(context.Context, swarm.ConfigSpec) (types.ConfigCreateResponse, error) + configInspectFunc func(context.Context, string) (swarm.Config, []byte, error) + configListFunc func(context.Context, types.ConfigListOptions) ([]swarm.Config, error) configRemoveFunc func(string) error } func (c *fakeClient) ConfigCreate(ctx context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if c.configCreateFunc != nil { - return c.configCreateFunc(spec) + return c.configCreateFunc(ctx, spec) } return types.ConfigCreateResponse{}, nil } func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) { if c.configInspectFunc != nil { - return c.configInspectFunc(id) + return c.configInspectFunc(ctx, id) } return swarm.Config{}, nil, nil } func (c *fakeClient) ConfigList(ctx context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { if c.configListFunc != nil { - return c.configListFunc(options) + return c.configListFunc(ctx, options) } return []swarm.Config{}, nil } -func (c *fakeClient) ConfigRemove(ctx context.Context, name string) error { +func (c *fakeClient) ConfigRemove(_ context.Context, name string) error { if c.configRemoveFunc != nil { return c.configRemoveFunc(name) } diff --git a/cli/command/config/create_test.go b/cli/command/config/create_test.go index 0d1f345788..a1c5e61899 100644 --- a/cli/command/config/create_test.go +++ b/cli/command/config/create_test.go @@ -1,6 +1,7 @@ package config import ( + "context" "io" "os" "path/filepath" @@ -22,7 +23,7 @@ const configDataFile = "config-create-with-name.golden" func TestConfigCreateErrors(t *testing.T) { testCases := []struct { args []string - configCreateFunc func(swarm.ConfigSpec) (types.ConfigCreateResponse, error) + configCreateFunc func(context.Context, swarm.ConfigSpec) (types.ConfigCreateResponse, error) expectedError string }{ { @@ -35,7 +36,7 @@ func TestConfigCreateErrors(t *testing.T) { }, { args: []string{"name", filepath.Join("testdata", configDataFile)}, - configCreateFunc: func(configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { + configCreateFunc: func(_ context.Context, configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { return types.ConfigCreateResponse{}, errors.Errorf("error creating config") }, expectedError: "error creating config", @@ -57,7 +58,7 @@ func TestConfigCreateWithName(t *testing.T) { name := "foo" var actual []byte cli := test.NewFakeCli(&fakeClient{ - configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { + configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if spec.Name != name { return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) } @@ -96,7 +97,7 @@ func TestConfigCreateWithLabels(t *testing.T) { } cli := test.NewFakeCli(&fakeClient{ - configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { + configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if !reflect.DeepEqual(spec, expected) { return types.ConfigCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec) } @@ -122,7 +123,7 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) { name := "foo" cli := test.NewFakeCli(&fakeClient{ - configCreateFunc: func(spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { + configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if spec.Name != name { return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) } diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index 523eba2acd..111f15bf82 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -1,6 +1,7 @@ package config import ( + "context" "fmt" "io" "testing" @@ -18,7 +19,7 @@ func TestConfigInspectErrors(t *testing.T) { testCases := []struct { args []string flags map[string]string - configInspectFunc func(configID string) (swarm.Config, []byte, error) + configInspectFunc func(_ context.Context, configID string) (swarm.Config, []byte, error) expectedError string }{ { @@ -26,7 +27,7 @@ func TestConfigInspectErrors(t *testing.T) { }, { args: []string{"foo"}, - configInspectFunc: func(configID string) (swarm.Config, []byte, error) { + configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) { return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") }, expectedError: "error while inspecting the config", @@ -40,7 +41,7 @@ func TestConfigInspectErrors(t *testing.T) { }, { args: []string{"foo", "bar"}, - configInspectFunc: func(configID string) (swarm.Config, []byte, error) { + configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) { if configID == "foo" { return *Config(ConfigName("foo")), nil, nil } @@ -68,12 +69,12 @@ func TestConfigInspectWithoutFormat(t *testing.T) { testCases := []struct { name string args []string - configInspectFunc func(configID string) (swarm.Config, []byte, error) + configInspectFunc func(_ context.Context, configID string) (swarm.Config, []byte, error) }{ { name: "single-config", args: []string{"foo"}, - configInspectFunc: func(name string) (swarm.Config, []byte, error) { + configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) { if name != "foo" { return swarm.Config{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name) } @@ -83,7 +84,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) { { name: "multiple-configs-with-labels", args: []string{"foo", "bar"}, - configInspectFunc: func(name string) (swarm.Config, []byte, error) { + configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) { return *Config(ConfigID("ID-"+name), ConfigName(name), ConfigLabels(map[string]string{ "label1": "label-foo", })), nil, nil @@ -100,7 +101,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) { } func TestConfigInspectWithFormat(t *testing.T) { - configInspectFunc := func(name string) (swarm.Config, []byte, error) { + configInspectFunc := func(_ context.Context, name string) (swarm.Config, []byte, error) { return *Config(ConfigName("foo"), ConfigLabels(map[string]string{ "label1": "label-foo", })), nil, nil @@ -109,7 +110,7 @@ func TestConfigInspectWithFormat(t *testing.T) { name string format string args []string - configInspectFunc func(name string) (swarm.Config, []byte, error) + configInspectFunc func(_ context.Context, name string) (swarm.Config, []byte, error) }{ { name: "simple-template", @@ -139,11 +140,11 @@ func TestConfigInspectWithFormat(t *testing.T) { func TestConfigInspectPretty(t *testing.T) { testCases := []struct { name string - configInspectFunc func(string) (swarm.Config, []byte, error) + configInspectFunc func(context.Context, string) (swarm.Config, []byte, error) }{ { name: "simple", - configInspectFunc: func(id string) (swarm.Config, []byte, error) { + configInspectFunc: func(_ context.Context, id string) (swarm.Config, []byte, error) { return *Config( ConfigLabels(map[string]string{ "lbl1": "value1", diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index 116c41bf5c..d21c2e4905 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -1,6 +1,7 @@ package config import ( + "context" "io" "testing" "time" @@ -19,7 +20,7 @@ import ( func TestConfigListErrors(t *testing.T) { testCases := []struct { args []string - configListFunc func(types.ConfigListOptions) ([]swarm.Config, error) + configListFunc func(context.Context, types.ConfigListOptions) ([]swarm.Config, error) expectedError string }{ { @@ -27,7 +28,7 @@ func TestConfigListErrors(t *testing.T) { expectedError: "accepts no argument", }, { - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{}, errors.Errorf("error listing configs") }, expectedError: "error listing configs", @@ -47,7 +48,7 @@ func TestConfigListErrors(t *testing.T) { func TestConfigList(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *Config(ConfigID("ID-1-foo"), ConfigName("1-foo"), @@ -77,7 +78,7 @@ func TestConfigList(t *testing.T) { func TestConfigListWithQuietOption(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *Config(ConfigID("ID-foo"), ConfigName("foo")), *Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{ @@ -94,7 +95,7 @@ func TestConfigListWithQuietOption(t *testing.T) { func TestConfigListWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *Config(ConfigID("ID-foo"), ConfigName("foo")), *Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{ @@ -113,7 +114,7 @@ func TestConfigListWithConfigFormat(t *testing.T) { func TestConfigListWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ *Config(ConfigID("ID-foo"), ConfigName("foo")), *Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{ @@ -130,7 +131,7 @@ func TestConfigListWithFormat(t *testing.T) { func TestConfigListWithFilter(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ - configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { + configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0])) assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0])) return []swarm.Config{