From d85a3b265cfac6f637c90786e5f344549944b125 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 24 Oct 2019 16:28:51 +0200 Subject: [PATCH 01/63] gometalinter: fix configuration The configuration abused "Exclude" to exclude file-paths by filtering on the output, however, the `Skip` option was designed for that, whereas `Exclude` is for matching warnings. An explicit "Skip" was added for "vendor", because even though the vendor directory should already be ignored by the linter, in some situations, it still seemed to warn on issues, so let's explicitly ignore it. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 71e525f74fa9469832e7fedf40a4a93030563fe9) Signed-off-by: Sebastiaan van Stijn --- gometalinter.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gometalinter.json b/gometalinter.json index a31a6a20ef..647516ae87 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -2,12 +2,16 @@ "Vendor": true, "Deadline": "2m", "Sort": ["linter", "severity", "path", "line"], - "Exclude": [ + "Skip": [ "cli/compose/schema/bindata.go", "cli/command/stack/kubernetes/api/openapi", "cli/command/stack/kubernetes/api/client", ".*generated.*", - "parameter .* always receives" + "vendor" + ], + "Exclude": [ + "parameter .* always receives", + "_esc(Dir|FS|FSString|FSMustString) is unused" ], "EnableGC": true, "Linters": { From 3bc713c1572df5e76ddcaa80bd18a9c9dbd87b07 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 28 Oct 2019 12:49:41 +0100 Subject: [PATCH 02/63] Gometalinter: raise deadline to 3 minutes Looks like we're just on the edge of the deadline, and it's sometimes failing; ``` cli/command/image/trust.go:346:1:warning: nolint directive did not match any issue (nolint) cli/command/manifest/push.go:211:1:warning: nolint directive did not match any issue (nolint) internal/pkg/containerized/snapshot.go:95:1:warning: nolint directive did not match any issue (nolint) internal/pkg/containerized/snapshot.go:138:1:warning: nolint directive did not match any issue (nolint) WARNING: deadline exceeded by linter interfacer (try increasing --deadline) Exited with code 3 ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 3e78cbc021fd90958fabad5ef2bee122c2b36291) Signed-off-by: Sebastiaan van Stijn --- gometalinter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gometalinter.json b/gometalinter.json index 647516ae87..f2b2e8545d 100644 --- a/gometalinter.json +++ b/gometalinter.json @@ -1,6 +1,6 @@ { "Vendor": true, - "Deadline": "2m", + "Deadline": "3m", "Sort": ["linter", "severity", "path", "line"], "Skip": [ "cli/compose/schema/bindata.go", From b71d5e32cd0157711c69c881610da05720ac7359 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 09:59:48 +0100 Subject: [PATCH 03/63] compose/loader: fix TestIsAbs not testing all combinations This test was intending to run all tests, but didn't, which was caught by golangci-lint; cli/compose/loader/windows_path_test.go:46:17: SA4010: this result of append is never used, except maybe in other appends (staticcheck) tests := append(isabstests, winisabstests...) ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0a21de05d2c712439bf053dfb108b2930730d399) Signed-off-by: Sebastiaan van Stijn --- cli/compose/loader/windows_path_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cli/compose/loader/windows_path_test.go b/cli/compose/loader/windows_path_test.go index d612d41733..e3c821ee2f 100644 --- a/cli/compose/loader/windows_path_test.go +++ b/cli/compose/loader/windows_path_test.go @@ -43,7 +43,8 @@ var winisabstests = []IsAbsTest{ } func TestIsAbs(t *testing.T) { - tests := append(isabstests, winisabstests...) + tests := winisabstests + // All non-windows tests should fail, because they have no volume letter. for _, test := range isabstests { tests = append(tests, IsAbsTest{test.path, false}) @@ -53,7 +54,7 @@ func TestIsAbs(t *testing.T) { tests = append(tests, IsAbsTest{"c:" + test.path, test.isAbs}) } - for _, test := range winisabstests { + for _, test := range tests { if r := isAbs(test.path); r != test.isAbs { t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs) } From ad7bd8235f4c483dd237f35bdd486eba62179b28 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:07:11 +0200 Subject: [PATCH 04/63] opts/throttledevice.go:51:5: SA4003: unsigned values are never < 0 (staticcheck) Signed-off-by: Silvin Lubecki Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 296297190c55cee3b539c9b49ffa1c3708ed3e9b) Signed-off-by: Sebastiaan van Stijn --- opts/throttledevice.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/opts/throttledevice.go b/opts/throttledevice.go index 0959efae35..0bf5dd666f 100644 --- a/opts/throttledevice.go +++ b/opts/throttledevice.go @@ -48,9 +48,6 @@ func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error) { if err != nil { return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :. Number must be a positive integer", val) } - if rate < 0 { - return nil, fmt.Errorf("invalid rate for device: %s. The correct format is :. Number must be a positive integer", val) - } return &blkiodev.ThrottleDevice{Path: split[0], Rate: rate}, nil } From 1ed4e67b349c7b8642039522d287df7938958049 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:08:43 +0200 Subject: [PATCH 05/63] cli/command/trust/inspect_pretty_test.go:399:24: SA4010: this result of append is never used, except maybe in other appends (staticcheck) Signed-off-by: Silvin Lubecki (cherry picked from commit 8018a850cb5e6dbd9a2cf2ae4c291ab7c0d88473) Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/inspect_pretty_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cli/command/trust/inspect_pretty_test.go b/cli/command/trust/inspect_pretty_test.go index 13d436d168..d9ed38306a 100644 --- a/cli/command/trust/inspect_pretty_test.go +++ b/cli/command/trust/inspect_pretty_test.go @@ -393,11 +393,6 @@ func TestGetSignerRolesWithKeyIDs(t *testing.T) { "bob": {"key71", "key72"}, } - var roleWithSigs []client.RoleWithSignatures - for _, role := range roles { - roleWithSig := client.RoleWithSignatures{Role: role, Signatures: nil} - roleWithSigs = append(roleWithSigs, roleWithSig) - } signerRoleToKeyIDs := getDelegationRoleToKeyMap(roles) assert.Check(t, is.DeepEqual(expectedSignerRoleToKeyIDs, signerRoleToKeyIDs)) } From 49ff9c82dbb003f4bc5d7a38fc0e1a2c9860d679 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:11:36 +0200 Subject: [PATCH 06/63] cli/command/container/stats.go:211:21: SA1015: using time.Tick leaks the underlying ticker, consider using it only in endless functions, tests and the main package, and use time.NewTicker here (staticcheck) Signed-off-by: Silvin Lubecki (cherry picked from commit 7da9360477210b4f254741d41d66f0e70e8af267) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/stats.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index e8309e3324..95afccf5cb 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -208,7 +208,9 @@ func runStats(dockerCli command.Cli, opts *statsOptions) error { } var err error - for range time.Tick(500 * time.Millisecond) { + ticker := time.NewTicker(500 * time.Millisecond) + defer ticker.Stop() + for range ticker.C { cleanScreen() ccstats := []StatsEntry{} cStats.mu.Lock() From 60aa890a06cf3bfe10f6b0c3360a6e4ee763bf84 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:20:07 +0200 Subject: [PATCH 07/63] SA1019: httputil.ErrPersistEOF is deprecated: No longer used. (staticcheck) Signed-off-by: Silvin Lubecki (cherry picked from commit 3a428202bf1194681374cd34eee92f109e8a8ca7) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/attach.go | 6 +----- cli/command/container/run.go | 6 +----- cli/command/container/start.go | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index de96a3b7d8..f2bcfb0256 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net/http/httputil" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -103,10 +102,7 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error { } resp, errAttach := client.ContainerAttach(ctx, opts.container, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach returns an ErrPersistEOF (connection closed) - // means server met an error and put it in Hijacked connection - // keep the error and read detailed error message from hijacked connection later + if errAttach != nil { return errAttach } defer resp.Close() diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 3c87efec7d..e9c2ffe0eb 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net/http/httputil" "os" "runtime" "strings" @@ -248,10 +247,7 @@ func attachContainer( } resp, errAttach := dockerCli.Client().ContainerAttach(ctx, containerID, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach returns an ErrPersistEOF (connection closed) - // means server met an error and put it in Hijacked connection - // keep the error and read detailed error message from hijacked connection later + if errAttach != nil { return nil, errAttach } diff --git a/cli/command/container/start.go b/cli/command/container/start.go index e388302841..10661768ac 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "net/http/httputil" "strings" "github.com/docker/cli/cli" @@ -98,10 +97,7 @@ func runStart(dockerCli command.Cli, opts *startOptions) error { } resp, errAttach := dockerCli.Client().ContainerAttach(ctx, c.ID, options) - if errAttach != nil && errAttach != httputil.ErrPersistEOF { - // ContainerAttach return an ErrPersistEOF (connection closed) - // means server met an error and already put it in Hijacked connection, - // we would keep the error and read the detailed error message from hijacked connection + if errAttach != nil { return errAttach } defer resp.Close() From fe1a85f1e9724d6b0416dc32aa58c2243d727b8a Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:20:59 +0200 Subject: [PATCH 08/63] cli/command/trust/key_generate.go:112:9: nilness: impossible condition: nil != nil (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit f5e8387067a45cb519fb96a1840f61c82506fd20) Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/key_generate.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/command/trust/key_generate.go b/cli/command/trust/key_generate.go index 47223c3d9d..5e4661eafb 100644 --- a/cli/command/trust/key_generate.go +++ b/cli/command/trust/key_generate.go @@ -108,8 +108,7 @@ func generateKeyAndOutputPubPEM(keyName string, privKeyStore trustmanager.KeySto return pem.Block{}, err } - privKeyStore.AddKey(trustmanager.KeyInfo{Role: data.RoleName(keyName)}, privKey) - if err != nil { + if err := privKeyStore.AddKey(trustmanager.KeyInfo{Role: data.RoleName(keyName)}, privKey); err != nil { return pem.Block{}, err } From cdc9d1095bbc98fad480c72eb5a10312da385159 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:22:06 +0200 Subject: [PATCH 09/63] cli/command/stack/kubernetes/list.go:32:47: nilness: tautological condition: non-nil != nil (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit 85cfd4e518c7bf1349dc3f8c1d61a0e1f89d4cb7) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/kubernetes/list.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/stack/kubernetes/list.go b/cli/command/stack/kubernetes/list.go index 9706f4be56..facd401bb9 100644 --- a/cli/command/stack/kubernetes/list.go +++ b/cli/command/stack/kubernetes/list.go @@ -29,7 +29,7 @@ func GetStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) } func isAllNamespacesDisabled(kubeCliConfig *configfile.KubernetesConfig) bool { - return kubeCliConfig == nil || kubeCliConfig != nil && kubeCliConfig.AllNamespaces != "disabled" + return kubeCliConfig == nil || kubeCliConfig.AllNamespaces != "disabled" } func getStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) { From c83334119c3b6e19cee9cc2e23b2b914d86cb894 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:23:39 +0200 Subject: [PATCH 10/63] cli/command/container/start.go:157:20: nilness: nil dereference in type assertion (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit 9afeb6f4329b8cd6bca15fee5e5b25ade3bc89e6) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/container/start.go b/cli/command/container/start.go index 10661768ac..2693987fc5 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -150,7 +150,7 @@ func runStart(dockerCli command.Cli, opts *startOptions) error { } } if attachErr := <-cErr; attachErr != nil { - if _, ok := err.(term.EscapeError); ok { + if _, ok := attachErr.(term.EscapeError); ok { // The user entered the detach escape sequence. return nil } From 66b760d2b1dc27ca3079e5033b3709631bff3eb3 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:24:19 +0200 Subject: [PATCH 11/63] cli/registry/client/fetcher.go:106:9: nilness: impossible condition: nil != nil (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit 5ceed3059f340176fbe134c4d7bdfc577bb6db97) Signed-off-by: Sebastiaan van Stijn --- cli/registry/client/fetcher.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index e3d6cd6069..2060f99126 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -11,7 +11,7 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/reference" "github.com/docker/distribution/registry/api/errcode" - "github.com/docker/distribution/registry/api/v2" + v2 "github.com/docker/distribution/registry/api/v2" distclient "github.com/docker/distribution/registry/client" "github.com/docker/docker/registry" digest "github.com/opencontainers/go-digest" @@ -103,9 +103,6 @@ func pullManifestSchemaV2ImageConfig(ctx context.Context, dgst digest.Digest, re } verifier := dgst.Verifier() - if err != nil { - return nil, err - } if _, err := verifier.Write(configJSON); err != nil { return nil, err } From 0f72909216405c0d6e4ce1f9fd004fd6d92ed83e Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:25:13 +0200 Subject: [PATCH 12/63] cli/compose/types/types.go:106:2: structtag: struct field tag `yaml:",inline", json:"-"` not compatible with reflect.StructTag.Get: key:"value" pairs not separated by spaces (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit 1bfe81318df56128ba258f724078c3aafe3752bb) Signed-off-by: Sebastiaan van Stijn --- cli/compose/types/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/compose/types/types.go b/cli/compose/types/types.go index d77c1b63dc..2578b8cf00 100644 --- a/cli/compose/types/types.go +++ b/cli/compose/types/types.go @@ -103,7 +103,7 @@ type Config struct { Volumes map[string]VolumeConfig `yaml:",omitempty" json:"volumes,omitempty"` Secrets map[string]SecretConfig `yaml:",omitempty" json:"secrets,omitempty"` Configs map[string]ConfigObjConfig `yaml:",omitempty" json:"configs,omitempty"` - Extras map[string]interface{} `yaml:",inline", json:"-"` + Extras map[string]interface{} `yaml:",inline" json:"-"` } // MarshalJSON makes Config implement json.Marshaler From 7d9b95d7ec90af15ee41b63760d747d357ea9d15 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 11:26:29 +0200 Subject: [PATCH 13/63] opts/ulimit_test.go:11:13: composites: `*github.com/docker/cli/vendor/github.com/docker/go-units.Ulimit` composite literal uses unkeyed fields (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit b3d4c6aac796b240f8c43d808de8c7492a8eed27) Signed-off-by: Sebastiaan van Stijn --- opts/ulimit_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opts/ulimit_test.go b/opts/ulimit_test.go index 0aa3facdfb..8fc4d5c555 100644 --- a/opts/ulimit_test.go +++ b/opts/ulimit_test.go @@ -8,7 +8,7 @@ import ( func TestUlimitOpt(t *testing.T) { ulimitMap := map[string]*units.Ulimit{ - "nofile": {"nofile", 1024, 512}, + "nofile": {Name: "nofile", Hard: 1024, Soft: 512}, } ulimitOpt := NewUlimitOpt(&ulimitMap) From c8c14206aada921668d16bc267a1884adfb796d0 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:03:33 +0200 Subject: [PATCH 14/63] cli/command/container/attach.go:141:15: nilness: impossible condition: nil != nil (govet) Signed-off-by: Silvin Lubecki (cherry picked from commit 584da37756dd386a8b33cfa6b49eca3e555380a3) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/attach.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index f2bcfb0256..854aa73952 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -138,10 +138,6 @@ func runAttach(dockerCli command.Cli, opts *attachOptions) error { return err } - if errAttach != nil { - return errAttach - } - return getExitStatus(errC, resultC) } From 1f3468bb77ebd93a29cd637d8215eb6237f53338 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:03:49 +0200 Subject: [PATCH 15/63] unchecked errors Signed-off-by: Silvin Lubecki (cherry picked from commit e1c0c7979e018dcfa33df53806e0707fab35dadf) Signed-off-by: Sebastiaan van Stijn --- cli/command/registry/login_test.go | 2 +- cli/command/service/opts_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index 0f1374ddbc..f31ebd1716 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -166,7 +166,7 @@ func TestRunLogin(t *testing.T) { if tc.inputStoredCred != nil { cred := *tc.inputStoredCred - configfile.GetCredentialsStore(cred.ServerAddress).Store(cred) + assert.NilError(t, configfile.GetCredentialsStore(cred.ServerAddress).Store(cred)) } loginErr := runLogin(cli, tc.inputLoginOption) if tc.expectedErr != "" { diff --git a/cli/command/service/opts_test.go b/cli/command/service/opts_test.go index 6b9b83d186..8c27e9f026 100644 --- a/cli/command/service/opts_test.go +++ b/cli/command/service/opts_test.go @@ -202,9 +202,9 @@ func TestToServiceNetwork(t *testing.T) { } nwo := opts.NetworkOpt{} - nwo.Set("zzz-network") - nwo.Set("mmm-network") - nwo.Set("aaa-network") + assert.NilError(t, nwo.Set("zzz-network")) + assert.NilError(t, nwo.Set("mmm-network")) + assert.NilError(t, nwo.Set("aaa-network")) o := newServiceOptions() o.mode = "replicated" From 6f91e46b7b687699b37cd36ba7a5d263498afac9 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:06:49 +0200 Subject: [PATCH 16/63] cli/command/image/build/context_test.go:244:38: `createTestTempDir` - `dir` always receives `""` (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit 70bd64d037b044aa04cb177972a5d2fee41a238b) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/context_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/command/image/build/context_test.go b/cli/command/image/build/context_test.go index de4d38f75d..5404f7aa5d 100644 --- a/cli/command/image/build/context_test.go +++ b/cli/command/image/build/context_test.go @@ -24,11 +24,11 @@ var prepareEmpty = func(t *testing.T) (string, func()) { } var prepareNoFiles = func(t *testing.T) (string, func()) { - return createTestTempDir(t, "", "builder-context-test") + return createTestTempDir(t, "builder-context-test") } var prepareOneFile = func(t *testing.T) (string, func()) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) return contextDir, cleanup } @@ -42,7 +42,7 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (stri } func TestGetContextFromLocalDirNoDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() _, _, err := GetContextFromLocalDir(contextDir, "") @@ -50,7 +50,7 @@ func TestGetContextFromLocalDirNoDockerfile(t *testing.T) { } func TestGetContextFromLocalDirNotExistingDir(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() fakePath := filepath.Join(contextDir, "fake") @@ -60,7 +60,7 @@ func TestGetContextFromLocalDirNotExistingDir(t *testing.T) { } func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() fakePath := filepath.Join(contextDir, "fake") @@ -70,7 +70,7 @@ func TestGetContextFromLocalDirNotExistingDockerfile(t *testing.T) { } func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { - contextDir, dirCleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, dirCleanup := createTestTempDir(t, "builder-context-test") defer dirCleanup() createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) @@ -86,7 +86,7 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { } func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) @@ -99,7 +99,7 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { } func TestGetContextFromLocalDirLocalFile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) @@ -121,7 +121,7 @@ func TestGetContextFromLocalDirLocalFile(t *testing.T) { } func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() chdirCleanup := chdir(t, contextDir) @@ -173,7 +173,7 @@ func TestGetContextFromReaderString(t *testing.T) { } func TestGetContextFromReaderTar(t *testing.T) { - contextDir, cleanup := createTestTempDir(t, "", "builder-context-test") + contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) @@ -241,8 +241,8 @@ func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) { // createTestTempDir creates a temporary directory for testing. // It returns the created path and a cleanup function which is meant to be used as deferred call. // When an error occurs, it terminates the test. -func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { - path, err := ioutil.TempDir(dir, prefix) +func createTestTempDir(t *testing.T, prefix string) (string, func()) { + path, err := ioutil.TempDir("", prefix) assert.NilError(t, err) return path, func() { assert.NilError(t, os.RemoveAll(path)) } } From 9c7b701de556e9e94d6b32e8f958d101ce1001a0 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:08:04 +0200 Subject: [PATCH 17/63] cli/command/image/build/context_test.go:252:71: `createTestTempFile` - `perm` always receives `0777` (`511`) (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit 0ce2eae5a29ea982212870545c020e2b69d1f0db) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/context_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cli/command/image/build/context_test.go b/cli/command/image/build/context_test.go index 5404f7aa5d..b0e77058fa 100644 --- a/cli/command/image/build/context_test.go +++ b/cli/command/image/build/context_test.go @@ -29,7 +29,7 @@ var prepareNoFiles = func(t *testing.T) (string, func()) { var prepareOneFile = func(t *testing.T) (string, func()) { contextDir, cleanup := createTestTempDir(t, "builder-context-test") - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) return contextDir, cleanup } @@ -73,7 +73,7 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) { contextDir, dirCleanup := createTestTempDir(t, "builder-context-test") defer dirCleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) chdirCleanup := chdir(t, contextDir) defer chdirCleanup() @@ -89,7 +89,7 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") assert.NilError(t, err) @@ -102,8 +102,8 @@ func TestGetContextFromLocalDirLocalFile(t *testing.T) { contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) - testFilename := createTestTempFile(t, contextDir, "tmpTest", "test", 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) + testFilename := createTestTempFile(t, contextDir, "tmpTest", "test") absContextDir, relDockerfile, err := GetContextFromLocalDir(testFilename, "") @@ -127,7 +127,7 @@ func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) { chdirCleanup := chdir(t, contextDir) defer chdirCleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName) assert.NilError(t, err) @@ -176,7 +176,7 @@ func TestGetContextFromReaderTar(t *testing.T) { contextDir, cleanup := createTestTempDir(t, "builder-context-test") defer cleanup() - createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) + createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents) tarStream, err := archive.Tar(contextDir, archive.Uncompressed) assert.NilError(t, err) @@ -249,9 +249,9 @@ func createTestTempDir(t *testing.T, prefix string) (string, func()) { // createTestTempFile creates a temporary file within dir with specific contents and permissions. // When an error occurs, it terminates the test -func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string { +func createTestTempFile(t *testing.T, dir, filename, contents string) string { filePath := filepath.Join(dir, filename) - err := ioutil.WriteFile(filePath, []byte(contents), perm) + err := ioutil.WriteFile(filePath, []byte(contents), 0777) assert.NilError(t, err) return filePath } From 20ae2a6c4e94b71975cdd100f5cd717c681fd816 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:16:13 +0200 Subject: [PATCH 18/63] cli/command/image/build_buildkit.go:450:56: parseSSH - result 1 (error) is always nil (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit 28ac2f82c690ac8f37c2980f2787572815439a50) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build_buildkit.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cli/command/image/build_buildkit.go b/cli/command/image/build_buildkit.go index b3b978c563..5c2de4630b 100644 --- a/cli/command/image/build_buildkit.go +++ b/cli/command/image/build_buildkit.go @@ -476,16 +476,13 @@ func parseSecret(value string) (*secretsprovider.FileSource, error) { func parseSSHSpecs(sl []string) (session.Attachable, error) { configs := make([]sshprovider.AgentConfig, 0, len(sl)) for _, v := range sl { - c, err := parseSSH(v) - if err != nil { - return nil, err - } + c := parseSSH(v) configs = append(configs, *c) } return sshprovider.NewSSHAgentProvider(configs) } -func parseSSH(value string) (*sshprovider.AgentConfig, error) { +func parseSSH(value string) *sshprovider.AgentConfig { parts := strings.SplitN(value, "=", 2) cfg := sshprovider.AgentConfig{ ID: parts[0], @@ -493,5 +490,5 @@ func parseSSH(value string) (*sshprovider.AgentConfig, error) { if len(parts) > 1 { cfg.Paths = strings.Split(parts[1], ",") } - return &cfg, nil + return &cfg } From a3912a4713db1d64d33e56df560435e6a99a6d41 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:22:30 +0200 Subject: [PATCH 19/63] cli/command/image/build_session.go:133:45: getBuildSharedKey - result 1 (error) is always nil (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit 75c60c1af7c8a3ca79e1af2f351b5b0d29960900) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build_session.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cli/command/image/build_session.go b/cli/command/image/build_session.go index c19120758d..aa7b3fe9bf 100644 --- a/cli/command/image/build_session.go +++ b/cli/command/image/build_session.go @@ -35,16 +35,13 @@ func isSessionSupported(dockerCli command.Cli, forStream bool) bool { } func trySession(dockerCli command.Cli, contextDir string, forStream bool) (*session.Session, error) { - var s *session.Session - if isSessionSupported(dockerCli, forStream) { - sharedKey, err := getBuildSharedKey(contextDir) - if err != nil { - return nil, errors.Wrap(err, "failed to get build shared key") - } - s, err = session.NewSession(context.Background(), filepath.Base(contextDir), sharedKey) - if err != nil { - return nil, errors.Wrap(err, "failed to create session") - } + if !isSessionSupported(dockerCli, forStream) { + return nil, nil + } + sharedKey := getBuildSharedKey(contextDir) + s, err := session.NewSession(context.Background(), filepath.Base(contextDir), sharedKey) + if err != nil { + return nil, errors.Wrap(err, "failed to create session") } return s, nil } @@ -130,10 +127,10 @@ func (bw *bufferedWriter) String() string { return fmt.Sprintf("%s", bw.Writer) } -func getBuildSharedKey(dir string) (string, error) { +func getBuildSharedKey(dir string) string { // build session is hash of build dir with node based randomness s := sha256.Sum256([]byte(fmt.Sprintf("%s:%s", tryNodeIdentifier(), dir))) - return hex.EncodeToString(s[:]), nil + return hex.EncodeToString(s[:]) } func tryNodeIdentifier() string { From a1f67cc029526994560a9957d35e77b8bd9a8c1f Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:25:33 +0200 Subject: [PATCH 20/63] cli/command/plugin/list_test.go:61:31: `TestList$1` - `filter` is unused (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit ab1aeedb27af56b3d5c29c4c95a748e98c386469) Signed-off-by: Sebastiaan van Stijn --- cli/command/plugin/list_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/command/plugin/list_test.go b/cli/command/plugin/list_test.go index fbde655316..75d0c8139c 100644 --- a/cli/command/plugin/list_test.go +++ b/cli/command/plugin/list_test.go @@ -58,7 +58,7 @@ func TestListErrors(t *testing.T) { } func TestList(t *testing.T) { - singlePluginListFunc := func(filter filters.Args) (types.PluginsListResponse, error) { + singlePluginListFunc := func(_ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{ { ID: "id-foo", @@ -113,7 +113,7 @@ func TestList(t *testing.T) { "format": "{{ .ID }}", }, golden: "plugin-list-with-no-trunc-option.golden", - listFunc: func(filter filters.Args) (types.PluginsListResponse, error) { + listFunc: func(_ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{ { ID: "xyg4z2hiSLO5yTnBJfg4OYia9gKA6Qjd", @@ -142,7 +142,7 @@ func TestList(t *testing.T) { "format": "{{ .Name }}", }, golden: "plugin-list-sort.golden", - listFunc: func(filter filters.Args) (types.PluginsListResponse, error) { + listFunc: func(_ filters.Args) (types.PluginsListResponse, error) { return types.PluginsListResponse{ { ID: "id-1", From 7db8c83e3aad70fa805509dd23c460e4f2f74787 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:27:01 +0200 Subject: [PATCH 21/63] cli/command/stack/kubernetes/deploy_test.go:65:68: `checkOwnerReferences` - `stackName` always receives `"test"` (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit a3c7cb4f12cb5a00a11388cb1b4a6ed532704956) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/kubernetes/deploy_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/command/stack/kubernetes/deploy_test.go b/cli/command/stack/kubernetes/deploy_test.go index 85d1a5ff7d..366ba45ebe 100644 --- a/cli/command/stack/kubernetes/deploy_test.go +++ b/cli/command/stack/kubernetes/deploy_test.go @@ -56,16 +56,16 @@ func TestCreateChildResourcesV1Beta1(t *testing.T) { secrets)) c, err := configs.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, c.ObjectMeta, "test", v1beta1.SchemeGroupVersion.String()) + checkOwnerReferences(t, c.ObjectMeta, v1beta1.SchemeGroupVersion.String()) s, err := secrets.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, s.ObjectMeta, "test", v1beta1.SchemeGroupVersion.String()) + checkOwnerReferences(t, s.ObjectMeta, v1beta1.SchemeGroupVersion.String()) } -func checkOwnerReferences(t *testing.T, objMeta metav1.ObjectMeta, stackName, stackVersion string) { +func checkOwnerReferences(t *testing.T, objMeta metav1.ObjectMeta, stackVersion string) { t.Helper() assert.Equal(t, len(objMeta.OwnerReferences), 1) - assert.Equal(t, objMeta.OwnerReferences[0].Name, stackName) + assert.Equal(t, objMeta.OwnerReferences[0].Name, "test") assert.Equal(t, objMeta.OwnerReferences[0].Kind, "Stack") assert.Equal(t, objMeta.OwnerReferences[0].APIVersion, stackVersion) } @@ -82,10 +82,10 @@ func TestCreateChildResourcesV1Beta2(t *testing.T) { secrets)) c, err := configs.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, c.ObjectMeta, "test", v1beta2.SchemeGroupVersion.String()) + checkOwnerReferences(t, c.ObjectMeta, v1beta2.SchemeGroupVersion.String()) s, err := secrets.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, s.ObjectMeta, "test", v1beta2.SchemeGroupVersion.String()) + checkOwnerReferences(t, s.ObjectMeta, v1beta2.SchemeGroupVersion.String()) } func TestCreateChildResourcesV1Alpha3(t *testing.T) { @@ -100,10 +100,10 @@ func TestCreateChildResourcesV1Alpha3(t *testing.T) { secrets)) c, err := configs.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, c.ObjectMeta, "test", v1alpha3.SchemeGroupVersion.String()) + checkOwnerReferences(t, c.ObjectMeta, v1alpha3.SchemeGroupVersion.String()) s, err := secrets.Get("test", metav1.GetOptions{}) assert.NilError(t, err) - checkOwnerReferences(t, s.ObjectMeta, "test", v1alpha3.SchemeGroupVersion.String()) + checkOwnerReferences(t, s.ObjectMeta, v1alpha3.SchemeGroupVersion.String()) } func TestCreateChildResourcesWithStackCreationErrorV1Beta1(t *testing.T) { From 9ac043bc9d83b9d1a78dc17e0fcfa8d1b3b75165 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:38:48 +0200 Subject: [PATCH 22/63] cli/command/system/info.go:116:68: prettyPrintClientInfo - result 0 (error) is always nil (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit 47741f81d15df9e347deb472bed9c8ecb13d3470) Signed-off-by: Sebastiaan van Stijn --- cli/command/system/info.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 7adf92bd50..d837ca5231 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -88,9 +88,7 @@ func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error func prettyPrintInfo(dockerCli command.Cli, info info) error { fmt.Fprintln(dockerCli.Out(), "Client:") if info.ClientInfo != nil { - if err := prettyPrintClientInfo(dockerCli, *info.ClientInfo); err != nil { - info.ClientErrors = append(info.ClientErrors, err.Error()) - } + prettyPrintClientInfo(dockerCli, *info.ClientInfo) } for _, err := range info.ClientErrors { fmt.Fprintln(dockerCli.Out(), "ERROR:", err) @@ -113,7 +111,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error { return nil } -func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) error { +func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) { fmt.Fprintln(dockerCli.Out(), " Debug Mode:", info.Debug) if len(info.Plugins) > 0 { @@ -134,8 +132,6 @@ func prettyPrintClientInfo(dockerCli command.Cli, info clientInfo) error { if len(info.Warnings) > 0 { fmt.Fprintln(dockerCli.Err(), strings.Join(info.Warnings, "\n")) } - - return nil } // nolint: gocyclo From 67a7fe0b3bcbde5f1fbff5d5487bd6767d14d4ec Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:40:25 +0200 Subject: [PATCH 23/63] cli/compose/convert: result 1 (error) is always nil (unparam) cli/compose/convert/service.go:592:76: convertDNSConfig - result 1 (error) is always nil (unparam) cli/compose/convert/service.go:538:110: convertEndpointSpec - result 1 (error) is always nil (unparam) Signed-off-by: Silvin Lubecki Signed-off-by: Sebastiaan van Stijn (cherry picked from commit d640f44df382839bdff18e6d72496c81e387ef48) Signed-off-by: Sebastiaan van Stijn --- cli/compose/convert/service.go | 21 +++++++-------------- cli/compose/convert/service_test.go | 16 +++++----------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 2da8c6dc55..da182bbfe8 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -66,11 +66,7 @@ func Service( configs []*swarm.ConfigReference, ) (swarm.ServiceSpec, error) { name := namespace.Scope(service.Name) - - endpoint, err := convertEndpointSpec(service.Deploy.EndpointMode, service.Ports) - if err != nil { - return swarm.ServiceSpec{}, err - } + endpoint := convertEndpointSpec(service.Deploy.EndpointMode, service.Ports) mode, err := convertDeployMode(service.Deploy.Mode, service.Deploy.Replicas) if err != nil { @@ -103,10 +99,7 @@ func Service( return swarm.ServiceSpec{}, err } - dnsConfig, err := convertDNSConfig(service.DNS, service.DNSSearch) - if err != nil { - return swarm.ServiceSpec{}, err - } + dnsConfig := convertDNSConfig(service.DNS, service.DNSSearch) var privileges swarm.Privileges privileges.CredentialSpec, err = convertCredentialSpec( @@ -575,7 +568,7 @@ func convertResources(source composetypes.Resources) (*swarm.ResourceRequirement return resources, nil } -func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) (*swarm.EndpointSpec, error) { +func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortConfig) *swarm.EndpointSpec { portConfigs := []swarm.PortConfig{} for _, port := range source { portConfig := swarm.PortConfig{ @@ -594,7 +587,7 @@ func convertEndpointSpec(endpointMode string, source []composetypes.ServicePortC return &swarm.EndpointSpec{ Mode: swarm.ResolutionMode(strings.ToLower(endpointMode)), Ports: portConfigs, - }, nil + } } func convertEnvironment(source map[string]*string) []string { @@ -629,14 +622,14 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) return serviceMode, nil } -func convertDNSConfig(DNS []string, DNSSearch []string) (*swarm.DNSConfig, error) { +func convertDNSConfig(DNS []string, DNSSearch []string) *swarm.DNSConfig { if DNS != nil || DNSSearch != nil { return &swarm.DNSConfig{ Nameservers: DNS, Search: DNSSearch, - }, nil + } } - return nil, nil + return nil } func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpecConfig, refs []*swarm.ConfigReference) (*swarm.CredentialSpec, error) { diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 4205038667..87f5327ffe 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -177,7 +177,7 @@ func TestConvertEndpointSpec(t *testing.T) { Published: 80, }, } - endpoint, err := convertEndpointSpec("vip", source) + endpoint := convertEndpointSpec("vip", source) expected := swarm.EndpointSpec{ Mode: swarm.ResolutionMode(strings.ToLower("vip")), @@ -195,7 +195,6 @@ func TestConvertEndpointSpec(t *testing.T) { }, } - assert.NilError(t, err) assert.Check(t, is.DeepEqual(expected, *endpoint)) } @@ -275,9 +274,7 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) { } func TestConvertDNSConfigEmpty(t *testing.T) { - dnsConfig, err := convertDNSConfig(nil, nil) - - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nil, nil) assert.Check(t, is.DeepEqual((*swarm.DNSConfig)(nil), dnsConfig)) } @@ -287,8 +284,7 @@ var ( ) func TestConvertDNSConfigAll(t *testing.T) { - dnsConfig, err := convertDNSConfig(nameservers, search) - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nameservers, search) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nameservers, Search: search, @@ -296,8 +292,7 @@ func TestConvertDNSConfigAll(t *testing.T) { } func TestConvertDNSConfigNameservers(t *testing.T) { - dnsConfig, err := convertDNSConfig(nameservers, nil) - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nameservers, nil) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nameservers, Search: nil, @@ -305,8 +300,7 @@ func TestConvertDNSConfigNameservers(t *testing.T) { } func TestConvertDNSConfigSearch(t *testing.T) { - dnsConfig, err := convertDNSConfig(nil, search) - assert.NilError(t, err) + dnsConfig := convertDNSConfig(nil, search) assert.Check(t, is.DeepEqual(&swarm.DNSConfig{ Nameservers: nil, Search: search, From c77f5255a4f9775af2db570704eaa2015cbc0ac6 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 13:52:19 +0200 Subject: [PATCH 24/63] disable unparam linter on these functions, as we need an error in these function signatures cli/compose/loader/loader.go:756:66: transformServiceNetworkMap - result 1 (error) is always nil (unparam) cli/compose/loader/loader.go:767:67: transformStringOrNumberList - result 1 (error) is always nil (unparam) Signed-off-by: Silvin Lubecki Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 6eb0c9c613a25a8d142795c76e20259ab9efe1dd) Signed-off-by: Sebastiaan van Stijn --- cli/compose/loader/loader.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index a17105f08e..2ddc858eab 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -772,6 +772,7 @@ func transformServiceVolumeConfig(data interface{}) (interface{}, error) { } } +// nolint: unparam func transformServiceNetworkMap(value interface{}) (interface{}, error) { if list, ok := value.([]interface{}); ok { mapValue := map[interface{}]interface{}{} @@ -783,6 +784,7 @@ func transformServiceNetworkMap(value interface{}) (interface{}, error) { return value, nil } +// nolint: unparam func transformStringOrNumberList(value interface{}) (interface{}, error) { list := value.([]interface{}) result := make([]string, len(list)) From b49a07b63d98ec56bace60764e7e0bccb5439660 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 00:10:55 +0100 Subject: [PATCH 25/63] compose/loader: define type for transformer-functions Also explicitly type transformer-functions Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 9118b2b2b89f60441f89fc5ff9c2832d53a3f20b) Signed-off-by: Sebastiaan van Stijn --- cli/compose/loader/loader.go | 37 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index 2ddc858eab..28573dc4d5 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -297,10 +297,13 @@ func Transform(source interface{}, target interface{}, additionalTransformers .. return decoder.Decode(source) } +// TransformerFunc defines a function to perform the actual transformation +type TransformerFunc func(interface{}) (interface{}, error) + // Transformer defines a map to type transformer type Transformer struct { TypeOf reflect.Type - Func func(interface{}) (interface{}, error) + Func TransformerFunc } func createTransformHook(additionalTransformers ...Transformer) mapstructure.DecodeHookFuncType { @@ -684,7 +687,7 @@ func absPath(workingDir string, filePath string) string { return filepath.Join(workingDir, filePath) } -func transformMapStringString(data interface{}) (interface{}, error) { +var transformMapStringString TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case map[string]interface{}: return toMapStringString(value, false), nil @@ -695,7 +698,7 @@ func transformMapStringString(data interface{}) (interface{}, error) { } } -func transformExternal(data interface{}) (interface{}, error) { +var transformExternal TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case bool: return map[string]interface{}{"external": value}, nil @@ -706,7 +709,7 @@ func transformExternal(data interface{}) (interface{}, error) { } } -func transformServicePort(data interface{}) (interface{}, error) { +var transformServicePort TransformerFunc = func(data interface{}) (interface{}, error) { switch entries := data.(type) { case []interface{}: // We process the list instead of individual items here. @@ -739,7 +742,7 @@ func transformServicePort(data interface{}) (interface{}, error) { } } -func transformStringSourceMap(data interface{}) (interface{}, error) { +var transformStringSourceMap TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: return map[string]interface{}{"source": value}, nil @@ -750,7 +753,7 @@ func transformStringSourceMap(data interface{}) (interface{}, error) { } } -func transformBuildConfig(data interface{}) (interface{}, error) { +var transformBuildConfig TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: return map[string]interface{}{"context": value}, nil @@ -761,7 +764,7 @@ func transformBuildConfig(data interface{}) (interface{}, error) { } } -func transformServiceVolumeConfig(data interface{}) (interface{}, error) { +var transformServiceVolumeConfig TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: return ParseVolume(value) @@ -772,8 +775,7 @@ func transformServiceVolumeConfig(data interface{}) (interface{}, error) { } } -// nolint: unparam -func transformServiceNetworkMap(value interface{}) (interface{}, error) { +var transformServiceNetworkMap TransformerFunc = func(value interface{}) (interface{}, error) { if list, ok := value.([]interface{}); ok { mapValue := map[interface{}]interface{}{} for _, name := range list { @@ -784,8 +786,7 @@ func transformServiceNetworkMap(value interface{}) (interface{}, error) { return value, nil } -// nolint: unparam -func transformStringOrNumberList(value interface{}) (interface{}, error) { +var transformStringOrNumberList TransformerFunc = func(value interface{}) (interface{}, error) { list := value.([]interface{}) result := make([]string, len(list)) for i, item := range list { @@ -794,7 +795,7 @@ func transformStringOrNumberList(value interface{}) (interface{}, error) { return result, nil } -func transformStringList(data interface{}) (interface{}, error) { +var transformStringList TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: return []string{value}, nil @@ -805,13 +806,13 @@ func transformStringList(data interface{}) (interface{}, error) { } } -func transformMappingOrListFunc(sep string, allowNil bool) func(interface{}) (interface{}, error) { +func transformMappingOrListFunc(sep string, allowNil bool) TransformerFunc { return func(data interface{}) (interface{}, error) { return transformMappingOrList(data, sep, allowNil), nil } } -func transformListOrMappingFunc(sep string, allowNil bool) func(interface{}) (interface{}, error) { +func transformListOrMappingFunc(sep string, allowNil bool) TransformerFunc { return func(data interface{}) (interface{}, error) { return transformListOrMapping(data, sep, allowNil), nil } @@ -850,14 +851,14 @@ func transformMappingOrList(mappingOrList interface{}, sep string, allowNil bool panic(errors.Errorf("expected a map or a list, got %T: %#v", mappingOrList, mappingOrList)) } -func transformShellCommand(value interface{}) (interface{}, error) { +var transformShellCommand TransformerFunc = func(value interface{}) (interface{}, error) { if str, ok := value.(string); ok { return shellwords.Parse(str) } return value, nil } -func transformHealthCheckTest(data interface{}) (interface{}, error) { +var transformHealthCheckTest TransformerFunc = func(data interface{}) (interface{}, error) { switch value := data.(type) { case string: return append([]string{"CMD-SHELL"}, value), nil @@ -868,7 +869,7 @@ func transformHealthCheckTest(data interface{}) (interface{}, error) { } } -func transformSize(value interface{}) (interface{}, error) { +var transformSize TransformerFunc = func(value interface{}) (interface{}, error) { switch value := value.(type) { case int: return int64(value), nil @@ -878,7 +879,7 @@ func transformSize(value interface{}) (interface{}, error) { panic(errors.Errorf("invalid type for size %T", value)) } -func transformStringToDuration(value interface{}) (interface{}, error) { +var transformStringToDuration TransformerFunc = func(value interface{}) (interface{}, error) { switch value := value.(type) { case string: d, err := time.ParseDuration(value) From c749704b83bf4add924ffce10012607e84a7df28 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 16:17:53 +0200 Subject: [PATCH 26/63] Disable unparam linter: cli/required.go:102:16: `pluralize` - `word` always receives `"argument"` (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit 7d823438bb84180a8af348760218400843048b97) Signed-off-by: Sebastiaan van Stijn --- cli/required.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/required.go b/cli/required.go index 33a4673546..cce81c86ab 100644 --- a/cli/required.go +++ b/cli/required.go @@ -99,6 +99,7 @@ func ExactArgs(number int) cobra.PositionalArgs { } } +//nolint: unparam func pluralize(word string, number int) string { if number == 1 { return word From 315715e145cdc08416dc5d4cd874f9844946877c Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 16:19:39 +0200 Subject: [PATCH 27/63] Disable unparam linter: e2e/image/push_test.go:299:27: `withNotaryPassphrase` - `pwd` always receives `"foo"` (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit f123e43c1f7e4dc4ed4e607b73c7a5a94c6c93a8) Signed-off-by: Sebastiaan van Stijn --- e2e/image/push_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/image/push_test.go b/e2e/image/push_test.go index 91dbc1cba8..1bcf025556 100644 --- a/e2e/image/push_test.go +++ b/e2e/image/push_test.go @@ -296,6 +296,7 @@ func createImage(t *testing.T, registryPrefix, repo, tag string) string { return image } +//nolint: unparam func withNotaryPassphrase(pwd string) func(*icmd.Cmd) { return func(c *icmd.Cmd) { c.Env = append(c.Env, []string{ From 03dbef8931c8108dbba3a5e0420e46127678241a Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 16:21:48 +0200 Subject: [PATCH 28/63] cli/command/trust/sign_test.go:119:70: unnecessary conversion (unconvert) Signed-off-by: Silvin Lubecki (cherry picked from commit 0153624a56ef3267e7fb6d52a1affe562cd86157) Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/sign_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/trust/sign_test.go b/cli/command/trust/sign_test.go index 31a56ea120..f197c7f599 100644 --- a/cli/command/trust/sign_test.go +++ b/cli/command/trust/sign_test.go @@ -116,7 +116,7 @@ func TestGetOrGenerateNotaryKey(t *testing.T) { assert.Check(t, is.DeepEqual(rootKeyA.Public(), rootKeyB.Public())) // Now also try with a delegation key - releasesKey, err := getOrGenerateNotaryKey(notaryRepo, data.RoleName(trust.ReleasesRole)) + releasesKey, err := getOrGenerateNotaryKey(notaryRepo, trust.ReleasesRole) assert.NilError(t, err) assert.Check(t, releasesKey != nil) From 2441946ce7f07976e28c8636b3b354e090a6ad7f Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 16:23:00 +0200 Subject: [PATCH 29/63] cli/compose/convert/service_test.go:274:72: unnecessary conversion (unconvert) Signed-off-by: Silvin Lubecki (cherry picked from commit c237379167f9bc59d01e905327122f9713574a0f) Signed-off-by: Sebastiaan van Stijn --- cli/compose/convert/service_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 87f5327ffe..85550628f2 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -270,7 +270,7 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) { } assert.NilError(t, err) - assert.Check(t, is.DeepEqual(expected, []swarm.NetworkAttachmentConfig(configs))) + assert.Check(t, is.DeepEqual(expected, configs)) } func TestConvertDNSConfigEmpty(t *testing.T) { From b2f6b4902cf7b0f0f93ffbbc95caded7738aaf12 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 17:20:21 +0200 Subject: [PATCH 30/63] File is not `goimports`-ed (goimports) Signed-off-by: Silvin Lubecki (cherry picked from commit 6047259e5a1317f2d02a180fa457f33799e024b9) Signed-off-by: Sebastiaan van Stijn --- cli/command/config/inspect_test.go | 3 +-- cli/command/config/ls_test.go | 3 +-- cli/command/container/list_test.go | 3 +-- cli/command/idresolver/idresolver_test.go | 8 +++----- cli/command/node/demote_test.go | 3 +-- cli/command/node/inspect_test.go | 3 +-- cli/command/node/list_test.go | 3 +-- cli/command/node/promote_test.go | 3 +-- cli/command/node/ps_test.go | 3 +-- cli/command/node/update_test.go | 3 +-- cli/command/secret/inspect_test.go | 3 +-- cli/command/secret/ls_test.go | 3 +-- cli/command/service/client_test.go | 3 +-- cli/command/stack/list_test.go | 3 +-- cli/command/stack/ps_test.go | 3 +-- cli/command/stack/services_test.go | 3 +-- cli/command/swarm/join_token_test.go | 3 +-- cli/command/swarm/unlock_key_test.go | 3 +-- cli/command/swarm/update_test.go | 4 +--- cli/command/task/print_test.go | 3 +-- cli/command/volume/inspect_test.go | 3 +-- cli/command/volume/list_test.go | 3 +-- internal/containerizedengine/update.go | 2 +- 23 files changed, 25 insertions(+), 49 deletions(-) diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index 1b4f275ccb..d174b0c502 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -7,10 +7,9 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index d3055b4aa1..4677b068e7 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -7,11 +7,10 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" is "gotest.tools/assert/cmp" "gotest.tools/golden" diff --git a/cli/command/container/list_test.go b/cli/command/container/list_test.go index 2bc1949a7f..310d78020a 100644 --- a/cli/command/container/list_test.go +++ b/cli/command/container/list_test.go @@ -7,9 +7,8 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/idresolver/idresolver_test.go b/cli/command/idresolver/idresolver_test.go index f667b10641..4cb6355594 100644 --- a/cli/command/idresolver/idresolver_test.go +++ b/cli/command/idresolver/idresolver_test.go @@ -1,16 +1,14 @@ package idresolver import ( + "context" "testing" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" + "github.com/pkg/errors" "gotest.tools/assert" is "gotest.tools/assert/cmp" - // Import builders to get the builder function as package function - "context" - - . "github.com/docker/cli/internal/test/builders" - "github.com/pkg/errors" ) func TestResolveError(t *testing.T) { diff --git a/cli/command/node/demote_test.go b/cli/command/node/demote_test.go index 3f18d63d41..849cbdc93d 100644 --- a/cli/command/node/demote_test.go +++ b/cli/command/node/demote_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodeDemoteErrors(t *testing.T) { diff --git a/cli/command/node/inspect_test.go b/cli/command/node/inspect_test.go index de343b0f49..22be4f475f 100644 --- a/cli/command/node/inspect_test.go +++ b/cli/command/node/inspect_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/node/list_test.go b/cli/command/node/list_test.go index 5dc11c961a..11e5ff3f60 100644 --- a/cli/command/node/list_test.go +++ b/cli/command/node/list_test.go @@ -6,14 +6,13 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" is "gotest.tools/assert/cmp" "gotest.tools/golden" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodeListErrorOnAPIFailure(t *testing.T) { diff --git a/cli/command/node/promote_test.go b/cli/command/node/promote_test.go index c6b5342320..528180ae00 100644 --- a/cli/command/node/promote_test.go +++ b/cli/command/node/promote_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodePromoteErrors(t *testing.T) { diff --git a/cli/command/node/ps_test.go b/cli/command/node/ps_test.go index 74a1779b1f..da4637da61 100644 --- a/cli/command/node/ps_test.go +++ b/cli/command/node/ps_test.go @@ -8,11 +8,10 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/node/update_test.go b/cli/command/node/update_test.go index 8b6ae807da..00c447b6b2 100644 --- a/cli/command/node/update_test.go +++ b/cli/command/node/update_test.go @@ -5,11 +5,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/assert" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) func TestNodeUpdateErrors(t *testing.T) { diff --git a/cli/command/secret/inspect_test.go b/cli/command/secret/inspect_test.go index 67addaeadf..9224f9b796 100644 --- a/cli/command/secret/inspect_test.go +++ b/cli/command/secret/inspect_test.go @@ -7,10 +7,9 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/secret/ls_test.go b/cli/command/secret/ls_test.go index e1417115ce..1e6af25a0d 100644 --- a/cli/command/secret/ls_test.go +++ b/cli/command/secret/ls_test.go @@ -7,11 +7,10 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" is "gotest.tools/assert/cmp" "gotest.tools/golden" diff --git a/cli/command/service/client_test.go b/cli/command/service/client_test.go index 8d0d592cec..97dd9d8c4c 100644 --- a/cli/command/service/client_test.go +++ b/cli/command/service/client_test.go @@ -3,11 +3,10 @@ package service import ( "context" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" ) type fakeClient struct { diff --git a/cli/command/stack/list_test.go b/cli/command/stack/list_test.go index 5fdc04bed3..8d792172ac 100644 --- a/cli/command/stack/list_test.go +++ b/cli/command/stack/list_test.go @@ -6,8 +6,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index a3e68656fb..8e49d193bd 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -7,8 +7,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/stack/services_test.go b/cli/command/stack/services_test.go index 64a58b9970..431a675f9d 100644 --- a/cli/command/stack/services_test.go +++ b/cli/command/stack/services_test.go @@ -6,8 +6,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index 1bd7ba2508..e34e7da5f0 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/swarm/unlock_key_test.go b/cli/command/swarm/unlock_key_test.go index d28921a141..d313c6319f 100644 --- a/cli/command/swarm/unlock_key_test.go +++ b/cli/command/swarm/unlock_key_test.go @@ -6,11 +6,10 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index 20a5624a89..ebddeeec0d 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -7,12 +7,10 @@ import ( "time" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" - - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/task/print_test.go b/cli/command/task/print_test.go index 6fa6e58653..5b5c0a81c3 100644 --- a/cli/command/task/print_test.go +++ b/cli/command/task/print_test.go @@ -8,8 +8,7 @@ import ( "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/idresolver" "github.com/docker/cli/internal/test" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "gotest.tools/assert" diff --git a/cli/command/volume/inspect_test.go b/cli/command/volume/inspect_test.go index 759042a512..c5baa9c62e 100644 --- a/cli/command/volume/inspect_test.go +++ b/cli/command/volume/inspect_test.go @@ -6,10 +6,9 @@ import ( "testing" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/cli/command/volume/list_test.go b/cli/command/volume/list_test.go index 9159eb89ef..9f07006f16 100644 --- a/cli/command/volume/list_test.go +++ b/cli/command/volume/list_test.go @@ -6,12 +6,11 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" + . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" volumetypes "github.com/docker/docker/api/types/volume" "github.com/pkg/errors" - // Import builders to get the builder function as package function - . "github.com/docker/cli/internal/test/builders" "gotest.tools/assert" "gotest.tools/golden" ) diff --git a/internal/containerizedengine/update.go b/internal/containerizedengine/update.go index 3cd7b31082..7c71da19e4 100644 --- a/internal/containerizedengine/update.go +++ b/internal/containerizedengine/update.go @@ -16,7 +16,7 @@ import ( "github.com/docker/distribution/reference" "github.com/docker/docker/api/types" ver "github.com/hashicorp/go-version" - "github.com/opencontainers/image-spec/specs-go/v1" + v1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) From 44c8cec274c2f759a6c3c133a8b47748b5ac4d68 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 16:24:37 +0200 Subject: [PATCH 31/63] cli/command/registry/login_test.go:66:25: unnecessary conversion (unconvert) Signed-off-by: Silvin Lubecki (cherry picked from commit 4be924a0af25bed639753f84667afba4f8ce0cf9) Signed-off-by: Sebastiaan van Stijn --- cli/command/registry/login_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index f31ebd1716..9372a50aec 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -69,7 +69,7 @@ func TestLoginWithCredStoreCreds(t *testing.T) { } ctx := context.Background() for _, tc := range testCases { - cli := (*test.FakeCli)(test.NewFakeCli(&fakeClient{})) + cli := test.NewFakeCli(&fakeClient{}) errBuf := new(bytes.Buffer) cli.SetErr(errBuf) loginWithCredStoreCreds(ctx, cli, &tc.inputAuthConfig) From 98d266152217915ea0a4e658718c4980109185ce Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 17:59:48 +0200 Subject: [PATCH 32/63] cli/command/image/build/context_test.go:244:38: `createTestTempDir` - `prefix` always receives `"builder-context-test"` (unparam) Signed-off-by: Silvin Lubecki (cherry picked from commit b83545ebbcd39c28db5c18dc133c985625572776) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/context_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/command/image/build/context_test.go b/cli/command/image/build/context_test.go index b0e77058fa..622f8edbd1 100644 --- a/cli/command/image/build/context_test.go +++ b/cli/command/image/build/context_test.go @@ -241,6 +241,7 @@ func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) { // createTestTempDir creates a temporary directory for testing. // It returns the created path and a cleanup function which is meant to be used as deferred call. // When an error occurs, it terminates the test. +//nolint: unparam func createTestTempDir(t *testing.T, prefix string) (string, func()) { path, err := ioutil.TempDir("", prefix) assert.NilError(t, err) From 7467a6a7de6a93bcc232bf19e193d3ecdd96fb8d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 01:44:16 +0100 Subject: [PATCH 33/63] e2e/container: containerExistsWithStatus - t is unused (unparam) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 6205ef33be7fb2afa6ce6f1ea163f225ddca1434) Signed-off-by: Sebastiaan van Stijn --- e2e/container/proxy_signal_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/e2e/container/proxy_signal_test.go b/e2e/container/proxy_signal_test.go index a822021d89..7d769b7180 100644 --- a/e2e/container/proxy_signal_test.go +++ b/e2e/container/proxy_signal_test.go @@ -26,17 +26,17 @@ func TestSigProxyWithTTY(t *testing.T) { assert.NilError(t, err, "failed to start container") defer icmd.RunCommand("docker", "container", "rm", "-f", t.Name()) - poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) + poll.WaitOn(t, containerExistsWithStatus(t.Name(), "running"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) pid := cmd.Process.Pid t.Logf("terminating PID %d", pid) err = syscall.Kill(pid, syscall.SIGTERM) assert.NilError(t, err) - poll.WaitOn(t, containerExistsWithStatus(t, t.Name(), "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) + poll.WaitOn(t, containerExistsWithStatus(t.Name(), "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(5*time.Second)) } -func containerExistsWithStatus(t *testing.T, containerID, status string) func(poll.LogT) poll.Result { +func containerExistsWithStatus(containerID, status string) func(poll.LogT) poll.Result { return func(poll.LogT) poll.Result { result := icmd.RunCommand("docker", "inspect", "-f", "{{ .State.Status }}", containerID) // ignore initial failures as the container may not yet exist (i.e., don't result.Assert(t, icmd.Success)) From 1a57296c26e288058207e196dbd8d331bc968201 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 01:47:58 +0100 Subject: [PATCH 34/63] cli/compose/convert: driverObjectConfig - result 1 (error) is always nil (unparam) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 34f595975de83b7ae3162d3f513e164c39fd8124) Signed-off-by: Sebastiaan van Stijn --- cli/compose/convert/compose.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/compose/convert/compose.go b/cli/compose/convert/compose.go index 983e7b52ea..189a909622 100644 --- a/cli/compose/convert/compose.go +++ b/cli/compose/convert/compose.go @@ -109,7 +109,7 @@ func Secrets(namespace Namespace, secrets map[string]composetypes.SecretConfig) var obj swarmFileObject var err error if secret.Driver != "" { - obj, err = driverObjectConfig(namespace, name, composetypes.FileObjectConfig(secret)) + obj = driverObjectConfig(namespace, name, composetypes.FileObjectConfig(secret)) } else { obj, err = fileObjectConfig(namespace, name, composetypes.FileObjectConfig(secret)) } @@ -161,7 +161,7 @@ type swarmFileObject struct { Data []byte } -func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileObjectConfig) (swarmFileObject, error) { +func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileObjectConfig) swarmFileObject { if obj.Name != "" { name = obj.Name } else { @@ -174,7 +174,7 @@ func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileO Labels: AddStackLabel(namespace, obj.Labels), }, Data: []byte{}, - }, nil + } } func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObjectConfig) (swarmFileObject, error) { From c10bf24fb249e85234926cc700f842c88e48f794 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 01:48:50 +0100 Subject: [PATCH 35/63] cli/command/secret: G101: Potential hardcoded credentials (gosec) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 1850a0595bd22c35355850f4d260f25a8c79c5e2) Signed-off-by: Sebastiaan van Stijn --- cli/command/secret/formatter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/secret/formatter.go b/cli/command/secret/formatter.go index 24a56bda62..9102f28856 100644 --- a/cli/command/secret/formatter.go +++ b/cli/command/secret/formatter.go @@ -13,7 +13,7 @@ import ( ) const ( - defaultSecretTableFormat = "table {{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.CreatedAt}}\t{{.UpdatedAt}}" + defaultSecretTableFormat = "table {{.ID}}\t{{.Name}}\t{{.Driver}}\t{{.CreatedAt}}\t{{.UpdatedAt}}" // #nosec G101 secretIDHeader = "ID" secretCreatedHeader = "CREATED" secretUpdatedHeader = "UPDATED" From f969531205948660edf56fb47faec879a892475e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 01:49:41 +0100 Subject: [PATCH 36/63] cli/command/service: SA1012: do not pass a nil Context (staticcheck) ``` cli/command/service/update_test.go:31:16: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck) updateService(nil, nil, flags, spec) ^ cli/command/service/update_test.go:535:16: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck) updateService(nil, nil, flags, spec) ^ cli/command/service/update_test.go:540:16: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck) updateService(nil, nil, flags, spec) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 8d64c2af1af90f12e43ebd510ee09767bdf42ce8) Signed-off-by: Sebastiaan van Stijn --- cli/command/service/update_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/command/service/update_test.go b/cli/command/service/update_test.go index 6eeea55a1f..fbabdf2bbf 100644 --- a/cli/command/service/update_test.go +++ b/cli/command/service/update_test.go @@ -28,7 +28,7 @@ func TestUpdateServiceArgs(t *testing.T) { cspec := spec.TaskTemplate.ContainerSpec cspec.Args = []string{"old", "args"} - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.DeepEqual([]string{"the", "new args"}, cspec.Args)) } @@ -532,18 +532,18 @@ func TestUpdateReadOnly(t *testing.T) { // Update with --read-only=true, changed to true flags := newUpdateCommand(nil).Flags() flags.Set("read-only", "true") - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, cspec.ReadOnly) // Update without --read-only, no change flags = newUpdateCommand(nil).Flags() - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, cspec.ReadOnly) // Update with --read-only=false, changed to false flags = newUpdateCommand(nil).Flags() flags.Set("read-only", "false") - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, !cspec.ReadOnly) } @@ -558,18 +558,18 @@ func TestUpdateInit(t *testing.T) { // Update with --init=true flags := newUpdateCommand(nil).Flags() flags.Set("init", "true") - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.Equal(true, *cspec.Init)) // Update without --init, no change flags = newUpdateCommand(nil).Flags() - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.Equal(true, *cspec.Init)) // Update with --init=false flags = newUpdateCommand(nil).Flags() flags.Set("init", "false") - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.Equal(false, *cspec.Init)) } @@ -584,18 +584,18 @@ func TestUpdateStopSignal(t *testing.T) { // Update with --stop-signal=SIGUSR1 flags := newUpdateCommand(nil).Flags() flags.Set("stop-signal", "SIGUSR1") - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.Equal("SIGUSR1", cspec.StopSignal)) // Update without --stop-signal, no change flags = newUpdateCommand(nil).Flags() - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.Equal("SIGUSR1", cspec.StopSignal)) // Update with --stop-signal=SIGWINCH flags = newUpdateCommand(nil).Flags() flags.Set("stop-signal", "SIGWINCH") - updateService(nil, nil, flags, spec) + updateService(context.TODO(), nil, flags, spec) assert.Check(t, is.Equal("SIGWINCH", cspec.StopSignal)) } From acec6cb56fbfe2bc3cd1c7f0e8dcd5a5c7ed558b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 01:51:07 +0100 Subject: [PATCH 37/63] cli/command/image/build: G107: Potential HTTP request made with variable url (gosec) cli/command/image/build/context.go:235: G107: Potential HTTP request made with variable url (gosec) if resp, err = http.Get(url); err != nil { Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0e4bd30cfe59451f26489d863f926cacd24067d8) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/context.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index e9af9bd358..89ef1db070 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -232,6 +232,7 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read // getWithStatusError does an http.Get() and returns an error if the // status code is 4xx or 5xx. func getWithStatusError(url string) (resp *http.Response, err error) { + // #nosec G107 if resp, err = http.Get(url); err != nil { return nil, err } From 3bfa0f36b2eab06191b8d5da4afcaa68baace9aa Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 01:52:36 +0100 Subject: [PATCH 38/63] cli/command/trust: SA1006: printf-style with no further arguments (staticcheck) ``` cli/command/trust/key_generate.go:91:30: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Fprintf(streams.Out(), err.Error()) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit f0614ca78829de4abb0e286b989aa68f489a166d) Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/key_generate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/trust/key_generate.go b/cli/command/trust/key_generate.go index 5e4661eafb..bca6c45d7d 100644 --- a/cli/command/trust/key_generate.go +++ b/cli/command/trust/key_generate.go @@ -88,7 +88,7 @@ func validateAndGenerateKey(streams command.Streams, keyName string, workingDir pubPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore) if err != nil { - fmt.Fprintf(streams.Out(), err.Error()) + fmt.Fprint(streams.Out(), err.Error()) return errors.Wrapf(err, "failed to generate key for %s", keyName) } From 50a23edef32f13dcad983ae3d70c2f2b8a5c5e23 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 10:10:03 +0100 Subject: [PATCH 39/63] cli/command/utils: SA1006: printf-style with no further arguments (staticcheck) ``` cli/command/utils.go:81:20: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Fprintf(outs, message) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit ea64a1ceb92bea858b8a1e701ac352ccd57467fc) Signed-off-by: Sebastiaan van Stijn --- cli/command/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/utils.go b/cli/command/utils.go index b19c9379bb..16b79fe065 100644 --- a/cli/command/utils.go +++ b/cli/command/utils.go @@ -78,7 +78,7 @@ func PromptForConfirmation(ins io.Reader, outs io.Writer, message string) bool { } message += " [y/N] " - fmt.Fprintf(outs, message) + _, _ = fmt.Fprint(outs, message) // On Windows, force the use of the regular OS stdin stream. if runtime.GOOS == "windows" { From fbe24f3e54d625dabf6b8ef4a726ccf1c7274767 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 10:21:20 +0100 Subject: [PATCH 40/63] cli/command/image: SA1006: printf-style with no further arguments (staticcheck) cli/command/image/build.go:434:32: SA1006: printf-style function with dynamic format string and no further arguments should use print-style function instead (staticcheck) fmt.Fprintf(dockerCli.Out(), imageID) ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 709728e723612977102b08b6f6f3212aa235e6f9) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/image/build.go b/cli/command/image/build.go index ef50a29179..6cebf98b6f 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -474,7 +474,7 @@ func runBuild(dockerCli command.Cli, options buildOptions) error { // should be just the image ID and we'll print that to stdout. if options.quiet { imageID = fmt.Sprintf("%s", buildBuff) - fmt.Fprintf(dockerCli.Out(), imageID) + _, _ = fmt.Fprint(dockerCli.Out(), imageID) } if options.imageIDFile != "" { From 98150ae8ac5f9785337cac5770fa8c807ab85aad Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 10:24:55 +0100 Subject: [PATCH 41/63] cli/context/store: SA5001: should check returned error before deferring f.Close() (staticcheck) ``` cli/context/store/store_test.go:156:2: SA5001: should check returned error before deferring f.Close() (staticcheck) defer f.Close() ^ cli/context/store/store_test.go:189:2: SA5001: should check returned error before deferring f.Close() (staticcheck) defer f.Close() ^ cli/context/store/store_test.go:240:2: SA5001: should check returned error before deferring f.Close() (staticcheck) defer f.Close() ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit fe3cc6eb7bef35dd060e338b38ac1e02bfb94c8a) Signed-off-by: Sebastiaan van Stijn --- cli/context/store/store_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/context/store/store_test.go b/cli/context/store/store_test.go index dd8586551d..d1d92b250c 100644 --- a/cli/context/store/store_test.go +++ b/cli/context/store/store_test.go @@ -153,8 +153,8 @@ func TestImportTarInvalid(t *testing.T) { tf := path.Join(testDir, "test.context") f, err := os.Create(tf) - defer f.Close() assert.NilError(t, err) + defer f.Close() tw := tar.NewWriter(f) hdr := &tar.Header{ @@ -186,8 +186,8 @@ func TestImportZip(t *testing.T) { zf := path.Join(testDir, "test.zip") f, err := os.Create(zf) - defer f.Close() assert.NilError(t, err) + defer f.Close() w := zip.NewWriter(f) meta, err := json.Marshal(Metadata{ @@ -237,8 +237,8 @@ func TestImportZipInvalid(t *testing.T) { zf := path.Join(testDir, "test.zip") f, err := os.Create(zf) - defer f.Close() assert.NilError(t, err) + defer f.Close() w := zip.NewWriter(f) df, err := w.Create("dummy-file") From 49253c7b00dd6e4e4e9f79c53abeffa0fdcdb0cf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 12:11:42 +0100 Subject: [PATCH 42/63] cli/command/formatter: Error return value of `ImageWrite` is not checked (errcheck) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 9275e2cb66aabf04a11ed7c58096a94d507b5378) Signed-off-by: Sebastiaan van Stijn --- cli/command/formatter/image_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/command/formatter/image_test.go b/cli/command/formatter/image_test.go index 7efad0a758..6df395457f 100644 --- a/cli/command/formatter/image_test.go +++ b/cli/command/formatter/image_test.go @@ -348,7 +348,8 @@ func TestImageContextWriteWithNoImage(t *testing.T) { } for _, context := range contexts { - ImageWrite(context.context, images) + err := ImageWrite(context.context, images) + assert.NilError(t, err) assert.Check(t, is.Equal(context.expected, out.String())) // Clean buffer out.Reset() From 10fda078a094e4d5df4309d31cb5684f5e083893 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 12:15:01 +0100 Subject: [PATCH 43/63] cli/command: Error return value of `cli.Apply` is not checked (errcheck) ``` cli/command/cli_test.go:297:11: Error return value of `cli.Apply` is not checked (errcheck) cli.Apply( ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 008f6a2da3e175dc13f0845ba51bb0317a36806b) Signed-off-by: Sebastiaan van Stijn --- cli/command/cli_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/command/cli_test.go b/cli/command/cli_test.go index 34d0c219ca..a97702e15e 100644 --- a/cli/command/cli_test.go +++ b/cli/command/cli_test.go @@ -294,11 +294,12 @@ func TestNewDockerCliAndOperators(t *testing.T) { inbuf := bytes.NewBuffer([]byte("input")) outbuf := bytes.NewBuffer(nil) errbuf := bytes.NewBuffer(nil) - cli.Apply( + err = cli.Apply( WithInputStream(ioutil.NopCloser(inbuf)), WithOutputStream(outbuf), WithErrorStream(errbuf), ) + assert.NilError(t, err) // Check input stream inputStream, err := ioutil.ReadAll(cli.In()) assert.NilError(t, err) From bd778fc27b2138a65a84d004fd2f7196e9a6bcb4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 12:16:17 +0100 Subject: [PATCH 44/63] cli/command/formatter: Error return value of `ContainerWrite` is not checked (errcheck) ``` cli/command/formatter/container_test.go:315:17: Error return value of `ContainerWrite` is not checked (errcheck) ContainerWrite(context.context, containers) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e74e2c7741fa0abc0eea12985b93b3c4d4278684) Signed-off-by: Sebastiaan van Stijn --- cli/command/formatter/container_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/command/formatter/container_test.go b/cli/command/formatter/container_test.go index cafb9abdac..9529c4c1a6 100644 --- a/cli/command/formatter/container_test.go +++ b/cli/command/formatter/container_test.go @@ -304,7 +304,8 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) { } for _, context := range contexts { - ContainerWrite(context.context, containers) + err := ContainerWrite(context.context, containers) + assert.NilError(t, err) assert.Check(t, is.Equal(context.expected, out.String())) // Clean buffer out.Reset() From 43b498829b5b59ed6059da96b537506f466b0cac Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:33:25 +0100 Subject: [PATCH 45/63] cli/config: Using the variable on range scope `tc` in function literal (scopelint) ``` cli/config/config_test.go:590:11: Using the variable on range scope `tc` in function literal (scopelint) SetDir(tc.dir) ^ cli/config/config_test.go:591:19: Using the variable on range scope `tc` in function literal (scopelint) f, err := Path(tc.path...) ^ cli/config/config_test.go:592:23: Using the variable on range scope `tc` in function literal (scopelint) assert.Equal(t, f, tc.expected) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 5a2a9d9ca8d8ee55f3a6054c7456e346114c78c5) Signed-off-by: Sebastiaan van Stijn --- cli/config/config_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/config/config_test.go b/cli/config/config_test.go index e334b4c9ab..e984399836 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -578,6 +578,7 @@ func TestConfigPath(t *testing.T) { expectedErr: fmt.Sprintf("is outside of root config directory %q", "dummy"), }, } { + tc := tc t.Run(tc.name, func(t *testing.T) { SetDir(tc.dir) f, err := Path(tc.path...) From a087595fb60cd3536894471803fd303ed6a18d19 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:34:33 +0100 Subject: [PATCH 46/63] service/logs: Using the variable on range scope `testcase` in function literal (scopelint) ``` service/logs/parse_logs_test.go:26:35: Using the variable on range scope `testcase` in function literal (scopelint) actual, err := ParseLogDetails(testcase.line) ^ service/logs/parse_logs_test.go:27:7: Using the variable on range scope `testcase` in function literal (scopelint) if testcase.err != nil { ^ service/logs/parse_logs_test.go:28:26: Using the variable on range scope `testcase` in function literal (scopelint) assert.Error(t, err, testcase.err.Error()) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit c828fa141d06c8add64959440d16c85f8dfb0c7e) Signed-off-by: Sebastiaan van Stijn --- service/logs/parse_logs_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/service/logs/parse_logs_test.go b/service/logs/parse_logs_test.go index 24bd0db7b7..4a423b9eb8 100644 --- a/service/logs/parse_logs_test.go +++ b/service/logs/parse_logs_test.go @@ -22,6 +22,7 @@ func TestParseLogDetails(t *testing.T) { {"errors", nil, errors.New("invalid details format")}, } for _, testcase := range testCases { + testcase := testcase t.Run(testcase.line, func(t *testing.T) { actual, err := ParseLogDetails(testcase.line) if testcase.err != nil { From ae7b1f737b203890abc0d050976e9892c387425e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:35:54 +0100 Subject: [PATCH 47/63] templates: Using the variable on range scope `testCase` in function literal (scopelint) ``` templates/templates_test.go:74:29: Using the variable on range scope `testCase` in function literal (scopelint) assert.Check(t, is.Equal(testCase.expected, b.String())) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 54d48de2163e9b1898c3631116836402512b7955) Signed-off-by: Sebastiaan van Stijn --- templates/templates_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/templates_test.go b/templates/templates_test.go index 102de2bd9f..3a007e7b9a 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -65,6 +65,8 @@ func TestParseTruncateFunction(t *testing.T) { } for _, testCase := range testCases { + testCase := testCase + tm, err := Parse(testCase.template) assert.NilError(t, err) From 42ad2446e059e0c35ba4bef8459f276c7d5acf27 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:37:58 +0100 Subject: [PATCH 48/63] cli/compose/loader: Using a reference for the variable on range scope `overrideService` (scopelint) ``` cli/compose/loader/merge.go:64:41: Using a reference for the variable on range scope `overrideService` (scopelint) if err := mergo.Merge(&baseService, &overrideService, mergo.WithAppendSlice, mergo.WithOverride, mergo.WithTransformers(specials)); err != nil { ^ cli/compose/loader/loader_test.go:1587:28: Using the variable on range scope `testcase` in function literal (scopelint) config, err := loadYAML(testcase.yaml) ^ cli/compose/loader/loader_test.go:1590:58: Using the variable on range scope `testcase` in function literal (scopelint) assert.Check(t, is.DeepEqual(config.Services[0].Init, testcase.init)) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 96ec7299d86536c33914f8f7e5bad274f3224717) Signed-off-by: Sebastiaan van Stijn --- cli/compose/loader/loader_test.go | 1 + cli/compose/loader/merge.go | 1 + 2 files changed, 2 insertions(+) diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index d956fb9f5f..6acdacc160 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -1583,6 +1583,7 @@ services: }, } for _, testcase := range testcases { + testcase := testcase t.Run(testcase.doc, func(t *testing.T) { config, err := loadYAML(testcase.yaml) assert.NilError(t, err) diff --git a/cli/compose/loader/merge.go b/cli/compose/loader/merge.go index 24b74ffbc5..015b1f5a55 100644 --- a/cli/compose/loader/merge.go +++ b/cli/compose/loader/merge.go @@ -60,6 +60,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig, }, } for name, overrideService := range overrideServices { + overrideService := overrideService if baseService, ok := baseServices[name]; ok { if err := mergo.Merge(&baseService, &overrideService, mergo.WithAppendSlice, mergo.WithOverride, mergo.WithTransformers(specials)); err != nil { return base, errors.Wrapf(err, "cannot merge service %s", name) From 0cab2689a5af768827d09e24ad323044c0db6db1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:39:32 +0100 Subject: [PATCH 49/63] e2e/cli-plugins: Using the variable on range scope `args` in function literal (scopelint) ``` e2e/cli-plugins/flags_test.go:135:27: Using the variable on range scope `args` in function literal (scopelint) res := icmd.RunCmd(run(args...)) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 1736662bea7b7b2051e40d33a8c50c8fdf93c87b) Signed-off-by: Sebastiaan van Stijn --- e2e/cli-plugins/flags_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/cli-plugins/flags_test.go b/e2e/cli-plugins/flags_test.go index 8335dc62fe..34c3ac3281 100644 --- a/e2e/cli-plugins/flags_test.go +++ b/e2e/cli-plugins/flags_test.go @@ -131,6 +131,7 @@ func TestUnknownGlobal(t *testing.T) { "separate-val": {"--unknown", "foo", "helloworld"}, "joined-val": {"--unknown=foo", "helloworld"}, } { + args := args t.Run(name, func(t *testing.T) { res := icmd.RunCmd(run(args...)) res.Assert(t, icmd.Expected{ From bda413e0aeaad5f0599f86b229e9c2d760782ae6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:40:25 +0100 Subject: [PATCH 50/63] cli/command/context: Using the variable on range scope `c` in function literal (scopelint) ``` cli/command/context/create_test.go:270:31: Using the variable on range scope `c` in function literal (scopelint) Name: c.name, ^ cli/command/context/create_test.go:271:31: Using the variable on range scope `c` in function literal (scopelint) Description: c.description, ^ cli/command/context/create_test.go:272:31: Using the variable on range scope `c` in function literal (scopelint) DefaultStackOrchestrator: c.orchestrator, cli/command/context/create_test.go:346:31: Using the variable on range scope `c` in function literal (scopelint) Name: c.name, ^ cli/command/context/create_test.go:347:31: Using the variable on range scope `c` in function literal (scopelint) Description: c.description, ^ cli/command/context/create_test.go:348:31: Using the variable on range scope `c` in function literal (scopelint) DefaultStackOrchestrator: c.orchestrator, ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit a269e17d726e92a0d85171f55b1af0db5606ad89) Signed-off-by: Sebastiaan van Stijn --- cli/command/context/create_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/command/context/create_test.go b/cli/command/context/create_test.go index 013e82d05e..99af79e5e3 100644 --- a/cli/command/context/create_test.go +++ b/cli/command/context/create_test.go @@ -263,6 +263,7 @@ func TestCreateFromContext(t *testing.T) { cli.SetCurrentContext("dummy") for _, c := range cases { + c := c t.Run(c.name, func(t *testing.T) { cli.ResetOutputBuffers() err := RunCreate(cli, &CreateOptions{ @@ -339,6 +340,7 @@ func TestCreateFromCurrent(t *testing.T) { cli.SetCurrentContext("original") for _, c := range cases { + c := c t.Run(c.name, func(t *testing.T) { cli.ResetOutputBuffers() err := RunCreate(cli, &CreateOptions{ From f7b23cf5728de75f19514e73c4489f9ff44b7c03 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 13:42:59 +0100 Subject: [PATCH 51/63] cli/command/trust: Using the variable on range scope `keyBytes` in function literal (scopelint) ``` cli/command/trust/key_load_test.go:121:27: Using the variable on range scope `keyID` in function literal (scopelint) testLoadKeyFromPath(t, keyID, keyBytes) ^ cli/command/trust/key_load_test.go:176:32: Using the variable on range scope `keyBytes` in function literal (scopelint) testLoadKeyTooPermissive(t, keyBytes) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 7c4b63b1c3d81dc1fa8b13802a41d677e54a742d) Signed-off-by: Sebastiaan van Stijn --- cli/command/trust/key_load_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/command/trust/key_load_test.go b/cli/command/trust/key_load_test.go index e0e35aab9b..b8c89f1cd5 100644 --- a/cli/command/trust/key_load_test.go +++ b/cli/command/trust/key_load_test.go @@ -117,6 +117,7 @@ var testKeys = map[string][]byte{ func TestLoadKeyFromPath(t *testing.T) { skip.If(t, runtime.GOOS == "windows") for keyID, keyBytes := range testKeys { + keyID, keyBytes := keyID, keyBytes t.Run(fmt.Sprintf("load-key-id-%s-from-path", keyID), func(t *testing.T) { testLoadKeyFromPath(t, keyID, keyBytes) }) @@ -172,6 +173,7 @@ func testLoadKeyFromPath(t *testing.T, privKeyID string, privKeyFixture []byte) func TestLoadKeyTooPermissive(t *testing.T) { skip.If(t, runtime.GOOS == "windows") for keyID, keyBytes := range testKeys { + keyID, keyBytes := keyID, keyBytes t.Run(fmt.Sprintf("load-key-id-%s-too-permissive", keyID), func(t *testing.T) { testLoadKeyTooPermissive(t, keyBytes) }) From b083f625e40f6ca851170c1d9d5c6f5532f41723 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:00:31 +0100 Subject: [PATCH 52/63] cli: remove unnecessary newlines (whitespace) ``` cli/config/config_test.go:465: unnecessary trailing newline (whitespace) } cli/compose/interpolation/interpolation.go:56: unnecessary leading newline (whitespace) switch value := value.(type) { cli/compose/interpolation/interpolation.go:94: unnecessary trailing newline (whitespace) } cli/command/image/build/context.go:348: unnecessary trailing newline (whitespace) } internal/licenseutils/client_test.go:98: unnecessary leading newline (whitespace) func (c *fakeLicensingClient) LoadLocalLicense(ctx context.Context, dclnt licensing.WrappedDockerClient) (*model.Subscription, error) { cli/registry/client/fetcher.go:211: unnecessary leading newline (whitespace) for _, endpoint := range endpoints { ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 612d83d6dfabded3891c166d3d2537f12895af4f) Signed-off-by: Sebastiaan van Stijn --- cli/command/image/build/context.go | 1 - cli/compose/interpolation/interpolation.go | 2 -- cli/compose/schema/schema_test.go | 1 - cli/config/config_test.go | 1 - cli/context/store/tlsstore_test.go | 1 - cli/registry/client/fetcher.go | 1 - 6 files changed, 7 deletions(-) diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index 89ef1db070..2ced3386bf 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -345,7 +345,6 @@ func getDockerfileRelPath(absContextDir, givenDockerfile string) (string, error) absDockerfile, err = filepath.EvalSymlinks(absDockerfile) if err != nil { return "", errors.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err) - } } diff --git a/cli/compose/interpolation/interpolation.go b/cli/compose/interpolation/interpolation.go index d4f5c4a43f..fd34ca82ea 100644 --- a/cli/compose/interpolation/interpolation.go +++ b/cli/compose/interpolation/interpolation.go @@ -54,7 +54,6 @@ func Interpolate(config map[string]interface{}, opts Options) (map[string]interf func recursiveInterpolate(value interface{}, path Path, opts Options) (interface{}, error) { switch value := value.(type) { - case string: newValue, err := opts.Substitute(value, template.Mapping(opts.LookupValue)) if err != nil || newValue == value { @@ -91,7 +90,6 @@ func recursiveInterpolate(value interface{}, path Path, opts Options) (interface default: return value, nil - } } diff --git a/cli/compose/schema/schema_test.go b/cli/compose/schema/schema_test.go index 10c40bba72..3133400c49 100644 --- a/cli/compose/schema/schema_test.go +++ b/cli/compose/schema/schema_test.go @@ -117,7 +117,6 @@ func TestValidateCredentialSpecs(t *testing.T) { } }) } - } func TestValidateSecretConfigNames(t *testing.T) { diff --git a/cli/config/config_test.go b/cli/config/config_test.go index e984399836..4ca981e6ce 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -454,7 +454,6 @@ func TestJSONWithPsFormatNoFile(t *testing.T) { if config.PsFormat != `table {{.ID}}\t{{.Label "com.docker.label.cpu"}}` { t.Fatalf("Unknown ps format: %s\n", config.PsFormat) } - } func TestJSONSaveWithNoFile(t *testing.T) { diff --git a/cli/context/store/tlsstore_test.go b/cli/context/store/tlsstore_test.go index 6079de0f8e..e8d029606e 100644 --- a/cli/context/store/tlsstore_test.go +++ b/cli/context/store/tlsstore_test.go @@ -75,5 +75,4 @@ func TestTlsListAndBatchRemove(t *testing.T) { resEmpty, err := testee.listContextData("test-ctx") assert.NilError(t, err) assert.DeepEqual(t, resEmpty, map[string]EndpointFiles{}) - } diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index 2060f99126..678ea2649e 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -209,7 +209,6 @@ func (c *client) iterateEndpoints(ctx context.Context, namedRef reference.Named, confirmedTLSRegistries := make(map[string]bool) for _, endpoint := range endpoints { - if endpoint.Version == registry.APIVersion1 { logrus.Debugf("skipping v1 endpoint %s", endpoint.URL) continue From be5a3ccb7d22e0df20a6c5c6ff88bb21e83f9eab Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:37:37 +0100 Subject: [PATCH 53/63] cli/command: Using the variable on range scope `testcase` in function literal (scopelint) ``` cli/command/cli_test.go:157:15: Using the variable on range scope `testcase` in function literal (scopelint) pingFunc: testcase.pingFunc, ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 2ec424a2d998233329e9b8d2914830033aea7837) Signed-off-by: Sebastiaan van Stijn --- cli/command/cli_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/command/cli_test.go b/cli/command/cli_test.go index a97702e15e..dcff1bb569 100644 --- a/cli/command/cli_test.go +++ b/cli/command/cli_test.go @@ -152,6 +152,7 @@ func TestInitializeFromClient(t *testing.T) { } for _, testcase := range testcases { + testcase := testcase t.Run(testcase.doc, func(t *testing.T) { apiclient := &fakeClient{ pingFunc: testcase.pingFunc, @@ -189,6 +190,7 @@ func TestExperimentalCLI(t *testing.T) { } for _, testcase := range testcases { + testcase := testcase t.Run(testcase.doc, func(t *testing.T) { dir := fs.NewDir(t, testcase.doc, fs.WithFile("config.json", testcase.configfile)) defer dir.Remove() @@ -242,6 +244,7 @@ func TestGetClientWithPassword(t *testing.T) { } for _, testcase := range testcases { + testcase := testcase t.Run(testcase.doc, func(t *testing.T) { passRetriever := func(_, _ string, _ bool, attempts int) (passphrase string, giveup bool, err error) { // Always return an invalid pass first to test iteration From 09c94458c7f2869776e6bdb3b9bc7a0eee96980a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:03:06 +0100 Subject: [PATCH 54/63] internal: remove unnecessary newlines (whitespace) ``` internal/licenseutils/client_test.go:98: unnecessary leading newline (whitespace) func (c *fakeLicensingClient) LoadLocalLicense(ctx context.Context, dclnt licensing.WrappedDockerClient) (*model.Subscription, error) { ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 63e45e6320c4351b4ab0190714580d92e8a299e1) Signed-off-by: Sebastiaan van Stijn --- internal/containerizedengine/progress.go | 1 - internal/licenseutils/client_test.go | 1 - internal/versions/versions.go | 1 - 3 files changed, 3 deletions(-) diff --git a/internal/containerizedengine/progress.go b/internal/containerizedengine/progress.go index 9ff2be52ab..e40b5a45d2 100644 --- a/internal/containerizedengine/progress.go +++ b/internal/containerizedengine/progress.go @@ -93,7 +93,6 @@ outer: } func updateNonActive(ctx context.Context, ongoing *jobs, cs content.Store, statuses map[string]statusInfo, keys *[]string, activeSeen map[string]struct{}, done *bool, start time.Time) error { - for _, j := range ongoing.jobs() { key := remotes.MakeRefKey(ctx, j) *keys = append(*keys, key) diff --git a/internal/licenseutils/client_test.go b/internal/licenseutils/client_test.go index b0b202ebb1..9e46202f28 100644 --- a/internal/licenseutils/client_test.go +++ b/internal/licenseutils/client_test.go @@ -96,7 +96,6 @@ func (c *fakeLicensingClient) StoreLicense(ctx context.Context, dclnt licensing. } func (c *fakeLicensingClient) LoadLocalLicense(ctx context.Context, dclnt licensing.WrappedDockerClient) (*model.Subscription, error) { - if c.loadLocalLicenseFunc != nil { return c.loadLocalLicenseFunc(ctx, dclnt) diff --git a/internal/versions/versions.go b/internal/versions/versions.go index 9e83bb371a..5e09eb65fd 100644 --- a/internal/versions/versions.go +++ b/internal/versions/versions.go @@ -24,7 +24,6 @@ const ( // GetEngineVersions reports the versions of the engine that are available func GetEngineVersions(ctx context.Context, registryClient registryclient.RegistryClient, registryPrefix, imageName, versionString string) (clitypes.AvailableVersions, error) { - if imageName == "" { var err error localMetadata, err := GetCurrentRuntimeMetadata("") From 65e0d7c5627d3f4d520dc1539ab5dd3c41d1ef57 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:47:14 +0100 Subject: [PATCH 55/63] e2e: remove unnecessary trailing newline (whitespace) Signed-off-by: Sebastiaan van Stijn (cherry picked from commit dd4d216afdce039da39e879572a7b896e3c4cb7f) Signed-off-by: Sebastiaan van Stijn --- e2e/trust/sign_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/trust/sign_test.go b/e2e/trust/sign_test.go index ffa320e904..da054530e0 100644 --- a/e2e/trust/sign_test.go +++ b/e2e/trust/sign_test.go @@ -31,7 +31,6 @@ func TestSignLocalImage(t *testing.T) { fixtures.WithConfig(dir.Path()), fixtures.WithNotary) result.Assert(t, icmd.Success) assert.Check(t, is.Contains(result.Stdout(), fmt.Sprintf("v1: digest: sha256:%s", fixtures.AlpineSha))) - } func TestSignWithLocalFlag(t *testing.T) { From 37ef1f56f7806a8965f60b00198e7ecf19f93f33 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:04:33 +0100 Subject: [PATCH 56/63] cli/command/container: suppress dogsled warnings ``` cli/command/container/opts_test.go:68:2: declaration has 3 blank identifiers (dogsled) _, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) ^ cli/command/container/opts_test.go:542:2: declaration has 3 blank identifiers (dogsled) _, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) ^ cli/command/container/opts_test.go:603:2: declaration has 3 blank identifiers (dogsled) _, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 79dc83e78be346103189aa66cde0ec2e6f64a70e) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/opts_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index a64b7c6a30..e8c71e2388 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -65,7 +65,7 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) { } func parseMustError(t *testing.T, args string) { - _, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) + _, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) //nolint:dogsled assert.ErrorContains(t, err, "", args) } @@ -539,7 +539,7 @@ func TestParseModes(t *testing.T) { } // uts ko - _, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) + _, _, _, err = parseRun([]string{"--uts=container:", "img", "cmd"}) //nolint:dogsled assert.ErrorContains(t, err, "--uts: invalid UTS mode") // uts ok @@ -600,7 +600,7 @@ func TestParseRestartPolicy(t *testing.T) { func TestParseRestartPolicyAutoRemove(t *testing.T) { expected := "Conflicting options: --restart and --rm" - _, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) + _, _, _, err := parseRun([]string{"--rm", "--restart=always", "img", "cmd"}) //nolint:dogsled if err == nil || err.Error() != expected { t.Fatalf("Expected error %v, but got none", expected) } From fccc105d4d7cbed82ac56ac7802a15d6f4577091 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:05:56 +0100 Subject: [PATCH 57/63] cli/compose/template: Using the variable on range scope `tc` in function literal (scopelint) ``` cli/compose/template/template_test.go:279:31: Using the variable on range scope `tc` in function literal (scopelint) actual := ExtractVariables(tc.dict, defaultPattern) ^ cli/compose/template/template_test.go:280:41: Using the variable on range scope `tc` in function literal (scopelint) assert.Check(t, is.DeepEqual(actual, tc.expected)) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit aafe3df8b394a9fd5abab5eff48c125c4521f13a) Signed-off-by: Sebastiaan van Stijn --- cli/compose/template/template_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/compose/template/template_test.go b/cli/compose/template/template_test.go index ce3690410f..b1610009bb 100644 --- a/cli/compose/template/template_test.go +++ b/cli/compose/template/template_test.go @@ -275,6 +275,7 @@ func TestExtractVariables(t *testing.T) { }, } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { actual := ExtractVariables(tc.dict, defaultPattern) assert.Check(t, is.DeepEqual(actual, tc.expected)) From 1b35214c11c3504a926dcfa8354a8cc42dbe0743 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:07:20 +0100 Subject: [PATCH 58/63] cli/manifest: Using the variable on range scope `testcase` in function literal (scopelint) ``` cli/manifest/store/store_test.go:97:29: Using the variable on range scope `testcase` in function literal (scopelint) actual, err := store.Get(testcase.listRef, testcase.manifestRef) ^ cli/manifest/store/store_test.go:98:7: Using the variable on range scope `testcase` in function literal (scopelint) if testcase.expectedErr != "" { ^ cli/manifest/store/store_test.go:99:26: Using the variable on range scope `testcase` in function literal (scopelint) assert.Error(t, err, testcase.expectedErr) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit cd3dca37b8f373cd137d4732cf614037d7828d9c) Signed-off-by: Sebastiaan van Stijn --- cli/manifest/store/store_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/manifest/store/store_test.go b/cli/manifest/store/store_test.go index ae56fea924..aa06afd35c 100644 --- a/cli/manifest/store/store_test.go +++ b/cli/manifest/store/store_test.go @@ -93,6 +93,7 @@ func TestStoreSaveAndGet(t *testing.T) { } for _, testcase := range testcases { + testcase := testcase t.Run(testcase.manifestRef.String(), func(t *testing.T) { actual, err := store.Get(testcase.listRef, testcase.manifestRef) if testcase.expectedErr != "" { From 201e44907dd85bb6eeea1dbb583d652c46a835ee Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:08:12 +0100 Subject: [PATCH 59/63] opts: Using the variable on range scope `tc` in function literal (scopelint) ``` opts/network_test.go:74:35: Using the variable on range scope `tc` in function literal (scopelint) assert.NilError(t, network.Set(tc.value)) ^ opts/network_test.go:102:40: Using the variable on range scope `tc` in function literal (scopelint) assert.ErrorContains(t, network.Set(tc.value), tc.expectedError) ^ opts/opts_test.go:270:30: Using the variable on range scope `tc` in function literal (scopelint) val, err := ValidateLabel(tc.value) ^ opts/opts_test.go:271:7: Using the variable on range scope `tc` in function literal (scopelint) if tc.expectedErr != "" { ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit c2b069f4db2adcbc86cf5b912741e4eb42505b09) Signed-off-by: Sebastiaan van Stijn --- opts/network_test.go | 2 ++ opts/opts_test.go | 1 + 2 files changed, 3 insertions(+) diff --git a/opts/network_test.go b/opts/network_test.go index 1867d8ac8b..0d38955dc5 100644 --- a/opts/network_test.go +++ b/opts/network_test.go @@ -69,6 +69,7 @@ func TestNetworkOptAdvancedSyntax(t *testing.T) { }, } for _, tc := range testCases { + tc := tc t.Run(tc.value, func(t *testing.T) { var network NetworkOpt assert.NilError(t, network.Set(tc.value)) @@ -96,6 +97,7 @@ func TestNetworkOptAdvancedSyntaxInvalid(t *testing.T) { }, } for _, tc := range testCases { + tc := tc t.Run(tc.value, func(t *testing.T) { var network NetworkOpt assert.ErrorContains(t, network.Set(tc.value), tc.expectedError) diff --git a/opts/opts_test.go b/opts/opts_test.go index 4d5ef1749e..9c9f9689ff 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -266,6 +266,7 @@ func TestValidateLabel(t *testing.T) { } for _, tc := range tests { + tc := tc t.Run(tc.name, func(t *testing.T) { val, err := ValidateLabel(tc.value) if tc.expectedErr != "" { From 73dad4356e89593827d7d8547243c2fa30d97343 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:16:54 +0100 Subject: [PATCH 60/63] cli/command/stack/kubernetes: Using a reference for the variable on range scope `obj` (scopelint) ``` cli/command/stack/kubernetes/watcher_test.go:44:20: Using a reference for the variable on range scope `obj` (scopelint) if err := o.Add(&obj); err != nil { ^ cli/command/stack/kubernetes/watcher_test.go:49:20: Using a reference for the variable on range scope `obj` (scopelint) if err := o.Add(&obj); err != nil { ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 754fc6fe677773cce9c31c4d77449a4227b35552) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/kubernetes/watcher_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/command/stack/kubernetes/watcher_test.go b/cli/command/stack/kubernetes/watcher_test.go index 0972a91461..c02655e8aa 100644 --- a/cli/command/stack/kubernetes/watcher_test.go +++ b/cli/command/stack/kubernetes/watcher_test.go @@ -41,11 +41,13 @@ func newTestPodAndStackRepository(initialPods []apiv1.Pod, initialStacks []apiv1 o := k8stesting.NewObjectTracker(scheme, codecs.UniversalDecoder()) for _, obj := range initialPods { + obj := obj if err := o.Add(&obj); err != nil { panic(err) } } for _, obj := range initialStacks { + obj := obj if err := o.Add(&obj); err != nil { panic(err) } From b320feff9b9174bf4e8052e9d3b4a62028f86031 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:41:38 +0100 Subject: [PATCH 61/63] cli/command/container: Using the variable on range scope `c` in function literal (scopelint) ``` cli/command/container/create_test.go:120:20: Using the variable on range scope `c` in function literal (scopelint) defer func() { c.ResponseCounter++ }() ^ cli/command/container/create_test.go:121:12: Using the variable on range scope `c` in function literal (scopelint) switch c.ResponseCounter { ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 542f80241eab952af1b581ba36e941775d044011) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/create_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index 29912d44dc..544943db19 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -151,6 +151,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) { }, } for _, tc := range testCases { + tc := tc cli := test.NewFakeCli(&fakeClient{ createContainerFunc: func(config *container.Config, hostConfig *container.HostConfig, @@ -209,6 +210,7 @@ func TestNewCreateCommandWithWarnings(t *testing.T) { }, } for _, tc := range testCases { + tc := tc t.Run(tc.name, func(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ createContainerFunc: func(config *container.Config, From e70edc35768bb17d7b2db04e38a148bd0835c267 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Oct 2019 14:44:09 +0100 Subject: [PATCH 62/63] cli/command/stack/kubernetes: Using the variable on range scope `c` in function literal (scopelint) ``` cli/command/stack/kubernetes/convert_test.go:199:35: Using the variable on range scope `c` in function literal (scopelint) conv, err := NewStackConverter(c.version) ^ ``` Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 640305f33c460aae129f1a20bf3f4d7d7865414e) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/kubernetes/convert_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cli/command/stack/kubernetes/convert_test.go b/cli/command/stack/kubernetes/convert_test.go index 1cdf4f276b..05d1748e55 100644 --- a/cli/command/stack/kubernetes/convert_test.go +++ b/cli/command/stack/kubernetes/convert_test.go @@ -195,6 +195,7 @@ func TestHandlePullSecret(t *testing.T) { } for _, c := range cases { + c := c t.Run(c.version, func(t *testing.T) { conv, err := NewStackConverter(c.version) assert.NilError(t, err) @@ -222,6 +223,7 @@ func TestHandlePullPolicy(t *testing.T) { } for _, c := range cases { + c := c t.Run(c.version, func(t *testing.T) { conv, err := NewStackConverter(c.version) assert.NilError(t, err) @@ -271,6 +273,7 @@ func TestHandleInternalServiceType(t *testing.T) { }, } for _, c := range cases { + c := c t.Run(c.name, func(t *testing.T) { res, err := fromComposeServiceConfig(composetypes.ServiceConfig{ Name: "test", From 7374c0a15296142f6495dd989ddca4324c645695 Mon Sep 17 00:00:00 2001 From: Silvin Lubecki Date: Tue, 2 Apr 2019 17:27:12 +0200 Subject: [PATCH 63/63] Remove now obsolete gometalinter and use golangci-lint instead Signed-off-by: Silvin Lubecki Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b7e06f2845bb4996269a49f2592a735e4cd03e49) Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 83 +++++++++++++++++++++++++++++++++++++ dockerfiles/Dockerfile.lint | 31 +++++++------- gometalinter.json | 46 -------------------- 3 files changed, 100 insertions(+), 60 deletions(-) create mode 100644 .golangci.yml delete mode 100644 gometalinter.json diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..c3add27d17 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,83 @@ +linters: + enable: + - bodyclose + - deadcode + - dogsled + - gocyclo + - goimports + - golint + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - lll + - megacheck + - misspell + - nakedret + - staticcheck + - structcheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + + disable: + - errcheck + +run: + timeout: 5m + skip-dirs: + - cli/command/stack/kubernetes/api/openapi + - cli/command/stack/kubernetes/api/client + skip-files: + - cli/compose/schema/bindata.go + - .*generated.* + +linters-settings: + gocyclo: + min-complexity: 16 + govet: + check-shadowing: false + lll: + line-length: 200 + nakedret: + command: nakedret + pattern: ^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$ + +issues: + # The default exclusion rules are a bit too permissive, so copying the relevant ones below + exclude-use-default: false + + exclude: + - parameter .* always receives + + exclude-rules: + # These are copied from the default exclude rules, except for "ineffective break statement" + # and GoDoc checks. + # https://github.com/golangci/golangci-lint/blob/0cc87df732aaf1d5ad9ce9ca538d38d916918b36/pkg/config/config.go#L36 + - text: "Error return value of .((os\\.)?std(out|err)\\..*|.*Close|.*Flush|os\\.Remove(All)?|.*printf?|os\\.(Un)?Setenv). is not checked" + linters: + - errcheck + - text: "func name will be used as test\\.Test.* by other packages, and that stutters; consider calling this" + linters: + - golint + - text: "G103: Use of unsafe calls should be audited" + linters: + - gosec + - text: "G104: Errors unhandled" + linters: + - gosec + - text: "G204: Subprocess launch(ed with (variable|function call)|ing should be audited)" + linters: + - gosec + - text: "(G301|G302): (Expect directory permissions to be 0750 or less|Expect file permissions to be 0600 or less)" + linters: + - gosec + - text: "G304: Potential file inclusion via variable" + linters: + - gosec + - text: "(G201|G202): SQL string (formatting|concatenation)" + linters: + - gosec diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 1d30d87b3f..be30abec28 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,20 +1,23 @@ +# syntax=docker/dockerfile:1.1.3-experimental + ARG GO_VERSION=1.12.12 +ARG GOLANGCI_LINTER_SHA="v1.21.0" -FROM golang:${GO_VERSION}-alpine +FROM golang:${GO_VERSION}-alpine AS build +ENV CGO_ENABLED=0 +RUN apk add --no-cache git +ARG GOLANGCI_LINTER_SHA +ARG GO111MODULE=on +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg/mod \ + go get github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINTER_SHA} -RUN apk add -U git - -ARG GOMETALINTER_SHA=v2.0.6 -RUN go get -d github.com/alecthomas/gometalinter && \ - cd /go/src/github.com/alecthomas/gometalinter && \ - git checkout -q "$GOMETALINTER_SHA" && \ - go build -v -o /usr/local/bin/gometalinter . && \ - gometalinter --install && \ - rm -rf /go/src/* /go/pkg/* - -WORKDIR /go/src/github.com/docker/cli +FROM golang:${GO_VERSION}-alpine AS lint ENV CGO_ENABLED=0 ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 -ENTRYPOINT ["/usr/local/bin/gometalinter"] -CMD ["--config=gometalinter.json", "./..."] +COPY --from=build /go/bin/golangci-lint /usr/local/bin +WORKDIR /go/src/github.com/docker/cli +ENV GOGC=75 +ENTRYPOINT ["/usr/local/bin/golangci-lint"] +CMD ["run", "--config=.golangci.yml"] COPY . . diff --git a/gometalinter.json b/gometalinter.json deleted file mode 100644 index f2b2e8545d..0000000000 --- a/gometalinter.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "Vendor": true, - "Deadline": "3m", - "Sort": ["linter", "severity", "path", "line"], - "Skip": [ - "cli/compose/schema/bindata.go", - "cli/command/stack/kubernetes/api/openapi", - "cli/command/stack/kubernetes/api/client", - ".*generated.*", - "vendor" - ], - "Exclude": [ - "parameter .* always receives", - "_esc(Dir|FS|FSString|FSMustString) is unused" - ], - "EnableGC": true, - "Linters": { - "nakedret": { - "Command": "nakedret", - "Pattern": "^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$" - } - }, - "WarnUnmatchedDirective": true, - - "DisableAll": true, - "Enable": [ - "deadcode", - "gocyclo", - "gofmt", - "goimports", - "golint", - "gosimple", - "ineffassign", - "interfacer", - "lll", - "misspell", - "nakedret", - "unconvert", - "unparam", - "unused", - "vet" - ], - - "Cyclo": 16, - "LineLength": 200 -}