From 7a9b855ccac07623e5e4860de6d0d2518b2eefe5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 19 Feb 2024 14:13:51 +0100 Subject: [PATCH 01/27] update to go1.21.7 go1.21.7 (released 2024-02-06) includes fixes to the compiler, the go command, the runtime, and the crypto/x509 package. See the Go 1.21.7 milestone on our issue tracker for details: - https://github.com/golang/go/issues?q=milestone%3AGo1.21.7+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.6...go1.21.7 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 20b9d489e044b7e1d65d3c568a147fb9a91a5113) Signed-off-by: Austin Vazquez --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 96c1d61b36f2..2def3d73534b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.20.13 + go-version: 1.21.7 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index 5316fc3b6071..78fed8bd83e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.20.13 +ARG GO_VERSION=1.21.7 ARG ALPINE_VERSION=3.18 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index 058b75bb9f07..2be99233f39a 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.20.13" + default = "1.21.7" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 4612c1b0cb5c..0217fdf80e56 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.20.13 +ARG GO_VERSION=1.21.7 ARG ALPINE_VERSION=3.18 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index f3e927ae4c43..d64f419ce179 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.20.13 +ARG GO_VERSION=1.21.7 ARG ALPINE_VERSION=3.18 ARG GOLANGCI_LINT_VERSION=v1.52.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index d8a0fab08d10..1fc74d9535e4 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.20.13 +ARG GO_VERSION=1.21.7 ARG ALPINE_VERSION=3.18 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index 054ced337d3e..7a3590f43e74 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.20.13 +ARG GO_VERSION=1.21.7 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 77a921c5c84380a736c8df17947e00b7856dc703 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 28 Aug 2023 23:21:03 +0200 Subject: [PATCH 02/27] update golangci-lint to v1.54.2 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit db6209abdddf2da9cc1bcdb8d2aa478cd5e6ba39) Signed-off-by: Austin Vazquez --- .golangci.yml | 11 +++++------ cli/command/service/opts.go | 2 +- dockerfiles/Dockerfile.lint | 2 +- e2e/internal/fixtures/fixtures.go | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 32ad73a065ac..5553fb533792 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,12 +32,11 @@ run: linters-settings: depguard: - list-type: blacklist - include-go-root: true - packages: - # The io/ioutil package has been deprecated. - # https://go.dev/doc/go1.16#ioutil - - io/ioutil + rules: + main: + deny: + - pkg: io/ioutil + desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil gocyclo: min-complexity: 16 govet: diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 97201fd432de..2149241af26b 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -1001,7 +1001,7 @@ const ( flagTTY = "tty" flagUpdateDelay = "update-delay" flagUpdateFailureAction = "update-failure-action" - flagUpdateMaxFailureRatio = "update-max-failure-ratio" + flagUpdateMaxFailureRatio = "update-max-failure-ratio" // #nosec G101 -- ignoring: Potential hardcoded credentials (gosec) flagUpdateMonitor = "update-monitor" flagUpdateOrder = "update-order" flagUpdateParallelism = "update-parallelism" diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index d64f419ce179..c98c559f65dd 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -2,7 +2,7 @@ ARG GO_VERSION=1.21.7 ARG ALPINE_VERSION=3.18 -ARG GOLANGCI_LINT_VERSION=v1.52.2 +ARG GOLANGCI_LINT_VERSION=v1.54.2 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint diff --git a/e2e/internal/fixtures/fixtures.go b/e2e/internal/fixtures/fixtures.go index 7672c033b5d1..700928b03b8e 100644 --- a/e2e/internal/fixtures/fixtures.go +++ b/e2e/internal/fixtures/fixtures.go @@ -17,11 +17,11 @@ const ( // AlpineImage is an image in the test registry AlpineImage = "registry:5000/alpine:3.6" // AlpineSha is the sha of the alpine image - AlpineSha = "641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d" + AlpineSha = "641b95ddb2ea9dc2af1a0113b6b348ebc20872ba615204fbe12148e98fd6f23d" // #nosec G101 -- ignoring: Potential hardcoded credentials (gosec) // BusyboxImage is an image in the test registry BusyboxImage = "registry:5000/busybox:1.27.2" // BusyboxSha is the sha of the busybox image - BusyboxSha = "030fcb92e1487b18c974784dcc110a93147c9fc402188370fbfd17efabffc6af" + BusyboxSha = "030fcb92e1487b18c974784dcc110a93147c9fc402188370fbfd17efabffc6af" // #nosec G101 -- ignoring: Potential hardcoded credentials (gosec) ) // SetupConfigFile creates a config.json file for testing From 7ff18d219ffdd866b766f90b4d7dd0e037b406b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Tue, 5 Mar 2024 22:04:00 +0100 Subject: [PATCH 03/27] update to go1.21.8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit go1.21.8 (released 2024-03-05) includes 5 security fixes: - crypto/x509: Verify panics on certificates with an unknown public key algorithm (CVE-2024-24783, https://go.dev/issue/65390) - net/http: memory exhaustion in Request.ParseMultipartForm (CVE-2023-45290, https://go.dev/issue/65383) - net/http, net/http/cookiejar: incorrect forwarding of sensitive headers and cookies on HTTP redirect (CVE-2023-45289, https://go.dev/issue/65065) - html/template: errors returned from MarshalJSON methods may break template escaping (CVE-2024-24785, https://go.dev/issue/65697) - net/mail: comments in display names are incorrectly handled (CVE-2024-24784, https://go.dev/issue/65083) View the release notes for more information: https://go.dev/doc/devel/release#go1.21.8 - https://github.com/golang/go/issues?q=milestone%3AGo1.21.8+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.6...go1.21.8 Signed-off-by: Paweł Gronowski (cherry picked from commit 3b7747794392e448a9b5ea9cef85972258e0aa2b) Signed-off-by: Austin Vazquez --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2def3d73534b..6e5f550c8c5e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.7 + go-version: 1.21.8 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index 78fed8bd83e1..f7adec96afe5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.7 +ARG GO_VERSION=1.21.8 ARG ALPINE_VERSION=3.18 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index 2be99233f39a..fccd07088827 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.7" + default = "1.21.8" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 0217fdf80e56..ae3b7153bcbc 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.7 +ARG GO_VERSION=1.21.8 ARG ALPINE_VERSION=3.18 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index c98c559f65dd..4c9a246fa9ce 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.7 +ARG GO_VERSION=1.21.8 ARG ALPINE_VERSION=3.18 ARG GOLANGCI_LINT_VERSION=v1.54.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index 1fc74d9535e4..897176a5a2f5 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.7 +ARG GO_VERSION=1.21.8 ARG ALPINE_VERSION=3.18 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index 7a3590f43e74..f47d3d695677 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.7 +ARG GO_VERSION=1.21.8 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 7dd9a687f162a16ed29964b6a0214d17c45e7b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 5 Apr 2024 12:39:50 +0200 Subject: [PATCH 04/27] update to go1.21.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit go1.21.9 (released 2024-04-03) includes a security fix to the net/http package, as well as bug fixes to the linker, and the go/types and net/http packages. See the Go 1.21.9 milestone on our issue tracker for details. - https://github.com/golang/go/issues?q=milestone%3AGo1.21.9+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.8...go1.21.9 **- Description for the changelog** ```markdown changelog Update Go runtime to 1.21.9 ``` Signed-off-by: Paweł Gronowski (cherry picked from commit 0a5bd6c75b8b70a74478d1f679516114213f0a6e) Signed-off-by: Austin Vazquez --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e5f550c8c5e..2ac9ca7c465a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.8 + go-version: 1.21.9 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index f7adec96afe5..7204dabe4789 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.8 +ARG GO_VERSION=1.21.9 ARG ALPINE_VERSION=3.18 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index fccd07088827..68d4bba69618 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.8" + default = "1.21.9" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index ae3b7153bcbc..fdeb5ffe85d6 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.8 +ARG GO_VERSION=1.21.9 ARG ALPINE_VERSION=3.18 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 4c9a246fa9ce..91635d63e85b 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.8 +ARG GO_VERSION=1.21.9 ARG ALPINE_VERSION=3.18 ARG GOLANGCI_LINT_VERSION=v1.54.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index 897176a5a2f5..39d8e96ff70d 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.8 +ARG GO_VERSION=1.21.9 ARG ALPINE_VERSION=3.18 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index f47d3d695677..367a9f059aa1 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.8 +ARG GO_VERSION=1.21.9 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 6131eb9dbc570bb239d1207f5a02ab8cd38498d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 8 May 2024 09:50:01 +0200 Subject: [PATCH 05/27] update to go1.21.10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These minor releases include 2 security fixes following the security policy: - cmd/go: arbitrary code execution during build on darwin On Darwin, building a Go module which contains CGO can trigger arbitrary code execution when using the Apple version of ld, due to usage of the -lto_library flag in a "#cgo LDFLAGS" directive. Thanks to Juho Forsén of Mattermost for reporting this issue. This is CVE-2024-24787 and Go issue https://go.dev/issue/67119. - net: malformed DNS message can cause infinite loop A malformed DNS message in response to a query can cause the Lookup functions to get stuck in an infinite loop. Thanks to long-name-let-people-remember-you on GitHub for reporting this issue, and to Mateusz Poliwczak for bringing the issue to our attention. This is CVE-2024-24788 and Go issue https://go.dev/issue/66754. View the release notes for more information: https://go.dev/doc/devel/release#go1.22.3 - https://github.com/golang/go/issues?q=milestone%3AGo1.21.10+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.9...go1.21.10 **- Description for the changelog** ```markdown changelog Update Go runtime to 1.21.10 ``` Signed-off-by: Paweł Gronowski (cherry picked from commit eb99994c75752c78e08c902ea02e7f359bad1af7) Signed-off-by: Austin Vazquez --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ac9ca7c465a..c38788493cfc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.9 + go-version: 1.21.10 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index 7204dabe4789..ed8ba001d398 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.9 +ARG GO_VERSION=1.21.10 ARG ALPINE_VERSION=3.18 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index 68d4bba69618..48061ed05851 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.9" + default = "1.21.10" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index fdeb5ffe85d6..a1cc51d9b76b 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.9 +ARG GO_VERSION=1.21.10 ARG ALPINE_VERSION=3.18 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 91635d63e85b..9c4d43f4ddfc 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.9 +ARG GO_VERSION=1.21.10 ARG ALPINE_VERSION=3.18 ARG GOLANGCI_LINT_VERSION=v1.54.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index 39d8e96ff70d..dd8098dd9e13 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.9 +ARG GO_VERSION=1.21.10 ARG ALPINE_VERSION=3.18 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index 367a9f059aa1..ba9cc033e854 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.9 +ARG GO_VERSION=1.21.10 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 1da2df7800dbae0596fc7c37a5ebfdd32ed51f39 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 26 May 2024 11:37:01 +0200 Subject: [PATCH 06/27] Dockerfile: update ALPINE_VERSION to 3.20 Update to the current version of Alpine, which is also the default for the golang:alpine image Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e70f68595d26d935a09ead0f0fe6dd1c6c518d80) Signed-off-by: Austin Vazquez --- Dockerfile | 2 +- dockerfiles/Dockerfile.authors | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed8ba001d398..57d9230d2c39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ ARG BASE_VARIANT=alpine ARG GO_VERSION=1.21.10 -ARG ALPINE_VERSION=3.18 +ARG ALPINE_VERSION=3.20 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 ARG GOTESTSUM_VERSION=v1.10.0 diff --git a/dockerfiles/Dockerfile.authors b/dockerfiles/Dockerfile.authors index 278ad769fea1..321a752c47ef 100644 --- a/dockerfiles/Dockerfile.authors +++ b/dockerfiles/Dockerfile.authors @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG ALPINE_VERSION=3.18 +ARG ALPINE_VERSION=3.20 FROM alpine:${ALPINE_VERSION} AS gen RUN apk add --no-cache bash git diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index a1cc51d9b76b..4060b586f094 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.21.10 -ARG ALPINE_VERSION=3.18 +ARG ALPINE_VERSION=3.20 ARG BUILDX_VERSION=0.11.2 FROM docker/buildx-bin:${BUILDX_VERSION} AS buildx diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 9c4d43f4ddfc..11355039f066 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.21.10 -ARG ALPINE_VERSION=3.18 +ARG ALPINE_VERSION=3.20 ARG GOLANGCI_LINT_VERSION=v1.54.2 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index dd8098dd9e13..62f3d5b0a31a 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG GO_VERSION=1.21.10 -ARG ALPINE_VERSION=3.18 +ARG ALPINE_VERSION=3.20 ARG MODOUTDATED_VERSION=v0.8.0 FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base From 8f7c53974d48ad7850d68fec1577dac8186d71aa Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 4 Jun 2024 23:39:27 +0200 Subject: [PATCH 07/27] update to go1.21.11 go1.21.11 (released 2024-06-04) includes security fixes to the archive/zip and net/netip packages, as well as bug fixes to the compiler, the go command, the runtime, and the os package. See the Go 1.21.11 milestone on our issue tracker for details; - https://github.com/golang/go/issues?q=milestone%3AGo1.21.11+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.10...go1.21.11 From the security announcement; We have just released Go versions 1.22.4 and 1.21.11, minor point releases. These minor releases include 2 security fixes following the security policy: - archive/zip: mishandling of corrupt central directory record The archive/zip package's handling of certain types of invalid zip files differed from the behavior of most zip implementations. This misalignment could be exploited to create an zip file with contents that vary depending on the implementation reading the file. The archive/zip package now rejects files containing these errors. Thanks to Yufan You for reporting this issue. This is CVE-2024-24789 and Go issue https://go.dev/issue/66869. - net/netip: unexpected behavior from Is methods for IPv4-mapped IPv6 addresses The various Is methods (IsPrivate, IsLoopback, etc) did not work as expected for IPv4-mapped IPv6 addresses, returning false for addresses which would return true in their traditional IPv4 forms. Thanks to Enze Wang of Alioth and Jianjun Chen of Zhongguancun Lab for reporting this issue. This is CVE-2024-24790 and Go issue https://go.dev/issue/67680. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 630e1d3e95b18da36dbb53f516c54ee00f2e421f) Signed-off-by: Austin Vazquez --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c38788493cfc..9895e9784978 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.10 + go-version: 1.21.11 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index 57d9230d2c39..bd359fdcacf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.10 +ARG GO_VERSION=1.21.11 ARG ALPINE_VERSION=3.20 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index 48061ed05851..b575ced0bb94 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.10" + default = "1.21.11" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 4060b586f094..0a4f6ea3eb3d 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.10 +ARG GO_VERSION=1.21.11 ARG ALPINE_VERSION=3.20 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 11355039f066..aa65b7b94f86 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.10 +ARG GO_VERSION=1.21.11 ARG ALPINE_VERSION=3.20 ARG GOLANGCI_LINT_VERSION=v1.54.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index 62f3d5b0a31a..89d095439a42 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.10 +ARG GO_VERSION=1.21.11 ARG ALPINE_VERSION=3.20 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index ba9cc033e854..0cb21fe6dacc 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.10 +ARG GO_VERSION=1.21.11 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 8239b55d3e23e2c6e671a70ad49e08c997c3c400 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 3 Jul 2024 10:59:37 +0200 Subject: [PATCH 08/27] update to go1.21.12 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/golang/go/issues?q=milestone%3AGo1.21.12+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.11...go1.21.12 These minor releases include 1 security fixes following the security policy: net/http: denial of service due to improper 100-continue handling The net/http HTTP/1.1 client mishandled the case where a server responds to a request with an "Expect: 100-continue" header with a non-informational (200 or higher) status. This mishandling could leave a client connection in an invalid state, where the next request sent on the connection will fail. An attacker sending a request to a net/http/httputil.ReverseProxy proxy can exploit this mishandling to cause a denial of service by sending "Expect: 100-continue" requests which elicit a non-informational response from the backend. Each such request leaves the proxy with an invalid connection, and causes one subsequent request using that connection to fail. Thanks to Geoff Franks for reporting this issue. This is CVE-2024-24791 and Go issue https://go.dev/issue/67555. View the release notes for more information: https://go.dev/doc/devel/release#go1.21.12 **- Description for the changelog** ```markdown changelog Update Go runtime to 1.21.12 ``` Signed-off-by: Paweł Gronowski (cherry picked from commit d73d7d4ed3f6211aa157d59a2e6674a1774dabc3) Signed-off-by: Austin Vazquez --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9895e9784978..030d53e67c6e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.11 + go-version: 1.21.12 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index bd359fdcacf6..d5af4ef64264 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.11 +ARG GO_VERSION=1.21.12 ARG ALPINE_VERSION=3.20 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index b575ced0bb94..725ddf73dc05 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.11" + default = "1.21.12" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 0a4f6ea3eb3d..5f9406395d6a 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.11 +ARG GO_VERSION=1.21.12 ARG ALPINE_VERSION=3.20 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index aa65b7b94f86..419956c632e7 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.11 +ARG GO_VERSION=1.21.12 ARG ALPINE_VERSION=3.20 ARG GOLANGCI_LINT_VERSION=v1.54.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index 89d095439a42..c19e4d9b7e1a 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.11 +ARG GO_VERSION=1.21.12 ARG ALPINE_VERSION=3.20 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index 0cb21fe6dacc..64b55991ef3a 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.11 +ARG GO_VERSION=1.21.12 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From f18b630f229a3fdac3d392ef1d047e1279284383 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Aug 2023 08:50:07 +0200 Subject: [PATCH 09/27] cli/registry: fix client.pullManifestList not de-referencing manifest Kudos to gosec; cli/registry/client/fetcher.go:205:57: G601: Implicit memory aliasing in for loop. (gosec) imageManifest.Descriptor.Platform = types.OCIPlatform(&manifestDescriptor.Platform) ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 5250f1bab59f208de6a024f187c684614d3e2d21) Signed-off-by: Cory Snider --- cli/registry/client/fetcher.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index acae274a4431..9b362ba8941e 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -202,7 +202,8 @@ func pullManifestList(ctx context.Context, ref reference.Named, repo distributio } // Replace platform from config - imageManifest.Descriptor.Platform = types.OCIPlatform(&manifestDescriptor.Platform) + p := manifestDescriptor.Platform + imageManifest.Descriptor.Platform = types.OCIPlatform(&p) infos = append(infos, imageManifest) } From 58e6338654914735e237004403d77835b9f1b9a2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 29 Aug 2023 09:37:37 +0200 Subject: [PATCH 10/27] cli/registry: client.iterateEndpoints: remove check for APIVersion1 registryService.LookupPullEndpoints uses lookupV2Endpoints https://github.com/moby/moby/blob/v24.0.5/registry/service.go#L137-L142 which, as the name indicates, only returns V2 endpoints; https://github.com/moby/moby/blob/v24.0.5/registry/service_v2.go#L10-L80 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 22b4bab90f32593aee5e3e1349ae5334a7d73193) Signed-off-by: Cory Snider --- cli/registry/client/fetcher.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index 9b362ba8941e..3ce09d137ca5 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -243,11 +243,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 - } - if endpoint.URL.Scheme != "https" { if _, confirmedTLS := confirmedTLSRegistries[endpoint.URL.Host]; confirmedTLS { logrus.Debugf("skipping non-TLS endpoint %s for host/port that appears to use TLS", endpoint.URL) From cfc99a548fb56fcae0780820b10987b0d2752bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 7 Aug 2024 11:48:53 +0200 Subject: [PATCH 11/27] update to go1.21.13 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - https://github.com/golang/go/issues?q=milestone%3AGo1.21.13+label%3ACherryPickApproved - full diff: https://github.com/golang/go/compare/go1.21.12...go1.21.13 go1.21.13 (released 2024-08-06) includes fixes to the go command, the covdata command, and the bytes package. See the [Go 1.21.13 milestone](https://github.com/golang/go/issues?q=milestone%3AGo1.21.13+label%3ACherryPickApproved) on our issue tracker for details. Signed-off-by: Paweł Gronowski (cherry picked from commit 434d8b75e8e8f1230d0858d18e39d25f8deeef5e) Signed-off-by: Cory Snider --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 030d53e67c6e..cfd7e197f351 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.12 + go-version: 1.21.13 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index d5af4ef64264..c365be9a755d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.12 +ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index 725ddf73dc05..2a3c8df015da 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.12" + default = "1.21.13" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 5f9406395d6a..2e8042ff2a20 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.12 +ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 419956c632e7..3a22129d3b6b 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.12 +ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 ARG GOLANGCI_LINT_VERSION=v1.54.2 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index c19e4d9b7e1a..701d987334fe 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.12 +ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index 64b55991ef3a..cd354a23ed55 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.12 +ARG GO_VERSION=1.21.13 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 867baaff664b545798fd63a0533bfec8167efd12 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 23 Oct 2023 15:21:29 +0200 Subject: [PATCH 12/27] swarm: TestSwarmUpdate: remove non-existing "--quiet" flag The `docker swarm update` copmmand does not have a `--quiet` flag, but this test was trying to set it. docker swarm update --help Usage: docker swarm update [OPTIONS] Update the swarm Options: --autolock Change manager autolocking setting (true|false) --cert-expiry duration Validity period for node certificates (ns|us|ms|s|m|h) (default 2160h0m0s) --dispatcher-heartbeat duration Dispatcher heartbeat period (ns|us|ms|s|m|h) (default 5s) --external-ca external-ca Specifications of one or more certificate signing endpoints --max-snapshots uint Number of additional Raft snapshots to retain --snapshot-interval uint Number of log entries between Raft snapshots (default 10000) --task-history-limit int Task history retention limit (default 5) The test didn't catch this issue, because errors when setting the flag were not handled, so also adding error-handling; === Failed === FAIL: cli/command/swarm TestSwarmUpdate (0.00s) update_test.go:177: assertion failed: error is not nil: no such flag -quiet Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b08e34b9f97efbbee9dffd019125c44e3cb145b3) Signed-off-by: Cory Snider --- cli/command/swarm/update_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index 14605c033a6c..028d4e4eab05 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -105,7 +105,6 @@ func TestSwarmUpdate(t *testing.T) { flagMaxSnapshots: "10", flagSnapshotInterval: "100", flagAutolock: "true", - flagQuiet: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { return *swarmInfo, nil @@ -174,7 +173,7 @@ func TestSwarmUpdate(t *testing.T) { cmd := newUpdateCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(cli.OutBuffer()) assert.NilError(t, cmd.Execute()) From 3e271deeca72b449788c70e7f05630b9672e8ac7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 23 Oct 2023 14:51:01 +0200 Subject: [PATCH 13/27] cli/command: remove dot-imports and unhandled errors Please the linters in preparation of updating golangci-lint; - remove dot-imports - add some checks for unhandled errors - replace some fixed-value variables for consts cli/command/image/build/context.go:238:17: G107: Potential HTTP request made with variable url (gosec) if resp, err = http.Get(url); err != nil { ^ cli/command/idresolver/idresolver_test.go:7:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/registry_test.go:7:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/cli/command" // Prevents a circular import with "github.com/docker/cli/internal/test" ^ cli/command/task/print_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/swarm/update_test.go:10:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/swarm/unlock_key_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/swarm/join_token_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/node/list_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/node/promote_test.go:8:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/node/demote_test.go:8:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions ^ cli/command/node/ps_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/node/update_test.go:8:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/node/inspect_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package functions ^ cli/command/secret/ls_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/secret/inspect_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/volume/inspect_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/volume/list_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/config/inspect_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/config/ls_test.go:11:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/network/list_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" ^ cli/command/container/list_test.go:10:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/service/list_test.go:12:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" ^ cli/command/service/client_test.go:6:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/stack/list_test.go:8:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/stack/services_test.go:9:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ cli/command/stack/ps_test.go:10:2: dot-imports: should not use dot imports (revive) . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 594aeb390a9fb09e886d80a05608a8479c1e7e34) Signed-off-by: Cory Snider --- cli/command/config/inspect_test.go | 30 +++--- cli/command/config/ls_test.go | 72 +++++++------- cli/command/container/list_test.go | 44 ++++---- cli/command/idresolver/idresolver_test.go | 10 +- cli/command/network/list_test.go | 18 ++-- cli/command/node/demote_test.go | 6 +- cli/command/node/inspect_test.go | 12 +-- cli/command/node/list_test.go | 24 ++--- cli/command/node/promote_test.go | 6 +- cli/command/node/ps_test.go | 24 ++--- cli/command/node/update_test.go | 18 ++-- cli/command/registry_test.go | 11 +- cli/command/secret/inspect_test.go | 30 +++--- cli/command/secret/ls_test.go | 76 +++++++------- cli/command/service/client_test.go | 6 +- cli/command/service/list_test.go | 31 +++--- cli/command/stack/list_test.go | 12 +-- cli/command/stack/ps_test.go | 34 +++---- cli/command/stack/services_test.go | 34 +++---- cli/command/swarm/join_token_test.go | 26 ++--- cli/command/swarm/unlock_key_test.go | 14 +-- cli/command/swarm/update_test.go | 10 +- cli/command/task/print_test.go | 116 +++++++++++----------- cli/command/volume/inspect_test.go | 12 +-- cli/command/volume/list_test.go | 36 +++---- 25 files changed, 357 insertions(+), 355 deletions(-) diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index 111f15bf82be..a35a74d776d7 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -8,7 +8,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -43,7 +43,7 @@ func TestConfigInspectErrors(t *testing.T) { args: []string{"foo", "bar"}, configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) { if configID == "foo" { - return *Config(ConfigName("foo")), nil, nil + return *builders.Config(builders.ConfigName("foo")), nil, nil } return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") }, @@ -58,7 +58,7 @@ func TestConfigInspectErrors(t *testing.T) { ) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -78,14 +78,14 @@ func TestConfigInspectWithoutFormat(t *testing.T) { if name != "foo" { return swarm.Config{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name) } - return *Config(ConfigID("ID-foo"), ConfigName("foo")), nil, nil + return *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), nil, nil }, }, { name: "multiple-configs-with-labels", args: []string{"foo", "bar"}, configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) { - return *Config(ConfigID("ID-"+name), ConfigName(name), ConfigLabels(map[string]string{ + return *builders.Config(builders.ConfigID("ID-"+name), builders.ConfigName(name), builders.ConfigLabels(map[string]string{ "label1": "label-foo", })), nil, nil }, @@ -102,7 +102,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) { func TestConfigInspectWithFormat(t *testing.T) { configInspectFunc := func(_ context.Context, name string) (swarm.Config, []byte, error) { - return *Config(ConfigName("foo"), ConfigLabels(map[string]string{ + return *builders.Config(builders.ConfigName("foo"), builders.ConfigLabels(map[string]string{ "label1": "label-foo", })), nil, nil } @@ -131,7 +131,7 @@ func TestConfigInspectWithFormat(t *testing.T) { }) cmd := newConfigInspectCommand(cli) cmd.SetArgs(tc.args) - cmd.Flags().Set("format", tc.format) + assert.Check(t, cmd.Flags().Set("format", tc.format)) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name)) } @@ -145,15 +145,15 @@ func TestConfigInspectPretty(t *testing.T) { { name: "simple", configInspectFunc: func(_ context.Context, id string) (swarm.Config, []byte, error) { - return *Config( - ConfigLabels(map[string]string{ + return *builders.Config( + builders.ConfigLabels(map[string]string{ "lbl1": "value1", }), - ConfigID("configID"), - ConfigName("configName"), - ConfigCreatedAt(time.Time{}), - ConfigUpdatedAt(time.Time{}), - ConfigData([]byte("payload here")), + builders.ConfigID("configID"), + builders.ConfigName("configName"), + builders.ConfigCreatedAt(time.Time{}), + builders.ConfigUpdatedAt(time.Time{}), + builders.ConfigData([]byte("payload here")), ), []byte{}, nil }, }, @@ -165,7 +165,7 @@ func TestConfigInspectPretty(t *testing.T) { cmd := newConfigInspectCommand(cli) cmd.SetArgs([]string{"configID"}) - cmd.Flags().Set("pretty", "true") + assert.Check(t, cmd.Flags().Set("pretty", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name)) } diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index d21c2e490560..27e76c1a95bb 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -8,7 +8,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -50,23 +50,23 @@ func TestConfigList(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ - *Config(ConfigID("ID-1-foo"), - ConfigName("1-foo"), - ConfigVersion(swarm.Version{Index: 10}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Config(builders.ConfigID("ID-1-foo"), + builders.ConfigName("1-foo"), + builders.ConfigVersion(swarm.Version{Index: 10}), + builders.ConfigCreatedAt(time.Now().Add(-2*time.Hour)), + builders.ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), ), - *Config(ConfigID("ID-10-foo"), - ConfigName("10-foo"), - ConfigVersion(swarm.Version{Index: 11}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Config(builders.ConfigID("ID-10-foo"), + builders.ConfigName("10-foo"), + builders.ConfigVersion(swarm.Version{Index: 11}), + builders.ConfigCreatedAt(time.Now().Add(-2*time.Hour)), + builders.ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), ), - *Config(ConfigID("ID-2-foo"), - ConfigName("2-foo"), - ConfigVersion(swarm.Version{Index: 11}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Config(builders.ConfigID("ID-2-foo"), + builders.ConfigName("2-foo"), + builders.ConfigVersion(swarm.Version{Index: 11}), + builders.ConfigCreatedAt(time.Now().Add(-2*time.Hour)), + builders.ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), ), }, nil }, @@ -80,15 +80,15 @@ func TestConfigListWithQuietOption(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ - *Config(ConfigID("ID-foo"), ConfigName("foo")), - *Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{ + *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), + *builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{ "label": "label-bar", })), }, nil }, }) cmd := newConfigListCommand(cli) - cmd.Flags().Set("quiet", "true") + assert.Check(t, cmd.Flags().Set("quiet", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden") } @@ -97,8 +97,8 @@ func TestConfigListWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ - *Config(ConfigID("ID-foo"), ConfigName("foo")), - *Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{ + *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), + *builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{ "label": "label-bar", })), }, nil @@ -116,15 +116,15 @@ func TestConfigListWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { return []swarm.Config{ - *Config(ConfigID("ID-foo"), ConfigName("foo")), - *Config(ConfigID("ID-bar"), ConfigName("bar"), ConfigLabels(map[string]string{ + *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), + *builders.Config(builders.ConfigID("ID-bar"), builders.ConfigName("bar"), builders.ConfigLabels(map[string]string{ "label": "label-bar", })), }, nil }, }) cmd := newConfigListCommand(cli) - cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") + assert.Check(t, cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden") } @@ -135,24 +135,24 @@ func TestConfigListWithFilter(t *testing.T) { assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0])) assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0])) return []swarm.Config{ - *Config(ConfigID("ID-foo"), - ConfigName("foo"), - ConfigVersion(swarm.Version{Index: 10}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Config(builders.ConfigID("ID-foo"), + builders.ConfigName("foo"), + builders.ConfigVersion(swarm.Version{Index: 10}), + builders.ConfigCreatedAt(time.Now().Add(-2*time.Hour)), + builders.ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), ), - *Config(ConfigID("ID-bar"), - ConfigName("bar"), - ConfigVersion(swarm.Version{Index: 11}), - ConfigCreatedAt(time.Now().Add(-2*time.Hour)), - ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Config(builders.ConfigID("ID-bar"), + builders.ConfigName("bar"), + builders.ConfigVersion(swarm.Version{Index: 11}), + builders.ConfigCreatedAt(time.Now().Add(-2*time.Hour)), + builders.ConfigUpdatedAt(time.Now().Add(-1*time.Hour)), ), }, nil }, }) cmd := newConfigListCommand(cli) - cmd.Flags().Set("filter", "name=foo") - cmd.Flags().Set("filter", "label=lbl1=Label-bar") + assert.Check(t, cmd.Flags().Set("filter", "name=foo")) + assert.Check(t, cmd.Flags().Set("filter", "label=lbl1=Label-bar")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden") } diff --git a/cli/command/container/list_test.go b/cli/command/container/list_test.go index f88aeeb56c83..fbb625fd1a14 100644 --- a/cli/command/container/list_test.go +++ b/cli/command/container/list_test.go @@ -7,7 +7,7 @@ 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/cli/internal/test/builders" "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "gotest.tools/v3/assert" @@ -159,7 +159,7 @@ func TestContainerListErrors(t *testing.T) { ) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -170,11 +170,11 @@ func TestContainerListWithoutFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { return []types.Container{ - *Container("c1"), - *Container("c2", WithName("foo")), - *Container("c3", WithPort(80, 80, TCP), WithPort(81, 81, TCP), WithPort(82, 82, TCP)), - *Container("c4", WithPort(81, 81, UDP)), - *Container("c5", WithPort(82, 82, IP("8.8.8.8"), TCP)), + *builders.Container("c1"), + *builders.Container("c2", builders.WithName("foo")), + *builders.Container("c3", builders.WithPort(80, 80, builders.TCP), builders.WithPort(81, 81, builders.TCP), builders.WithPort(82, 82, builders.TCP)), + *builders.Container("c4", builders.WithPort(81, 81, builders.UDP)), + *builders.Container("c5", builders.WithPort(82, 82, builders.IP("8.8.8.8"), builders.TCP)), }, nil }, }) @@ -187,13 +187,13 @@ func TestContainerListNoTrunc(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { return []types.Container{ - *Container("c1"), - *Container("c2", WithName("foo/bar")), + *builders.Container("c1"), + *builders.Container("c2", builders.WithName("foo/bar")), }, nil }, }) cmd := newListCommand(cli) - cmd.Flags().Set("no-trunc", "true") + assert.Check(t, cmd.Flags().Set("no-trunc", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden") } @@ -203,13 +203,13 @@ func TestContainerListNamesMultipleTime(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { return []types.Container{ - *Container("c1"), - *Container("c2", WithName("foo/bar")), + *builders.Container("c1"), + *builders.Container("c2", builders.WithName("foo/bar")), }, nil }, }) cmd := newListCommand(cli) - cmd.Flags().Set("format", "{{.Names}} {{.Names}}") + assert.Check(t, cmd.Flags().Set("format", "{{.Names}} {{.Names}}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden") } @@ -219,13 +219,13 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { return []types.Container{ - *Container("c1", WithLabel("some.label", "value")), - *Container("c2", WithName("foo/bar"), WithLabel("foo", "bar")), + *builders.Container("c1", builders.WithLabel("some.label", "value")), + *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")), }, nil }, }) cmd := newListCommand(cli) - cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`) + assert.Check(t, cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`)) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden") } @@ -274,9 +274,9 @@ func TestContainerListFormatSizeSetsOption(t *testing.T) { }, }) cmd := newListCommand(cli) - cmd.Flags().Set("format", tc.format) + assert.Check(t, cmd.Flags().Set("format", tc.format)) if tc.sizeFlag != "" { - cmd.Flags().Set("size", tc.sizeFlag) + assert.Check(t, cmd.Flags().Set("size", tc.sizeFlag)) } assert.NilError(t, cmd.Execute()) }) @@ -287,8 +287,8 @@ func TestContainerListWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { return []types.Container{ - *Container("c1", WithLabel("some.label", "value"), WithSize(10700000)), - *Container("c2", WithName("foo/bar"), WithLabel("foo", "bar"), WithSize(3200000)), + *builders.Container("c1", builders.WithLabel("some.label", "value"), builders.WithSize(10700000)), + *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar"), builders.WithSize(3200000)), }, nil }, }) @@ -304,8 +304,8 @@ func TestContainerListWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { return []types.Container{ - *Container("c1", WithLabel("some.label", "value")), - *Container("c2", WithName("foo/bar"), WithLabel("foo", "bar")), + *builders.Container("c1", builders.WithLabel("some.label", "value")), + *builders.Container("c2", builders.WithName("foo/bar"), builders.WithLabel("foo", "bar")), }, nil }, }) diff --git a/cli/command/idresolver/idresolver_test.go b/cli/command/idresolver/idresolver_test.go index a7b6fc036314..1b8810c7ae3a 100644 --- a/cli/command/idresolver/idresolver_test.go +++ b/cli/command/idresolver/idresolver_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function + "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -50,7 +50,7 @@ func TestResolveWithCache(t *testing.T) { cli := &fakeClient{ nodeInspectFunc: func(nodeID string) (swarm.Node, []byte, error) { inspectCounter++ - return *Node(NodeName("node-foo")), []byte{}, nil + return *builders.Node(builders.NodeName("node-foo")), []byte{}, nil }, } @@ -82,14 +82,14 @@ func TestResolveNode(t *testing.T) { { nodeID: "nodeID", nodeInspectFunc: func(string) (swarm.Node, []byte, error) { - return *Node(NodeName("node-foo")), []byte{}, nil + return *builders.Node(builders.NodeName("node-foo")), []byte{}, nil }, expectedID: "node-foo", }, { nodeID: "nodeID", nodeInspectFunc: func(string) (swarm.Node, []byte, error) { - return *Node(NodeName(""), Hostname("node-hostname")), []byte{}, nil + return *builders.Node(builders.NodeName(""), builders.Hostname("node-hostname")), []byte{}, nil }, expectedID: "node-hostname", }, @@ -124,7 +124,7 @@ func TestResolveService(t *testing.T) { { serviceID: "serviceID", serviceInspectFunc: func(string) (swarm.Service, []byte, error) { - return *Service(ServiceName("service-foo")), []byte{}, nil + return *builders.Service(builders.ServiceName("service-foo")), []byte{}, nil }, expectedID: "service-foo", }, diff --git a/cli/command/network/list_test.go b/cli/command/network/list_test.go index b32c08f85b3f..2834aa125da5 100644 --- a/cli/command/network/list_test.go +++ b/cli/command/network/list_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/docker/cli/internal/test" - . "github.com/docker/cli/internal/test/builders" + "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/google/go-cmp/cmp" @@ -59,10 +59,10 @@ func TestNetworkList(t *testing.T) { } assert.Check(t, is.DeepEqual(expectedOpts, options, cmp.AllowUnexported(filters.Args{}))) - return []types.NetworkResource{*NetworkResource(NetworkResourceID("123454321"), - NetworkResourceName("network_1"), - NetworkResourceDriver("09.7.01"), - NetworkResourceScope("global"))}, nil + return []types.NetworkResource{*builders.NetworkResource(builders.NetworkResourceID("123454321"), + builders.NetworkResourceName("network_1"), + builders.NetworkResourceDriver("09.7.01"), + builders.NetworkResourceScope("global"))}, nil }, }, { @@ -73,9 +73,9 @@ func TestNetworkList(t *testing.T) { golden: "network-list-sort.golden", networkListFunc: func(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { return []types.NetworkResource{ - *NetworkResource(NetworkResourceName("network-2-foo")), - *NetworkResource(NetworkResourceName("network-1-foo")), - *NetworkResource(NetworkResourceName("network-10-foo")), + *builders.NetworkResource(builders.NetworkResourceName("network-2-foo")), + *builders.NetworkResource(builders.NetworkResourceName("network-1-foo")), + *builders.NetworkResource(builders.NetworkResourceName("network-10-foo")), }, nil }, }, @@ -86,7 +86,7 @@ func TestNetworkList(t *testing.T) { cli := test.NewFakeCli(&fakeClient{networkListFunc: tc.networkListFunc}) cmd := newListCommand(cli) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), tc.golden) diff --git a/cli/command/node/demote_test.go b/cli/command/node/demote_test.go index 8c226a9f9fe9..64a11c098593 100644 --- a/cli/command/node/demote_test.go +++ b/cli/command/node/demote_test.go @@ -5,7 +5,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -52,7 +52,7 @@ func TestNodeDemoteNoChange(t *testing.T) { cmd := newDemoteCommand( test.NewFakeCli(&fakeClient{ nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleWorker { @@ -69,7 +69,7 @@ func TestNodeDemoteMultipleNode(t *testing.T) { cmd := newDemoteCommand( test.NewFakeCli(&fakeClient{ nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleWorker { diff --git a/cli/command/node/inspect_test.go b/cli/command/node/inspect_test.go index 2c2e33bedf2b..3e932def39c0 100644 --- a/cli/command/node/inspect_test.go +++ b/cli/command/node/inspect_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -71,7 +71,7 @@ func TestNodeInspectErrors(t *testing.T) { })) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -86,7 +86,7 @@ func TestNodeInspectPretty(t *testing.T) { { name: "simple", nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(NodeLabels(map[string]string{ + return *builders.Node(builders.NodeLabels(map[string]string{ "lbl1": "value1", })), []byte{}, nil }, @@ -94,13 +94,13 @@ func TestNodeInspectPretty(t *testing.T) { { name: "manager", nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, }, { name: "manager-leader", nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager(Leader())), []byte{}, nil + return *builders.Node(builders.Manager(builders.Leader())), []byte{}, nil }, }, } @@ -110,7 +110,7 @@ func TestNodeInspectPretty(t *testing.T) { }) cmd := newInspectCommand(cli) cmd.SetArgs([]string{"nodeID"}) - cmd.Flags().Set("pretty", "true") + assert.Check(t, cmd.Flags().Set("pretty", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name)) } diff --git a/cli/command/node/list_test.go b/cli/command/node/list_test.go index 6c176795fc77..bff15a82ae63 100644 --- a/cli/command/node/list_test.go +++ b/cli/command/node/list_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -56,9 +56,9 @@ func TestNodeList(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ nodeListFunc: func() ([]swarm.Node, error) { return []swarm.Node{ - *Node(NodeID("nodeID1"), Hostname("node-2-foo"), Manager(Leader()), EngineVersion(".")), - *Node(NodeID("nodeID2"), Hostname("node-10-foo"), Manager(), EngineVersion("18.03.0-ce")), - *Node(NodeID("nodeID3"), Hostname("node-1-foo")), + *builders.Node(builders.NodeID("nodeID1"), builders.Hostname("node-2-foo"), builders.Manager(builders.Leader()), builders.EngineVersion(".")), + *builders.Node(builders.NodeID("nodeID2"), builders.Hostname("node-10-foo"), builders.Manager(), builders.EngineVersion("18.03.0-ce")), + *builders.Node(builders.NodeID("nodeID3"), builders.Hostname("node-1-foo")), }, nil }, infoFunc: func() (types.Info, error) { @@ -79,12 +79,12 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ nodeListFunc: func() ([]swarm.Node, error) { return []swarm.Node{ - *Node(NodeID("nodeID1")), + *builders.Node(builders.NodeID("nodeID1")), }, nil }, }) cmd := newListCommand(cli) - cmd.Flags().Set("quiet", "true") + assert.Check(t, cmd.Flags().Set("quiet", "true")) assert.NilError(t, cmd.Execute()) assert.Check(t, is.Equal(cli.OutBuffer().String(), "nodeID1\n")) } @@ -93,9 +93,9 @@ func TestNodeListDefaultFormatFromConfig(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ nodeListFunc: func() ([]swarm.Node, error) { return []swarm.Node{ - *Node(NodeID("nodeID1"), Hostname("nodeHostname1"), Manager(Leader())), - *Node(NodeID("nodeID2"), Hostname("nodeHostname2"), Manager()), - *Node(NodeID("nodeID3"), Hostname("nodeHostname3")), + *builders.Node(builders.NodeID("nodeID1"), builders.Hostname("nodeHostname1"), builders.Manager(builders.Leader())), + *builders.Node(builders.NodeID("nodeID2"), builders.Hostname("nodeHostname2"), builders.Manager()), + *builders.Node(builders.NodeID("nodeID3"), builders.Hostname("nodeHostname3")), }, nil }, infoFunc: func() (types.Info, error) { @@ -118,8 +118,8 @@ func TestNodeListFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ nodeListFunc: func() ([]swarm.Node, error) { return []swarm.Node{ - *Node(NodeID("nodeID1"), Hostname("nodeHostname1"), Manager(Leader())), - *Node(NodeID("nodeID2"), Hostname("nodeHostname2"), Manager()), + *builders.Node(builders.NodeID("nodeID1"), builders.Hostname("nodeHostname1"), builders.Manager(builders.Leader())), + *builders.Node(builders.NodeID("nodeID2"), builders.Hostname("nodeHostname2"), builders.Manager()), }, nil }, infoFunc: func() (types.Info, error) { @@ -134,7 +134,7 @@ func TestNodeListFormat(t *testing.T) { NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}", }) cmd := newListCommand(cli) - cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}") + assert.Check(t, cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "node-list-format-flag.golden") } diff --git a/cli/command/node/promote_test.go b/cli/command/node/promote_test.go index ebb2890ec2ad..42b3a7d755ed 100644 --- a/cli/command/node/promote_test.go +++ b/cli/command/node/promote_test.go @@ -5,7 +5,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -52,7 +52,7 @@ func TestNodePromoteNoChange(t *testing.T) { cmd := newPromoteCommand( test.NewFakeCli(&fakeClient{ nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleManager { @@ -69,7 +69,7 @@ func TestNodePromoteMultipleNode(t *testing.T) { cmd := newPromoteCommand( test.NewFakeCli(&fakeClient{ nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleManager { diff --git a/cli/command/node/ps_test.go b/cli/command/node/ps_test.go index 870e8eb1871f..529edf3faf9d 100644 --- a/cli/command/node/ps_test.go +++ b/cli/command/node/ps_test.go @@ -8,7 +8,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -57,7 +57,7 @@ func TestNodePsErrors(t *testing.T) { cmd := newPsCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.Error(t, cmd.Execute(), tc.expectedError) @@ -79,11 +79,11 @@ func TestNodePs(t *testing.T) { name: "simple", args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{ - *Task(WithStatus(Timestamp(time.Now().Add(-2*time.Hour)), PortStatus([]swarm.PortConfig{ + *builders.Task(builders.WithStatus(builders.Timestamp(time.Now().Add(-2*time.Hour)), builders.PortStatus([]swarm.PortConfig{ { TargetPort: 80, PublishedPort: 80, @@ -107,16 +107,16 @@ func TestNodePs(t *testing.T) { name: "with-errors", args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{ - *Task(TaskID("taskID1"), TaskServiceID("failure"), - WithStatus(Timestamp(time.Now().Add(-2*time.Hour)), StatusErr("a task error"))), - *Task(TaskID("taskID2"), TaskServiceID("failure"), - WithStatus(Timestamp(time.Now().Add(-3*time.Hour)), StatusErr("a task error"))), - *Task(TaskID("taskID3"), TaskServiceID("failure"), - WithStatus(Timestamp(time.Now().Add(-4*time.Hour)), StatusErr("a task error"))), + *builders.Task(builders.TaskID("taskID1"), builders.TaskServiceID("failure"), + builders.WithStatus(builders.Timestamp(time.Now().Add(-2*time.Hour)), builders.StatusErr("a task error"))), + *builders.Task(builders.TaskID("taskID2"), builders.TaskServiceID("failure"), + builders.WithStatus(builders.Timestamp(time.Now().Add(-3*time.Hour)), builders.StatusErr("a task error"))), + *builders.Task(builders.TaskID("taskID3"), builders.TaskServiceID("failure"), + builders.WithStatus(builders.Timestamp(time.Now().Add(-4*time.Hour)), builders.StatusErr("a task error"))), }, nil }, serviceInspectFunc: func(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) { @@ -142,7 +142,7 @@ func TestNodePs(t *testing.T) { cmd := newPsCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-ps.%s.golden", tc.name)) diff --git a/cli/command/node/update_test.go b/cli/command/node/update_test.go index 797f79f621da..0421e4757022 100644 --- a/cli/command/node/update_test.go +++ b/cli/command/node/update_test.go @@ -5,7 +5,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -43,7 +43,7 @@ func TestNodeUpdateErrors(t *testing.T) { { args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(NodeLabels(map[string]string{ + return *builders.Node(builders.NodeLabels(map[string]string{ "key": "value", })), []byte{}, nil }, @@ -61,7 +61,7 @@ func TestNodeUpdateErrors(t *testing.T) { })) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -81,7 +81,7 @@ func TestNodeUpdate(t *testing.T) { "role": "manager", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleManager { @@ -96,7 +96,7 @@ func TestNodeUpdate(t *testing.T) { "availability": "drain", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Availability != swarm.NodeAvailabilityDrain { @@ -111,7 +111,7 @@ func TestNodeUpdate(t *testing.T) { "label-add": "lbl", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if _, present := node.Annotations.Labels["lbl"]; !present { @@ -126,7 +126,7 @@ func TestNodeUpdate(t *testing.T) { "label-add": "key=value", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(), []byte{}, nil + return *builders.Node(), []byte{}, nil }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if value, present := node.Annotations.Labels["key"]; !present || value != "value" { @@ -141,7 +141,7 @@ func TestNodeUpdate(t *testing.T) { "label-rm": "key", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(NodeLabels(map[string]string{ + return *builders.Node(builders.NodeLabels(map[string]string{ "key": "value", })), []byte{}, nil }, @@ -161,7 +161,7 @@ func TestNodeUpdate(t *testing.T) { })) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.NilError(t, cmd.Execute()) } diff --git a/cli/command/registry_test.go b/cli/command/registry_test.go index be518e3175b9..35e80200897a 100644 --- a/cli/command/registry_test.go +++ b/cli/command/registry_test.go @@ -4,9 +4,10 @@ import ( "bytes" "context" "fmt" + "path/filepath" "testing" - . "github.com/docker/cli/cli/command" // Prevents a circular import with "github.com/docker/cli/internal/test" + "github.com/docker/cli/cli/command" configtypes "github.com/docker/cli/cli/config/types" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" @@ -79,12 +80,13 @@ func TestGetDefaultAuthConfig(t *testing.T) { cli := test.NewFakeCli(&fakeClient{}) errBuf := new(bytes.Buffer) cli.SetErr(errBuf) + cli.ConfigFile().Filename = filepath.Join(t.TempDir(), "config") for _, authconfig := range testAuthConfigs { - cli.ConfigFile().GetCredentialsStore(authconfig.ServerAddress).Store(configtypes.AuthConfig(authconfig)) + assert.Check(t, cli.ConfigFile().GetCredentialsStore(authconfig.ServerAddress).Store(configtypes.AuthConfig(authconfig))) } for _, tc := range testCases { serverAddress := tc.inputServerAddress - authconfig, err := GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/") + authconfig, err := command.GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/") if tc.expectedErr != "" { assert.Check(t, err != nil) assert.Check(t, is.Equal(tc.expectedErr, err.Error())) @@ -104,7 +106,8 @@ func TestGetDefaultAuthConfig_HelperError(t *testing.T) { expectedAuthConfig := types.AuthConfig{ ServerAddress: serverAddress, } - authconfig, err := GetDefaultAuthConfig(cli, true, serverAddress, serverAddress == "https://index.docker.io/v1/") + const isDefaultRegistry = false // registry is not "https://index.docker.io/v1/" + authconfig, err := command.GetDefaultAuthConfig(cli, true, serverAddress, isDefaultRegistry) assert.Check(t, is.DeepEqual(expectedAuthConfig, authconfig)) assert.Check(t, is.ErrorContains(err, "docker-credential-fake-does-not-exist")) } diff --git a/cli/command/secret/inspect_test.go b/cli/command/secret/inspect_test.go index 8f0f3e81ec8b..47a28cb8d010 100644 --- a/cli/command/secret/inspect_test.go +++ b/cli/command/secret/inspect_test.go @@ -8,7 +8,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -43,7 +43,7 @@ func TestSecretInspectErrors(t *testing.T) { args: []string{"foo", "bar"}, secretInspectFunc: func(_ context.Context, secretID string) (swarm.Secret, []byte, error) { if secretID == "foo" { - return *Secret(SecretName("foo")), nil, nil + return *builders.Secret(builders.SecretName("foo")), nil, nil } return swarm.Secret{}, nil, errors.Errorf("error while inspecting the secret") }, @@ -58,7 +58,7 @@ func TestSecretInspectErrors(t *testing.T) { ) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -78,14 +78,14 @@ func TestSecretInspectWithoutFormat(t *testing.T) { if name != "foo" { return swarm.Secret{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name) } - return *Secret(SecretID("ID-foo"), SecretName("foo")), nil, nil + return *builders.Secret(builders.SecretID("ID-foo"), builders.SecretName("foo")), nil, nil }, }, { name: "multiple-secrets-with-labels", args: []string{"foo", "bar"}, secretInspectFunc: func(_ context.Context, name string) (swarm.Secret, []byte, error) { - return *Secret(SecretID("ID-"+name), SecretName(name), SecretLabels(map[string]string{ + return *builders.Secret(builders.SecretID("ID-"+name), builders.SecretName(name), builders.SecretLabels(map[string]string{ "label1": "label-foo", })), nil, nil }, @@ -104,7 +104,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) { func TestSecretInspectWithFormat(t *testing.T) { secretInspectFunc := func(_ context.Context, name string) (swarm.Secret, []byte, error) { - return *Secret(SecretName("foo"), SecretLabels(map[string]string{ + return *builders.Secret(builders.SecretName("foo"), builders.SecretLabels(map[string]string{ "label1": "label-foo", })), nil, nil } @@ -133,7 +133,7 @@ func TestSecretInspectWithFormat(t *testing.T) { }) cmd := newSecretInspectCommand(cli) cmd.SetArgs(tc.args) - cmd.Flags().Set("format", tc.format) + assert.Check(t, cmd.Flags().Set("format", tc.format)) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name)) } @@ -147,15 +147,15 @@ func TestSecretInspectPretty(t *testing.T) { { name: "simple", secretInspectFunc: func(_ context.Context, id string) (swarm.Secret, []byte, error) { - return *Secret( - SecretLabels(map[string]string{ + return *builders.Secret( + builders.SecretLabels(map[string]string{ "lbl1": "value1", }), - SecretID("secretID"), - SecretName("secretName"), - SecretDriver("driver"), - SecretCreatedAt(time.Time{}), - SecretUpdatedAt(time.Time{}), + builders.SecretID("secretID"), + builders.SecretName("secretName"), + builders.SecretDriver("driver"), + builders.SecretCreatedAt(time.Time{}), + builders.SecretUpdatedAt(time.Time{}), ), []byte{}, nil }, }, @@ -166,7 +166,7 @@ func TestSecretInspectPretty(t *testing.T) { }) cmd := newSecretInspectCommand(cli) cmd.SetArgs([]string{"secretID"}) - cmd.Flags().Set("pretty", "true") + assert.Check(t, cmd.Flags().Set("pretty", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-pretty.%s.golden", tc.name)) } diff --git a/cli/command/secret/ls_test.go b/cli/command/secret/ls_test.go index c5ee26ee99a8..0579612b96a9 100644 --- a/cli/command/secret/ls_test.go +++ b/cli/command/secret/ls_test.go @@ -8,7 +8,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -50,25 +50,25 @@ func TestSecretList(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) { return []swarm.Secret{ - *Secret(SecretID("ID-1-foo"), - SecretName("1-foo"), - SecretVersion(swarm.Version{Index: 10}), - SecretCreatedAt(time.Now().Add(-2*time.Hour)), - SecretUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Secret(builders.SecretID("ID-1-foo"), + builders.SecretName("1-foo"), + builders.SecretVersion(swarm.Version{Index: 10}), + builders.SecretCreatedAt(time.Now().Add(-2*time.Hour)), + builders.SecretUpdatedAt(time.Now().Add(-1*time.Hour)), ), - *Secret(SecretID("ID-10-foo"), - SecretName("10-foo"), - SecretVersion(swarm.Version{Index: 11}), - SecretCreatedAt(time.Now().Add(-2*time.Hour)), - SecretUpdatedAt(time.Now().Add(-1*time.Hour)), - SecretDriver("driver"), + *builders.Secret(builders.SecretID("ID-10-foo"), + builders.SecretName("10-foo"), + builders.SecretVersion(swarm.Version{Index: 11}), + builders.SecretCreatedAt(time.Now().Add(-2*time.Hour)), + builders.SecretUpdatedAt(time.Now().Add(-1*time.Hour)), + builders.SecretDriver("driver"), ), - *Secret(SecretID("ID-2-foo"), - SecretName("2-foo"), - SecretVersion(swarm.Version{Index: 11}), - SecretCreatedAt(time.Now().Add(-2*time.Hour)), - SecretUpdatedAt(time.Now().Add(-1*time.Hour)), - SecretDriver("driver"), + *builders.Secret(builders.SecretID("ID-2-foo"), + builders.SecretName("2-foo"), + builders.SecretVersion(swarm.Version{Index: 11}), + builders.SecretCreatedAt(time.Now().Add(-2*time.Hour)), + builders.SecretUpdatedAt(time.Now().Add(-1*time.Hour)), + builders.SecretDriver("driver"), ), }, nil }, @@ -82,15 +82,15 @@ func TestSecretListWithQuietOption(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) { return []swarm.Secret{ - *Secret(SecretID("ID-foo"), SecretName("foo")), - *Secret(SecretID("ID-bar"), SecretName("bar"), SecretLabels(map[string]string{ + *builders.Secret(builders.SecretID("ID-foo"), builders.SecretName("foo")), + *builders.Secret(builders.SecretID("ID-bar"), builders.SecretName("bar"), builders.SecretLabels(map[string]string{ "label": "label-bar", })), }, nil }, }) cmd := newSecretListCommand(cli) - cmd.Flags().Set("quiet", "true") + assert.Check(t, cmd.Flags().Set("quiet", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-quiet-option.golden") } @@ -99,8 +99,8 @@ func TestSecretListWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) { return []swarm.Secret{ - *Secret(SecretID("ID-foo"), SecretName("foo")), - *Secret(SecretID("ID-bar"), SecretName("bar"), SecretLabels(map[string]string{ + *builders.Secret(builders.SecretID("ID-foo"), builders.SecretName("foo")), + *builders.Secret(builders.SecretID("ID-bar"), builders.SecretName("bar"), builders.SecretLabels(map[string]string{ "label": "label-bar", })), }, nil @@ -118,15 +118,15 @@ func TestSecretListWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) { return []swarm.Secret{ - *Secret(SecretID("ID-foo"), SecretName("foo")), - *Secret(SecretID("ID-bar"), SecretName("bar"), SecretLabels(map[string]string{ + *builders.Secret(builders.SecretID("ID-foo"), builders.SecretName("foo")), + *builders.Secret(builders.SecretID("ID-bar"), builders.SecretName("bar"), builders.SecretLabels(map[string]string{ "label": "label-bar", })), }, nil }, }) cmd := newSecretListCommand(cli) - cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") + assert.Check(t, cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-format.golden") } @@ -137,24 +137,24 @@ func TestSecretListWithFilter(t *testing.T) { assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]), "foo") assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0])) return []swarm.Secret{ - *Secret(SecretID("ID-foo"), - SecretName("foo"), - SecretVersion(swarm.Version{Index: 10}), - SecretCreatedAt(time.Now().Add(-2*time.Hour)), - SecretUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Secret(builders.SecretID("ID-foo"), + builders.SecretName("foo"), + builders.SecretVersion(swarm.Version{Index: 10}), + builders.SecretCreatedAt(time.Now().Add(-2*time.Hour)), + builders.SecretUpdatedAt(time.Now().Add(-1*time.Hour)), ), - *Secret(SecretID("ID-bar"), - SecretName("bar"), - SecretVersion(swarm.Version{Index: 11}), - SecretCreatedAt(time.Now().Add(-2*time.Hour)), - SecretUpdatedAt(time.Now().Add(-1*time.Hour)), + *builders.Secret(builders.SecretID("ID-bar"), + builders.SecretName("bar"), + builders.SecretVersion(swarm.Version{Index: 11}), + builders.SecretCreatedAt(time.Now().Add(-2*time.Hour)), + builders.SecretUpdatedAt(time.Now().Add(-1*time.Hour)), ), }, nil }, }) cmd := newSecretListCommand(cli) - cmd.Flags().Set("filter", "name=foo") - cmd.Flags().Set("filter", "label=lbl1=Label-bar") + assert.Check(t, cmd.Flags().Set("filter", "name=foo")) + assert.Check(t, cmd.Flags().Set("filter", "label=lbl1=Label-bar")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-filter.golden") } diff --git a/cli/command/service/client_test.go b/cli/command/service/client_test.go index d00afe2ca22a..5e81a58cc7fe 100644 --- a/cli/command/service/client_test.go +++ b/cli/command/service/client_test.go @@ -3,7 +3,7 @@ package service import ( "context" - . "github.com/docker/cli/internal/test/builders" // Import builders to get the builder function as package function + "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" @@ -39,7 +39,7 @@ func (f *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string return f.serviceInspectWithRawFunc(ctx, serviceID, options) } - return *Service(ServiceID(serviceID)), []byte{}, nil + return *builders.Service(builders.ServiceID(serviceID)), []byte{}, nil } func (f *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { @@ -73,5 +73,5 @@ func (f *fakeClient) NetworkInspect(ctx context.Context, networkID string, optio } func newService(id string, name string) swarm.Service { - return *Service(ServiceID(id), ServiceName(name)) + return *builders.Service(builders.ServiceID(id), builders.ServiceName(name)) } diff --git a/cli/command/service/list_test.go b/cli/command/service/list_test.go index 576ecc34ee57..6a50210ec58f 100644 --- a/cli/command/service/list_test.go +++ b/cli/command/service/list_test.go @@ -8,8 +8,7 @@ import ( "testing" "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" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" @@ -30,7 +29,7 @@ func TestServiceListOrder(t *testing.T) { }) cmd := newListCommand(cli) cmd.SetArgs([]string{}) - cmd.Flags().Set("format", "{{.Name}}") + assert.Check(t, cmd.Flags().Set("format", "{{.Name}}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "service-list-sort.golden") } @@ -248,21 +247,21 @@ func generateServices(t *testing.T, opts clusterOpts) []swarm.Service { } return []swarm.Service{ - *Service( - ServiceID("replicated"), - ServiceName("01-replicated-service"), - ReplicatedService(opts.desiredTasks), - ServiceStatus(opts.desiredTasks, opts.runningTasks), + *builders.Service( + builders.ServiceID("replicated"), + builders.ServiceName("01-replicated-service"), + builders.ReplicatedService(opts.desiredTasks), + builders.ServiceStatus(opts.desiredTasks, opts.runningTasks), ), - *Service( - ServiceID("global"), - ServiceName("02-global-service"), - GlobalService(), - ServiceStatus(opts.activeNodes, globalTasks), + *builders.Service( + builders.ServiceID("global"), + builders.ServiceName("02-global-service"), + builders.GlobalService(), + builders.ServiceStatus(opts.activeNodes, globalTasks), ), - *Service( - ServiceID("none-id"), - ServiceName("03-none-service"), + *builders.Service( + builders.ServiceID("none-id"), + builders.ServiceName("03-none-service"), ), } } diff --git a/cli/command/stack/list_test.go b/cli/command/stack/list_test.go index 3d18f894d907..f4c2d41b3c01 100644 --- a/cli/command/stack/list_test.go +++ b/cli/command/stack/list_test.go @@ -5,7 +5,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -38,7 +38,7 @@ func TestListErrors(t *testing.T) { }, { serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{*Service()}, nil + return []swarm.Service{*builders.Service()}, nil }, expectedError: "cannot get label", }, @@ -51,7 +51,7 @@ func TestListErrors(t *testing.T) { cmd.SetArgs(tc.args) cmd.SetOut(io.Discard) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.ErrorContains(t, cmd.Execute(), tc.expectedError) } @@ -101,8 +101,8 @@ func TestStackList(t *testing.T) { var services []swarm.Service for _, name := range tc.serviceNames { services = append(services, - *Service( - ServiceLabels(map[string]string{ + *builders.Service( + builders.ServiceLabels(map[string]string{ "com.docker.stack.namespace": name, }), ), @@ -115,7 +115,7 @@ func TestStackList(t *testing.T) { }) cmd := newListCommand(cli) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), tc.golden) diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index 674ab9018db6..a6b87393608a 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -7,7 +7,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -76,7 +76,7 @@ func TestStackPs(t *testing.T) { { doc: "WithQuietOption", taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task(TaskID("id-foo"))}, nil + return []swarm.Task{*builders.Task(builders.TaskID("id-foo"))}, nil }, args: []string{"foo"}, flags: map[string]string{ @@ -87,7 +87,7 @@ func TestStackPs(t *testing.T) { { doc: "WithNoTruncOption", taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task(TaskID("xn4cypcov06f2w8gsbaf2lst3"))}, nil + return []swarm.Task{*builders.Task(builders.TaskID("xn4cypcov06f2w8gsbaf2lst3"))}, nil }, args: []string{"foo"}, flags: map[string]string{ @@ -99,12 +99,12 @@ func TestStackPs(t *testing.T) { { doc: "WithNoResolveOption", taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task( - TaskNodeID("id-node-foo"), + return []swarm.Task{*builders.Task( + builders.TaskNodeID("id-node-foo"), )}, nil }, nodeInspectWithRaw: func(ref string) (swarm.Node, []byte, error) { - return *Node(NodeName("node-name-bar")), nil, nil + return *builders.Node(builders.NodeName("node-name-bar")), nil, nil }, args: []string{"foo"}, flags: map[string]string{ @@ -116,7 +116,7 @@ func TestStackPs(t *testing.T) { { doc: "WithFormat", taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task(TaskServiceID("service-id-foo"))}, nil + return []swarm.Task{*builders.Task(builders.TaskServiceID("service-id-foo"))}, nil }, args: []string{"foo"}, flags: map[string]string{ @@ -127,7 +127,7 @@ func TestStackPs(t *testing.T) { { doc: "WithConfigFormat", taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task(TaskServiceID("service-id-foo"))}, nil + return []swarm.Task{*builders.Task(builders.TaskServiceID("service-id-foo"))}, nil }, config: configfile.ConfigFile{ TasksFormat: "{{ .Name }}", @@ -138,17 +138,17 @@ func TestStackPs(t *testing.T) { { doc: "WithoutFormat", taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task( - TaskID("id-foo"), - TaskServiceID("service-id-foo"), - TaskNodeID("id-node"), - WithTaskSpec(TaskImage("myimage:mytag")), - TaskDesiredState(swarm.TaskStateReady), - WithStatus(TaskState(swarm.TaskStateFailed), Timestamp(time.Now().Add(-2*time.Hour))), + return []swarm.Task{*builders.Task( + builders.TaskID("id-foo"), + builders.TaskServiceID("service-id-foo"), + builders.TaskNodeID("id-node"), + builders.WithTaskSpec(builders.TaskImage("myimage:mytag")), + builders.TaskDesiredState(swarm.TaskStateReady), + builders.WithStatus(builders.TaskState(swarm.TaskStateFailed), builders.Timestamp(time.Now().Add(-2*time.Hour))), )}, nil }, nodeInspectWithRaw: func(ref string) (swarm.Node, []byte, error) { - return *Node(NodeName("node-name-bar")), nil, nil + return *builders.Node(builders.NodeName("node-name-bar")), nil, nil }, args: []string{"foo"}, golden: "stack-ps-without-format.golden", @@ -166,7 +166,7 @@ func TestStackPs(t *testing.T) { cmd := newPsCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) diff --git a/cli/command/stack/services_test.go b/cli/command/stack/services_test.go index f48ee2b11ce3..2ec6431558a0 100644 --- a/cli/command/stack/services_test.go +++ b/cli/command/stack/services_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -34,20 +34,20 @@ func TestStackServicesErrors(t *testing.T) { { args: []string{"foo"}, serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{*Service(GlobalService())}, nil + return []swarm.Service{*builders.Service(builders.GlobalService())}, nil }, nodeListFunc: func(options types.NodeListOptions) ([]swarm.Node, error) { return nil, errors.Errorf("error getting nodes") }, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{*Task()}, nil + return []swarm.Task{*builders.Task()}, nil }, expectedError: "error getting nodes", }, { args: []string{"foo"}, serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{*Service(GlobalService())}, nil + return []swarm.Service{*builders.Service(builders.GlobalService())}, nil }, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { return nil, errors.Errorf("error getting tasks") @@ -60,7 +60,7 @@ func TestStackServicesErrors(t *testing.T) { "format": "{{invalid format}}", }, serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{*Service()}, nil + return []swarm.Service{*builders.Service()}, nil }, expectedError: "template parsing error", }, @@ -77,7 +77,7 @@ func TestStackServicesErrors(t *testing.T) { cmd := newServicesCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -109,11 +109,11 @@ func TestStackServicesEmptyServiceList(t *testing.T) { func TestStackServicesWithQuietOption(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{*Service(ServiceID("id-foo"))}, nil + return []swarm.Service{*builders.Service(builders.ServiceID("id-foo"))}, nil }, }) cmd := newServicesCommand(cli) - cmd.Flags().Set("quiet", "true") + assert.Check(t, cmd.Flags().Set("quiet", "true")) cmd.SetArgs([]string{"foo"}) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-quiet-option.golden") @@ -123,13 +123,13 @@ func TestStackServicesWithFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ - *Service(ServiceName("service-name-foo")), + *builders.Service(builders.ServiceName("service-name-foo")), }, nil }, }) cmd := newServicesCommand(cli) cmd.SetArgs([]string{"foo"}) - cmd.Flags().Set("format", "{{ .Name }}") + assert.Check(t, cmd.Flags().Set("format", "{{ .Name }}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-format.golden") } @@ -138,7 +138,7 @@ func TestStackServicesWithConfigFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { return []swarm.Service{ - *Service(ServiceName("service-name-foo")), + *builders.Service(builders.ServiceName("service-name-foo")), }, nil }, }) @@ -154,12 +154,12 @@ func TestStackServicesWithConfigFormat(t *testing.T) { func TestStackServicesWithoutFormat(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{*Service( - ServiceName("name-foo"), - ServiceID("id-foo"), - ReplicatedService(2), - ServiceImage("busybox:latest"), - ServicePort(swarm.PortConfig{ + return []swarm.Service{*builders.Service( + builders.ServiceName("name-foo"), + builders.ServiceID("id-foo"), + builders.ReplicatedService(2), + builders.ServiceImage("busybox:latest"), + builders.ServicePort(swarm.PortConfig{ PublishMode: swarm.PortConfigPublishModeIngress, PublishedPort: 0, TargetPort: 3232, diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index 082b54852a2e..cd5fca1cdebf 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -96,7 +96,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { cmd := newJoinTokenCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -123,10 +123,10 @@ func TestSwarmJoinToken(t *testing.T) { }, nil }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, }, { @@ -140,10 +140,10 @@ func TestSwarmJoinToken(t *testing.T) { }, nil }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, }, { @@ -160,10 +160,10 @@ func TestSwarmJoinToken(t *testing.T) { }, nil }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, }, { @@ -173,10 +173,10 @@ func TestSwarmJoinToken(t *testing.T) { flagQuiet: "true", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, }, { @@ -186,10 +186,10 @@ func TestSwarmJoinToken(t *testing.T) { flagQuiet: "true", }, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return *Node(Manager()), []byte{}, nil + return *builders.Node(builders.Manager()), []byte{}, nil }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, }, } @@ -202,7 +202,7 @@ func TestSwarmJoinToken(t *testing.T) { cmd := newJoinTokenCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("jointoken-%s.golden", tc.name)) diff --git a/cli/command/swarm/unlock_key_test.go b/cli/command/swarm/unlock_key_test.go index 24ca164aa6cb..cfe49feb3e47 100644 --- a/cli/command/swarm/unlock_key_test.go +++ b/cli/command/swarm/unlock_key_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -45,7 +45,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, expectedError: "cannot rotate because autolock is not turned on", }, @@ -55,7 +55,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(Autolock()), nil + return *builders.Swarm(builders.Autolock()), nil }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { return errors.Errorf("error updating the swarm") @@ -88,7 +88,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { })) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -129,7 +129,7 @@ func TestSwarmUnlockKey(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(Autolock()), nil + return *builders.Swarm(builders.Autolock()), nil }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { return types.SwarmUnlockKeyResponse{ @@ -144,7 +144,7 @@ func TestSwarmUnlockKey(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(Autolock()), nil + return *builders.Swarm(builders.Autolock()), nil }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { return types.SwarmUnlockKeyResponse{ @@ -162,7 +162,7 @@ func TestSwarmUnlockKey(t *testing.T) { cmd := newUnlockKeyCommand(cli) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("unlockkeys-%s.golden", tc.name)) diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index 028d4e4eab05..29432cd55b6e 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -7,7 +7,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/pkg/errors" @@ -56,7 +56,7 @@ func TestSwarmUpdateErrors(t *testing.T) { flagAutolock: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key") @@ -73,7 +73,7 @@ func TestSwarmUpdateErrors(t *testing.T) { })) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) assert.ErrorContains(t, cmd.Execute(), tc.expectedError) @@ -81,7 +81,7 @@ func TestSwarmUpdateErrors(t *testing.T) { } func TestSwarmUpdate(t *testing.T) { - swarmInfo := Swarm() + swarmInfo := builders.Swarm() swarmInfo.ClusterInfo.TLSInfo.TrustRoot = "trustroot" testCases := []struct { @@ -155,7 +155,7 @@ func TestSwarmUpdate(t *testing.T) { return nil }, swarmInspectFunc: func() (swarm.Swarm, error) { - return *Swarm(), nil + return *builders.Swarm(), nil }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { return types.SwarmUnlockKeyResponse{ diff --git a/cli/command/task/print_test.go b/cli/command/task/print_test.go index d3452dbf4c82..b549f678263d 100644 --- a/cli/command/task/print_test.go +++ b/cli/command/task/print_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/idresolver" "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/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "gotest.tools/v3/assert" @@ -19,29 +19,29 @@ func TestTaskPrintSorted(t *testing.T) { apiClient := &fakeClient{ serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) { if ref == "service-id-one" { - return *Service(ServiceName("service-name-1")), nil, nil + return *builders.Service(builders.ServiceName("service-name-1")), nil, nil } - return *Service(ServiceName("service-name-10")), nil, nil + return *builders.Service(builders.ServiceName("service-name-10")), nil, nil }, } cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{ - *Task( - TaskID("id-foo"), - TaskServiceID("service-id-ten"), - TaskNodeID("id-node"), - WithTaskSpec(TaskImage("myimage:mytag")), - TaskDesiredState(swarm.TaskStateReady), - WithStatus(TaskState(swarm.TaskStateFailed), Timestamp(time.Now().Add(-2*time.Hour))), + *builders.Task( + builders.TaskID("id-foo"), + builders.TaskServiceID("service-id-ten"), + builders.TaskNodeID("id-node"), + builders.WithTaskSpec(builders.TaskImage("myimage:mytag")), + builders.TaskDesiredState(swarm.TaskStateReady), + builders.WithStatus(builders.TaskState(swarm.TaskStateFailed), builders.Timestamp(time.Now().Add(-2*time.Hour))), ), - *Task( - TaskID("id-bar"), - TaskServiceID("service-id-one"), - TaskNodeID("id-node"), - WithTaskSpec(TaskImage("myimage:mytag")), - TaskDesiredState(swarm.TaskStateReady), - WithStatus(TaskState(swarm.TaskStateFailed), Timestamp(time.Now().Add(-2*time.Hour))), + *builders.Task( + builders.TaskID("id-bar"), + builders.TaskServiceID("service-id-one"), + builders.TaskNodeID("id-node"), + builders.WithTaskSpec(builders.TaskImage("myimage:mytag")), + builders.TaskDesiredState(swarm.TaskStateReady), + builders.WithStatus(builders.TaskState(swarm.TaskStateFailed), builders.Timestamp(time.Now().Add(-2*time.Hour))), ), } @@ -51,25 +51,25 @@ func TestTaskPrintSorted(t *testing.T) { } func TestTaskPrintWithQuietOption(t *testing.T) { - quiet := true - trunc := false - noResolve := true + const quiet = true + const trunc = false + const noResolve = true apiClient := &fakeClient{} cli := test.NewFakeCli(apiClient) - tasks := []swarm.Task{*Task(TaskID("id-foo"))} + tasks := []swarm.Task{*builders.Task(builders.TaskID("id-foo"))} err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey) assert.NilError(t, err) golden.Assert(t, cli.OutBuffer().String(), "task-print-with-quiet-option.golden") } func TestTaskPrintWithNoTruncOption(t *testing.T) { - quiet := false - trunc := false - noResolve := true + const quiet = false + const trunc = false + const noResolve = true apiClient := &fakeClient{} cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{ - *Task(TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")), + *builders.Task(builders.TaskID("id-foo-yov6omdek8fg3k5stosyp2m50")), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .ID }}") assert.NilError(t, err) @@ -77,13 +77,13 @@ func TestTaskPrintWithNoTruncOption(t *testing.T) { } func TestTaskPrintWithGlobalService(t *testing.T) { - quiet := false - trunc := false - noResolve := true + const quiet = false + const trunc = false + const noResolve = true apiClient := &fakeClient{} cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{ - *Task(TaskServiceID("service-id-foo"), TaskNodeID("node-id-bar"), TaskSlot(0)), + *builders.Task(builders.TaskServiceID("service-id-foo"), builders.TaskNodeID("node-id-bar"), builders.TaskSlot(0)), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}") assert.NilError(t, err) @@ -91,13 +91,13 @@ func TestTaskPrintWithGlobalService(t *testing.T) { } func TestTaskPrintWithReplicatedService(t *testing.T) { - quiet := false - trunc := false - noResolve := true + const quiet = false + const trunc = false + const noResolve = true apiClient := &fakeClient{} cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{ - *Task(TaskServiceID("service-id-foo"), TaskSlot(1)), + *builders.Task(builders.TaskServiceID("service-id-foo"), builders.TaskSlot(1)), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }}") assert.NilError(t, err) @@ -105,34 +105,34 @@ func TestTaskPrintWithReplicatedService(t *testing.T) { } func TestTaskPrintWithIndentation(t *testing.T) { - quiet := false - trunc := false - noResolve := false + const quiet = false + const trunc = false + const noResolve = false apiClient := &fakeClient{ serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) { - return *Service(ServiceName("service-name-foo")), nil, nil + return *builders.Service(builders.ServiceName("service-name-foo")), nil, nil }, nodeInspectWithRaw: func(ref string) (swarm.Node, []byte, error) { - return *Node(NodeName("node-name-bar")), nil, nil + return *builders.Node(builders.NodeName("node-name-bar")), nil, nil }, } cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{ - *Task( - TaskID("id-foo"), - TaskServiceID("service-id-foo"), - TaskNodeID("id-node"), - WithTaskSpec(TaskImage("myimage:mytag")), - TaskDesiredState(swarm.TaskStateReady), - WithStatus(TaskState(swarm.TaskStateFailed), Timestamp(time.Now().Add(-2*time.Hour))), + *builders.Task( + builders.TaskID("id-foo"), + builders.TaskServiceID("service-id-foo"), + builders.TaskNodeID("id-node"), + builders.WithTaskSpec(builders.TaskImage("myimage:mytag")), + builders.TaskDesiredState(swarm.TaskStateReady), + builders.WithStatus(builders.TaskState(swarm.TaskStateFailed), builders.Timestamp(time.Now().Add(-2*time.Hour))), ), - *Task( - TaskID("id-bar"), - TaskServiceID("service-id-foo"), - TaskNodeID("id-node"), - WithTaskSpec(TaskImage("myimage:mytag")), - TaskDesiredState(swarm.TaskStateReady), - WithStatus(TaskState(swarm.TaskStateFailed), Timestamp(time.Now().Add(-2*time.Hour))), + *builders.Task( + builders.TaskID("id-bar"), + builders.TaskServiceID("service-id-foo"), + builders.TaskNodeID("id-node"), + builders.WithTaskSpec(builders.TaskImage("myimage:mytag")), + builders.TaskDesiredState(swarm.TaskStateReady), + builders.WithStatus(builders.TaskState(swarm.TaskStateFailed), builders.Timestamp(time.Now().Add(-2*time.Hour))), ), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, formatter.TableFormatKey) @@ -141,20 +141,20 @@ func TestTaskPrintWithIndentation(t *testing.T) { } func TestTaskPrintWithResolution(t *testing.T) { - quiet := false - trunc := false - noResolve := false + const quiet = false + const trunc = false + const noResolve = false apiClient := &fakeClient{ serviceInspectWithRaw: func(ref string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) { - return *Service(ServiceName("service-name-foo")), nil, nil + return *builders.Service(builders.ServiceName("service-name-foo")), nil, nil }, nodeInspectWithRaw: func(ref string) (swarm.Node, []byte, error) { - return *Node(NodeName("node-name-bar")), nil, nil + return *builders.Node(builders.NodeName("node-name-bar")), nil, nil }, } cli := test.NewFakeCli(apiClient) tasks := []swarm.Task{ - *Task(TaskServiceID("service-id-foo"), TaskSlot(1)), + *builders.Task(builders.TaskServiceID("service-id-foo"), builders.TaskSlot(1)), } err := Print(context.Background(), cli, tasks, idresolver.New(apiClient, noResolve), trunc, quiet, "{{ .Name }} {{ .Node }}") assert.NilError(t, err) diff --git a/cli/command/volume/inspect_test.go b/cli/command/volume/inspect_test.go index 62c9c00aa83c..624dc8de63b0 100644 --- a/cli/command/volume/inspect_test.go +++ b/cli/command/volume/inspect_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/volume" "github.com/pkg/errors" @@ -59,7 +59,7 @@ func TestVolumeInspectErrors(t *testing.T) { ) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) @@ -80,14 +80,14 @@ func TestVolumeInspectWithoutFormat(t *testing.T) { if volumeID != "foo" { return volume.Volume{}, errors.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID) } - return *Volume(), nil + return *builders.Volume(), nil }, }, { name: "multiple-volume-with-labels", args: []string{"foo", "bar"}, volumeInspectFunc: func(volumeID string) (volume.Volume, error) { - return *Volume(VolumeName(volumeID), VolumeLabels(map[string]string{ + return *builders.Volume(builders.VolumeName(volumeID), builders.VolumeLabels(map[string]string{ "foo": "bar", })), nil }, @@ -106,7 +106,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) { func TestVolumeInspectWithFormat(t *testing.T) { volumeInspectFunc := func(volumeID string) (volume.Volume, error) { - return *Volume(VolumeLabels(map[string]string{ + return *builders.Volume(builders.VolumeLabels(map[string]string{ "foo": "bar", })), nil } @@ -135,7 +135,7 @@ func TestVolumeInspectWithFormat(t *testing.T) { }) cmd := newInspectCommand(cli) cmd.SetArgs(tc.args) - cmd.Flags().Set("format", tc.format) + assert.Check(t, cmd.Flags().Set("format", tc.format)) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name)) } diff --git a/cli/command/volume/list_test.go b/cli/command/volume/list_test.go index 45bbc955e471..08fd4038486a 100644 --- a/cli/command/volume/list_test.go +++ b/cli/command/volume/list_test.go @@ -6,7 +6,7 @@ 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/cli/internal/test/builders" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" "github.com/pkg/errors" @@ -40,7 +40,7 @@ func TestVolumeListErrors(t *testing.T) { ) cmd.SetArgs(tc.args) for key, value := range tc.flags { - cmd.Flags().Set(key, value) + assert.Check(t, cmd.Flags().Set(key, value)) } cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) @@ -53,9 +53,9 @@ func TestVolumeListWithoutFormat(t *testing.T) { volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) { return volume.ListResponse{ Volumes: []*volume.Volume{ - Volume(), - Volume(VolumeName("foo"), VolumeDriver("bar")), - Volume(VolumeName("baz"), VolumeLabels(map[string]string{ + builders.Volume(), + builders.Volume(builders.VolumeName("foo"), builders.VolumeDriver("bar")), + builders.Volume(builders.VolumeName("baz"), builders.VolumeLabels(map[string]string{ "foo": "bar", })), }, @@ -72,9 +72,9 @@ func TestVolumeListWithConfigFormat(t *testing.T) { volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) { return volume.ListResponse{ Volumes: []*volume.Volume{ - Volume(), - Volume(VolumeName("foo"), VolumeDriver("bar")), - Volume(VolumeName("baz"), VolumeLabels(map[string]string{ + builders.Volume(), + builders.Volume(builders.VolumeName("foo"), builders.VolumeDriver("bar")), + builders.Volume(builders.VolumeName("baz"), builders.VolumeLabels(map[string]string{ "foo": "bar", })), }, @@ -94,9 +94,9 @@ func TestVolumeListWithFormat(t *testing.T) { volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) { return volume.ListResponse{ Volumes: []*volume.Volume{ - Volume(), - Volume(VolumeName("foo"), VolumeDriver("bar")), - Volume(VolumeName("baz"), VolumeLabels(map[string]string{ + builders.Volume(), + builders.Volume(builders.VolumeName("foo"), builders.VolumeDriver("bar")), + builders.Volume(builders.VolumeName("baz"), builders.VolumeLabels(map[string]string{ "foo": "bar", })), }, @@ -104,7 +104,7 @@ func TestVolumeListWithFormat(t *testing.T) { }, }) cmd := newListCommand(cli) - cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}") + assert.Check(t, cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "volume-list-with-format.golden") } @@ -114,15 +114,15 @@ func TestVolumeListSortOrder(t *testing.T) { volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) { return volume.ListResponse{ Volumes: []*volume.Volume{ - Volume(VolumeName("volume-2-foo")), - Volume(VolumeName("volume-10-foo")), - Volume(VolumeName("volume-1-foo")), + builders.Volume(builders.VolumeName("volume-2-foo")), + builders.Volume(builders.VolumeName("volume-10-foo")), + builders.Volume(builders.VolumeName("volume-1-foo")), }, }, nil }, }) cmd := newListCommand(cli) - cmd.Flags().Set("format", "{{ .Name }}") + assert.Check(t, cmd.Flags().Set("format", "{{ .Name }}")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "volume-list-sort.golden") } @@ -223,14 +223,14 @@ func TestClusterVolumeList(t *testing.T) { }, }, }, - Volume(VolumeName("volume-local-1")), + builders.Volume(builders.VolumeName("volume-local-1")), }, }, nil }, }) cmd := newListCommand(cli) - cmd.Flags().Set("cluster", "true") + assert.Check(t, cmd.Flags().Set("cluster", "true")) assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "volume-cluster-volume-list.golden") } From fcad2c6584cf74af9b7ccaa13daedabba248e9b5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 23 Oct 2023 15:01:31 +0200 Subject: [PATCH 14/27] image/build: use "nolint" comment to work around gosec regression Latest gosec linter has a regression in parsing "nosec" comments; see https://github.com/securego/gosec/issues/1046 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 9e1f8d646e15b2626e56960e9505ad281937dc30) Signed-off-by: Cory Snider --- cli/command/image/build/context.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index c4deef7e08a6..141344a4072f 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -231,8 +231,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 { + if resp, err = http.Get(url); err != nil { //nolint:gosec // Ignore G107: Potential HTTP request made with variable url return nil, err } if resp.StatusCode < http.StatusBadRequest { From 1d72a32b64f773efcd880edf0d9b722efd6f6fbc Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 23 Oct 2023 15:02:57 +0200 Subject: [PATCH 15/27] update to golangci-lint v1.55.0 release notes: https://github.com/golangci/golangci-lint/releases/tag/v1.55.0 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b7b5b31a7ee88e4a425e2785972bdffb911ebb24) Signed-off-by: Cory Snider --- dockerfiles/Dockerfile.lint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 3a22129d3b6b..108ce408abcc 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -2,7 +2,7 @@ ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 -ARG GOLANGCI_LINT_VERSION=v1.54.2 +ARG GOLANGCI_LINT_VERSION=v1.55.0 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint From 5adf6be6d8c43493689331941f95d28c898cd167 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 20:22:15 +0200 Subject: [PATCH 16/27] cli/command/network: fix linting issue and pass client instead of cli Rename variable that shadowed an import, and pass the network API-client instead of the whole CLI Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e93abde7a002873e9ccdd8fd25d697c5c01aad9d) Signed-off-by: Cory Snider --- cli/command/network/connect.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cli/command/network/connect.go b/cli/command/network/connect.go index 75e3c0b4c893..21dd12e3abd7 100644 --- a/cli/command/network/connect.go +++ b/cli/command/network/connect.go @@ -10,6 +10,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/opts" "github.com/docker/docker/api/types/network" + "github.com/docker/docker/client" "github.com/spf13/cobra" ) @@ -36,14 +37,14 @@ func newConnectCommand(dockerCli command.Cli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { options.network = args[0] options.container = args[1] - return runConnect(dockerCli, options) + return runConnect(cmd.Context(), dockerCli.Client(), options) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) == 0 { return completion.NetworkNames(dockerCli)(cmd, args, toComplete) } - network := args[0] - return completion.ContainerNames(dockerCli, true, not(isConnected(network)))(cmd, args, toComplete) + nw := args[0] + return completion.ContainerNames(dockerCli, true, not(isConnected(nw)))(cmd, args, toComplete) }, } @@ -57,14 +58,13 @@ func newConnectCommand(dockerCli command.Cli) *cobra.Command { return cmd } -func runConnect(dockerCli command.Cli, options connectOptions) error { - client := dockerCli.Client() - +func runConnect(ctx context.Context, apiClient client.NetworkAPIClient, options connectOptions) error { driverOpts, err := convertDriverOpt(options.driverOpts) if err != nil { return err } - epConfig := &network.EndpointSettings{ + + return apiClient.NetworkConnect(ctx, options.network, options.container, &network.EndpointSettings{ IPAMConfig: &network.EndpointIPAMConfig{ IPv4Address: options.ipaddress, IPv6Address: options.ipv6address, @@ -73,9 +73,7 @@ func runConnect(dockerCli command.Cli, options connectOptions) error { Links: options.links.GetAll(), Aliases: options.aliases, DriverOpts: driverOpts, - } - - return client.NetworkConnect(context.Background(), options.network, options.container, epConfig) + }) } func convertDriverOpt(opts []string) (map[string]string, error) { From 416c0610003724990bbdddb50765cd0652c13322 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 20:47:07 +0200 Subject: [PATCH 17/27] linting: fmt.Errorf can be replaced with errors.New (perfsprint) internal/test/cli.go:175:14: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("no notary client available unless defined") ^ cli/command/cli.go:318:29: fmt.Errorf can be replaced with errors.New (perfsprint) return docker.Endpoint{}, fmt.Errorf("no context store initialized") ^ cli/command/container/attach.go:161:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf(result.Error.Message) ^ cli/command/container/opts.go:577:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("--health-start-period cannot be negative") ^ cli/command/container/opts.go:580:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("--health-start-interval cannot be negative") ^ cli/command/container/stats.go:221:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("filtering is not supported when specifying a list of containers") ^ cli/command/container/attach_test.go:82:17: fmt.Errorf can be replaced with errors.New (perfsprint) expectedErr = fmt.Errorf("unexpected error") ^ cli/command/container/create_test.go:234:40: fmt.Errorf can be replaced with errors.New (perfsprint) return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") ^ cli/command/container/list_test.go:150:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("error listing containers") ^ cli/command/container/rm_test.go:40:31: fmt.Errorf can be replaced with errors.New (perfsprint) return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container)) ^ cli/command/container/run_test.go:138:40: fmt.Errorf can be replaced with errors.New (perfsprint) return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") ^ cli/command/image/pull_test.go:115:49: fmt.Errorf can be replaced with errors.New (perfsprint) return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image") ^ cli/command/network/connect.go:88:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("invalid key/value pair format in driver options") ^ cli/command/plugin/create_test.go:96:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error creating plugin") ^ cli/command/plugin/disable_test.go:32:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error disabling plugin") ^ cli/command/plugin/enable_test.go:32:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("failed to enable plugin") ^ cli/command/plugin/inspect_test.go:55:22: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, nil, fmt.Errorf("error inspecting plugin") ^ cli/command/plugin/install_test.go:43:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("Error installing plugin") ^ cli/command/plugin/install_test.go:51:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("(image) when fetching") ^ cli/command/plugin/install_test.go:95:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("should not try to install plugin") ^ cli/command/plugin/list_test.go:35:41: fmt.Errorf can be replaced with errors.New (perfsprint) return types.PluginsListResponse{}, fmt.Errorf("error listing plugins") ^ cli/command/plugin/remove_test.go:27:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error removing plugin") ^ cli/command/registry/login_test.go:36:46: fmt.Errorf can be replaced with errors.New (perfsprint) return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password") ^ cli/command/registry/login_test.go:44:46: fmt.Errorf can be replaced with errors.New (perfsprint) return registrytypes.AuthenticateOKBody{}, fmt.Errorf(errUnknownUser) ^ cli/command/system/info.go:190:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("errors pretty printing info") ^ cli/command/system/prune.go:77:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`) ^ cli/command/system/version_test.go:19:28: fmt.Errorf can be replaced with errors.New (perfsprint) return types.Version{}, fmt.Errorf("no server") ^ cli/command/trust/key_load.go:112:22: fmt.Errorf can be replaced with errors.New (perfsprint) return []byte{}, fmt.Errorf("could not decrypt key") ^ cli/command/trust/revoke.go:44:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("cannot use a digest reference for IMAGE:TAG") ^ cli/command/trust/revoke.go:105:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("no signed tags to remove") ^ cli/command/trust/signer_add.go:56:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("releases is a reserved keyword, please use a different signer name") ^ cli/command/trust/signer_add.go:60:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("path to a public key must be provided using the `--key` flag") ^ opts/config.go:71:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("source is required") ^ opts/mount.go:168:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("type is required") ^ opts/mount.go:172:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("target is required") ^ opts/network.go:90:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("network name/id is not specified") ^ opts/network.go:129:18: fmt.Errorf can be replaced with errors.New (perfsprint) return "", "", fmt.Errorf("invalid key value pair format in driver options") ^ opts/opts.go:404:13: fmt.Errorf can be replaced with errors.New (perfsprint) return 0, fmt.Errorf("value is too precise") ^ opts/opts.go:412:18: fmt.Errorf can be replaced with errors.New (perfsprint) return "", "", fmt.Errorf("empty string specified for links") ^ opts/parse.go:84:37: fmt.Errorf can be replaced with errors.New (perfsprint) return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: no policy provided before colon") ^ opts/parse.go:89:38: fmt.Errorf can be replaced with errors.New (perfsprint) return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: maximum retry count must be an integer") ^ opts/port.go:105:13: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("hostip is not supported") ^ opts/secret.go:70:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("source is required") ^ opts/env_test.go:57:11: fmt.Errorf can be replaced with errors.New (perfsprint) err: fmt.Errorf("invalid environment variable: =a"), ^ opts/env_test.go:93:11: fmt.Errorf can be replaced with errors.New (perfsprint) err: fmt.Errorf("invalid environment variable: ="), ^ cli-plugins/manager/error_test.go:16:11: fmt.Errorf can be replaced with errors.New (perfsprint) inner := fmt.Errorf("testing") ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit dfec976e844b31d77defb49ed8b270487036e3ed) Signed-off-by: Cory Snider --- cli-plugins/manager/error_test.go | 4 ++-- cli/command/cli.go | 2 +- cli/command/container/attach.go | 3 +-- cli/command/container/attach_test.go | 3 +-- cli/command/container/create_test.go | 3 +-- cli/command/container/list_test.go | 4 ++-- cli/command/container/opts.go | 2 +- cli/command/container/rm_test.go | 4 ++-- cli/command/container/run_test.go | 3 +-- cli/command/image/pull_test.go | 3 ++- cli/command/network/connect.go | 4 ++-- cli/command/plugin/create_test.go | 12 +++++------- cli/command/plugin/disable_test.go | 6 +++--- cli/command/plugin/enable_test.go | 11 +++++------ cli/command/plugin/inspect_test.go | 4 ++-- cli/command/plugin/install_test.go | 10 +++++----- cli/command/plugin/list_test.go | 4 ++-- cli/command/plugin/remove_test.go | 6 +++--- cli/command/registry/login_test.go | 3 ++- cli/command/system/info.go | 3 ++- cli/command/system/prune.go | 7 ++++--- cli/command/system/version_test.go | 4 ++-- cli/command/trust/key_load.go | 2 +- cli/command/trust/revoke.go | 6 +++--- cli/command/trust/signer_add.go | 4 ++-- internal/test/cli.go | 4 ++-- opts/config.go | 3 ++- opts/env_test.go | 24 ++++++++++++------------ opts/mount.go | 5 +++-- opts/network.go | 7 ++++--- opts/opts.go | 6 +++--- opts/parse.go | 4 ++-- opts/port.go | 3 ++- opts/secret.go | 5 +++-- 34 files changed, 90 insertions(+), 88 deletions(-) diff --git a/cli-plugins/manager/error_test.go b/cli-plugins/manager/error_test.go index 55222d7042ea..c4cb19bd55d5 100644 --- a/cli-plugins/manager/error_test.go +++ b/cli-plugins/manager/error_test.go @@ -2,7 +2,7 @@ package manager import ( "encoding/json" - "fmt" + "errors" "testing" "gotest.tools/v3/assert" @@ -13,7 +13,7 @@ func TestPluginError(t *testing.T) { err := NewPluginError("new error") assert.Check(t, is.Error(err, "new error")) - inner := fmt.Errorf("testing") + inner := errors.New("testing") err = wrapAsPluginError(inner, "wrapping") assert.Check(t, is.Error(err, "wrapping: testing")) assert.Check(t, is.ErrorIs(err, inner)) diff --git a/cli/command/cli.go b/cli/command/cli.go index 2a61d5e48c5b..53a166903d52 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -278,7 +278,7 @@ func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigF func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) { if s == nil { - return docker.Endpoint{}, fmt.Errorf("no context store initialized") + return docker.Endpoint{}, errors.New("no context store initialized") } ctxMeta, err := s.GetMetadata(contextName) if err != nil { diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index bd17696b8032..98441909b75c 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -2,7 +2,6 @@ package container import ( "context" - "fmt" "io" "github.com/docker/cli/cli" @@ -153,7 +152,7 @@ func getExitStatus(errC <-chan error, resultC <-chan container.WaitResponse) err select { case result := <-resultC: if result.Error != nil { - return fmt.Errorf(result.Error.Message) + return errors.New(result.Error.Message) } if result.StatusCode != 0 { return cli.StatusError{StatusCode: int(result.StatusCode)} diff --git a/cli/command/container/attach_test.go b/cli/command/container/attach_test.go index b0aaea688cb3..7c16aec778f6 100644 --- a/cli/command/container/attach_test.go +++ b/cli/command/container/attach_test.go @@ -1,7 +1,6 @@ package container import ( - "fmt" "io" "testing" @@ -79,7 +78,7 @@ func TestNewAttachCommandErrors(t *testing.T) { func TestGetExitStatus(t *testing.T) { var ( - expectedErr = fmt.Errorf("unexpected error") + expectedErr = errors.New("unexpected error") errC = make(chan error, 1) resultC = make(chan container.WaitResponse, 1) ) diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index c74b5d359eec..5da0761d54f0 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -3,7 +3,6 @@ package container import ( "context" "errors" - "fmt" "io" "os" "runtime" @@ -225,7 +224,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) { platform *specs.Platform, containerName string, ) (container.CreateResponse, error) { - return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") + return container.CreateResponse{}, errors.New("shouldn't try to pull image") }, }, test.EnableContentTrust) cli.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/container/list_test.go b/cli/command/container/list_test.go index fbb625fd1a14..110960df1b93 100644 --- a/cli/command/container/list_test.go +++ b/cli/command/container/list_test.go @@ -1,7 +1,7 @@ package container import ( - "fmt" + "errors" "io" "testing" @@ -146,7 +146,7 @@ func TestContainerListErrors(t *testing.T) { }, { containerListFunc: func(_ types.ContainerListOptions) ([]types.Container, error) { - return nil, fmt.Errorf("error listing containers") + return nil, errors.New("error listing containers") }, expectedError: "error listing containers", }, diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index e4db20ee3e47..d59d4879bc5e 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -541,7 +541,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con return nil, errors.Errorf("--health-retries cannot be negative") } if copts.healthStartPeriod < 0 { - return nil, fmt.Errorf("--health-start-period cannot be negative") + return nil, errors.New("--health-start-period cannot be negative") } healthConfig = &container.HealthConfig{ diff --git a/cli/command/container/rm_test.go b/cli/command/container/rm_test.go index 7ab83dd2c907..a124edd0bca6 100644 --- a/cli/command/container/rm_test.go +++ b/cli/command/container/rm_test.go @@ -2,7 +2,7 @@ package container import ( "context" - "fmt" + "errors" "io" "sort" "sync" @@ -37,7 +37,7 @@ func TestRemoveForce(t *testing.T) { mutex.Unlock() if container == "nosuchcontainer" { - return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container)) + return errdefs.NotFound(errors.New("Error: no such container: " + container)) } return nil }, diff --git a/cli/command/container/run_test.go b/cli/command/container/run_test.go index 4f3acfa730d7..8df7c640b4c3 100644 --- a/cli/command/container/run_test.go +++ b/cli/command/container/run_test.go @@ -2,7 +2,6 @@ package container import ( "errors" - "fmt" "io" "testing" @@ -65,7 +64,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) { platform *specs.Platform, containerName string, ) (container.CreateResponse, error) { - return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") + return container.CreateResponse{}, errors.New("shouldn't try to pull image") }, }, test.EnableContentTrust) cli.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/image/pull_test.go b/cli/command/image/pull_test.go index 3e6c55a5b45b..ca87aeb70b36 100644 --- a/cli/command/image/pull_test.go +++ b/cli/command/image/pull_test.go @@ -1,6 +1,7 @@ package image import ( + "errors" "fmt" "io" "strings" @@ -112,7 +113,7 @@ func TestNewPullCommandWithContentTrustErrors(t *testing.T) { for _, tc := range testCases { cli := test.NewFakeCli(&fakeClient{ imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) { - return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image") + return io.NopCloser(strings.NewReader("")), errors.New("shouldn't try to pull image") }, }, test.EnableContentTrust) cli.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/network/connect.go b/cli/command/network/connect.go index 21dd12e3abd7..0ff367b3159c 100644 --- a/cli/command/network/connect.go +++ b/cli/command/network/connect.go @@ -2,7 +2,7 @@ package network import ( "context" - "fmt" + "errors" "strings" "github.com/docker/cli/cli" @@ -83,7 +83,7 @@ func convertDriverOpt(opts []string) (map[string]string, error) { // TODO(thaJeztah): we should probably not accept whitespace here (both for key and value). k = strings.TrimSpace(k) if !ok || k == "" { - return nil, fmt.Errorf("invalid key/value pair format in driver options") + return nil, errors.New("invalid key/value pair format in driver options") } driverOpt[k] = strings.TrimSpace(v) } diff --git a/cli/command/plugin/create_test.go b/cli/command/plugin/create_test.go index 37ce5e22c4bc..e05eb6085538 100644 --- a/cli/command/plugin/create_test.go +++ b/cli/command/plugin/create_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "runtime" "testing" @@ -91,16 +91,14 @@ func TestCreateErrorFromDaemon(t *testing.T) { fs.WithFile("config.json", `{ "Name": "plugin-foo" }`)) defer tmpDir.Remove() - cli := test.NewFakeCli(&fakeClient{ + cmd := newCreateCommand(test.NewFakeCli(&fakeClient{ pluginCreateFunc: func(createContext io.Reader, createOptions types.PluginCreateOptions) error { - return fmt.Errorf("Error creating plugin") + return errors.New("error creating plugin") }, - }) - - cmd := newCreateCommand(cli) + })) cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()}) cmd.SetOut(io.Discard) - assert.ErrorContains(t, cmd.Execute(), "Error creating plugin") + assert.ErrorContains(t, cmd.Execute(), "error creating plugin") } func TestCreatePlugin(t *testing.T) { diff --git a/cli/command/plugin/disable_test.go b/cli/command/plugin/disable_test.go index ca2e0d2cbbbe..cd78943c942d 100644 --- a/cli/command/plugin/disable_test.go +++ b/cli/command/plugin/disable_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -27,9 +27,9 @@ func TestPluginDisableErrors(t *testing.T) { }, { args: []string{"plugin-foo"}, - expectedError: "Error disabling plugin", + expectedError: "error disabling plugin", pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error { - return fmt.Errorf("Error disabling plugin") + return errors.New("error disabling plugin") }, }, } diff --git a/cli/command/plugin/enable_test.go b/cli/command/plugin/enable_test.go index 1d8840e77c16..0f220547562a 100644 --- a/cli/command/plugin/enable_test.go +++ b/cli/command/plugin/enable_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -29,7 +29,7 @@ func TestPluginEnableErrors(t *testing.T) { { args: []string{"plugin-foo"}, pluginEnableFunc: func(name string, options types.PluginEnableOptions) error { - return fmt.Errorf("failed to enable plugin") + return errors.New("failed to enable plugin") }, expectedError: "failed to enable plugin", }, @@ -43,10 +43,9 @@ func TestPluginEnableErrors(t *testing.T) { } for _, tc := range testCases { - cmd := newEnableCommand( - test.NewFakeCli(&fakeClient{ - pluginEnableFunc: tc.pluginEnableFunc, - })) + cmd := newEnableCommand(test.NewFakeCli(&fakeClient{ + pluginEnableFunc: tc.pluginEnableFunc, + })) cmd.SetArgs(tc.args) for key, value := range tc.flags { cmd.Flags().Set(key, value) diff --git a/cli/command/plugin/inspect_test.go b/cli/command/plugin/inspect_test.go index 4d3127660a68..f5c2ad585760 100644 --- a/cli/command/plugin/inspect_test.go +++ b/cli/command/plugin/inspect_test.go @@ -1,13 +1,13 @@ package plugin import ( + "errors" "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" - "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -52,7 +52,7 @@ func TestInspectErrors(t *testing.T) { args: []string{"foo"}, expectedError: "error inspecting plugin", inspectFunc: func(name string) (*types.Plugin, []byte, error) { - return nil, nil, fmt.Errorf("error inspecting plugin") + return nil, nil, errors.New("error inspecting plugin") }, }, { diff --git a/cli/command/plugin/install_test.go b/cli/command/plugin/install_test.go index e49b582f83c8..03cad5f110e9 100644 --- a/cli/command/plugin/install_test.go +++ b/cli/command/plugin/install_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "strings" "testing" @@ -38,9 +38,9 @@ func TestInstallErrors(t *testing.T) { { description: "installation error", args: []string{"foo"}, - expectedError: "Error installing plugin", + expectedError: "error installing plugin", installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, fmt.Errorf("Error installing plugin") + return nil, errors.New("error installing plugin") }, }, { @@ -48,7 +48,7 @@ func TestInstallErrors(t *testing.T) { args: []string{"foo"}, expectedError: "docker image pull", installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, fmt.Errorf("(image) when fetching") + return nil, errors.New("(image) when fetching") }, }, } @@ -92,7 +92,7 @@ func TestInstallContentTrustErrors(t *testing.T) { for _, tc := range testCases { cli := test.NewFakeCli(&fakeClient{ pluginInstallFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, fmt.Errorf("should not try to install plugin") + return nil, errors.New("should not try to install plugin") }, }, test.EnableContentTrust) cli.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/plugin/list_test.go b/cli/command/plugin/list_test.go index ed30eb1c596f..a5e4e71d31a0 100644 --- a/cli/command/plugin/list_test.go +++ b/cli/command/plugin/list_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -32,7 +32,7 @@ func TestListErrors(t *testing.T) { args: []string{}, expectedError: "error listing plugins", listFunc: func(filter filters.Args) (types.PluginsListResponse, error) { - return types.PluginsListResponse{}, fmt.Errorf("error listing plugins") + return types.PluginsListResponse{}, errors.New("error listing plugins") }, }, { diff --git a/cli/command/plugin/remove_test.go b/cli/command/plugin/remove_test.go index 36cfe0ba4508..cf701cfa3b72 100644 --- a/cli/command/plugin/remove_test.go +++ b/cli/command/plugin/remove_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -24,9 +24,9 @@ func TestRemoveErrors(t *testing.T) { { args: []string{"plugin-foo"}, pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error { - return fmt.Errorf("Error removing plugin") + return errors.New("error removing plugin") }, - expectedError: "Error removing plugin", + expectedError: "error removing plugin", }, } diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index 483f4578ee31..8a61c65fcb42 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -3,6 +3,7 @@ package registry import ( "bytes" "context" + "errors" "fmt" "testing" @@ -40,7 +41,7 @@ func (c fakeClient) Info(context.Context) (types.Info, error) { func (c fakeClient) RegistryLogin(_ context.Context, auth types.AuthConfig) (registrytypes.AuthenticateOKBody, error) { if auth.Password == expiredPassword { - return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password") + return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password") } if auth.Password == useToken { return registrytypes.AuthenticateOKBody{ diff --git a/cli/command/system/info.go b/cli/command/system/info.go index d30f8b2dfbfa..ecf0c47360dd 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -2,6 +2,7 @@ package system import ( "context" + "errors" "fmt" "io" "regexp" @@ -167,7 +168,7 @@ func prettyPrintInfo(dockerCli command.Cli, info info) error { } if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 { - return fmt.Errorf("errors pretty printing info") + return errors.New("errors pretty printing info") } return nil } diff --git a/cli/command/system/prune.go b/cli/command/system/prune.go index 51773cce3a38..aa2511f5563a 100644 --- a/cli/command/system/prune.go +++ b/cli/command/system/prune.go @@ -2,6 +2,7 @@ package system import ( "bytes" + "errors" "fmt" "sort" "text/template" @@ -71,7 +72,7 @@ Are you sure you want to continue?` func runPrune(dockerCli command.Cli, options pruneOptions) error { // TODO version this once "until" filter is supported for volumes if options.pruneVolumes && options.filter.Value().Contains("until") { - return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`) + return errors.New(`ERROR: The "until" filter is not supported with "--volumes"`) } if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), confirmationMessage(dockerCli, options)) { return nil @@ -96,11 +97,11 @@ func runPrune(dockerCli command.Cli, options pruneOptions) error { } spaceReclaimed += spc if output != "" { - fmt.Fprintln(dockerCli.Out(), output) + _, _ = fmt.Fprintln(dockerCli.Out(), output) } } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) + _, _ = fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) return nil } diff --git a/cli/command/system/version_test.go b/cli/command/system/version_test.go index 5d7483c66c31..c0cf6425975f 100644 --- a/cli/command/system/version_test.go +++ b/cli/command/system/version_test.go @@ -2,7 +2,7 @@ package system import ( "context" - "fmt" + "errors" "strings" "testing" @@ -16,7 +16,7 @@ import ( func TestVersionWithoutServer(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ serverVersion: func(ctx context.Context) (types.Version, error) { - return types.Version{}, fmt.Errorf("no server") + return types.Version{}, errors.New("no server") }, }) cmd := NewVersionCommand(cli) diff --git a/cli/command/trust/key_load.go b/cli/command/trust/key_load.go index bbb19e733e39..4a5bb2605578 100644 --- a/cli/command/trust/key_load.go +++ b/cli/command/trust/key_load.go @@ -109,7 +109,7 @@ func decodePrivKeyIfNecessary(privPemBytes []byte, passRet notary.PassRetriever) if _, ok := pemBlock.Headers["path"]; !ok { privKey, _, err := trustmanager.GetPasswdDecryptBytes(passRet, privPemBytes, "", "encrypted") if err != nil { - return []byte{}, fmt.Errorf("could not decrypt key") + return []byte{}, errors.New("could not decrypt key") } privPemBytes = privKey.Private() } diff --git a/cli/command/trust/revoke.go b/cli/command/trust/revoke.go index 31437b03f1c8..6aaa7d9f1069 100644 --- a/cli/command/trust/revoke.go +++ b/cli/command/trust/revoke.go @@ -42,7 +42,7 @@ func revokeTrust(cli command.Cli, remote string, options revokeOptions) error { } tag := imgRefAndAuth.Tag() if imgRefAndAuth.Tag() == "" && imgRefAndAuth.Digest() != "" { - return fmt.Errorf("cannot use a digest reference for IMAGE:TAG") + return errors.New("cannot use a digest reference for IMAGE:TAG") } if imgRefAndAuth.Tag() == "" && !options.forceYes { deleteRemote := command.PromptForConfirmation(os.Stdin, cli.Out(), fmt.Sprintf("Please confirm you would like to delete all signature data for %s?", remote)) @@ -64,7 +64,7 @@ func revokeTrust(cli command.Cli, remote string, options revokeOptions) error { if err := revokeSignature(notaryRepo, tag); err != nil { return errors.Wrapf(err, "could not remove signature for %s", remote) } - fmt.Fprintf(cli.Out(), "Successfully deleted signature for %s\n", remote) + _, _ = fmt.Fprintf(cli.Out(), "Successfully deleted signature for %s\n", remote) return nil } @@ -101,7 +101,7 @@ func revokeAllSigs(notaryRepo client.Repository) error { } if len(releasedTargetWithRoleList) == 0 { - return fmt.Errorf("no signed tags to remove") + return errors.New("no signed tags to remove") } // we need all the roles that signed each released target so we can remove from all roles. diff --git a/cli/command/trust/signer_add.go b/cli/command/trust/signer_add.go index 53c5c67cd433..c0090b508e83 100644 --- a/cli/command/trust/signer_add.go +++ b/cli/command/trust/signer_add.go @@ -53,11 +53,11 @@ func addSigner(cli command.Cli, options signerAddOptions) error { return fmt.Errorf("signer name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", signerName) } if signerName == "releases" { - return fmt.Errorf("releases is a reserved keyword, please use a different signer name") + return errors.New("releases is a reserved keyword, please use a different signer name") } if options.keys.Len() == 0 { - return fmt.Errorf("path to a public key must be provided using the `--key` flag") + return errors.New("path to a public key must be provided using the `--key` flag") } signerPubKeys, err := ingestPublicKeys(options.keys.GetAll()) if err != nil { diff --git a/internal/test/cli.go b/internal/test/cli.go index 11d674d85744..85079347f9da 100644 --- a/internal/test/cli.go +++ b/internal/test/cli.go @@ -2,7 +2,7 @@ package test import ( "bytes" - "fmt" + "errors" "io" "strings" @@ -172,7 +172,7 @@ func (c *FakeCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []st if c.notaryClientFunc != nil { return c.notaryClientFunc(imgRefAndAuth, actions) } - return nil, fmt.Errorf("no notary client available unless defined") + return nil, errors.New("no notary client available unless defined") } // ManifestStore returns a fake store used for testing diff --git a/opts/config.go b/opts/config.go index 3be0fa93dde0..1423ae3be585 100644 --- a/opts/config.go +++ b/opts/config.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "os" "strconv" @@ -68,7 +69,7 @@ func (o *ConfigOpt) Set(value string) error { } if options.ConfigName == "" { - return fmt.Errorf("source is required") + return errors.New("source is required") } if options.File.Name == "" { options.File.Name = options.ConfigName diff --git a/opts/env_test.go b/opts/env_test.go index 3561ceb3140c..a8a565be2a6f 100644 --- a/opts/env_test.go +++ b/opts/env_test.go @@ -11,9 +11,9 @@ import ( func TestValidateEnv(t *testing.T) { type testCase struct { - value string - expected string - err error + value string + expected string + expectedErr string } tests := []testCase{ { @@ -53,8 +53,8 @@ func TestValidateEnv(t *testing.T) { expected: fmt.Sprintf("PATH=%v", os.Getenv("PATH")), }, { - value: "=a", - err: fmt.Errorf("invalid environment variable: =a"), + value: "=a", + expectedErr: "invalid environment variable: =a", }, { value: "PATH=", @@ -89,17 +89,17 @@ func TestValidateEnv(t *testing.T) { expected: "some space after ", }, { - value: "=", - err: fmt.Errorf("invalid environment variable: ="), + value: "=", + expectedErr: "invalid environment variable: =", }, } if runtime.GOOS == "windows" { // Environment variables are case in-sensitive on Windows tests = append(tests, testCase{ - value: "PaTh", - expected: fmt.Sprintf("PaTh=%v", os.Getenv("PATH")), - err: nil, + value: "PaTh", + expected: fmt.Sprintf("PaTh=%v", os.Getenv("PATH")), + expectedErr: "", }) } @@ -108,10 +108,10 @@ func TestValidateEnv(t *testing.T) { t.Run(tc.value, func(t *testing.T) { actual, err := ValidateEnv(tc.value) - if tc.err == nil { + if tc.expectedErr == "" { assert.NilError(t, err) } else { - assert.Error(t, err, tc.err.Error()) + assert.Error(t, err, tc.expectedErr) } assert.Equal(t, actual, tc.expected) }) diff --git a/opts/mount.go b/opts/mount.go index 2b531127ebdb..ac1ba79c54d2 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "os" "path/filepath" @@ -144,11 +145,11 @@ func (m *MountOpt) Set(value string) error { } if mount.Type == "" { - return fmt.Errorf("type is required") + return errors.New("type is required") } if mount.Target == "" { - return fmt.Errorf("target is required") + return errors.New("target is required") } if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume { diff --git a/opts/network.go b/opts/network.go index 12c3977b1bc3..da26c605ce33 100644 --- a/opts/network.go +++ b/opts/network.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "regexp" "strings" @@ -76,11 +77,11 @@ func (n *NetworkOpt) Set(value string) error { } netOpt.DriverOpts[key] = val default: - return fmt.Errorf("invalid field key %s", key) + return errors.New("invalid field key " + key) } } if len(netOpt.Target) == 0 { - return fmt.Errorf("network name/id is not specified") + return errors.New("network name/id is not specified") } } else { netOpt.Target = value @@ -119,7 +120,7 @@ func parseDriverOpt(driverOpt string) (string, string, error) { // TODO(thaJeztah): should value be converted to lowercase as well, or only the key? key, value, ok := strings.Cut(strings.ToLower(driverOpt), "=") if !ok || key == "" { - return "", "", fmt.Errorf("invalid key value pair format in driver options") + return "", "", errors.New("invalid key value pair format in driver options") } key = strings.TrimSpace(key) value = strings.TrimSpace(value) diff --git a/opts/opts.go b/opts/opts.go index 4e7790f0fcd9..a00b7191d8a1 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -397,7 +397,7 @@ func ParseCPUs(value string) (int64, error) { } nano := cpu.Mul(cpu, big.NewRat(1e9, 1)) if !nano.IsInt() { - return 0, fmt.Errorf("value is too precise") + return 0, errors.New("value is too precise") } return nano.Num().Int64(), nil } @@ -405,14 +405,14 @@ func ParseCPUs(value string) (int64, error) { // ParseLink parses and validates the specified string as a link format (name:alias) func ParseLink(val string) (string, string, error) { if val == "" { - return "", "", fmt.Errorf("empty string specified for links") + return "", "", errors.New("empty string specified for links") } // We expect two parts, but restrict to three to allow detecting invalid formats. arr := strings.SplitN(val, ":", 3) // TODO(thaJeztah): clean up this logic!! if len(arr) > 2 { - return "", "", fmt.Errorf("bad format for links: %s", val) + return "", "", errors.New("bad format for links: " + val) } // TODO(thaJeztah): this should trim the "/" prefix as well?? if len(arr) == 1 { diff --git a/opts/parse.go b/opts/parse.go index 017577e4bf09..d2b657df4189 100644 --- a/opts/parse.go +++ b/opts/parse.go @@ -1,7 +1,7 @@ package opts import ( - "fmt" + "errors" "os" "strconv" "strings" @@ -81,7 +81,7 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) { if v != "" { count, err := strconv.Atoi(v) if err != nil { - return p, fmt.Errorf("invalid restart policy format: maximum retry count must be an integer") + return p, errors.New("invalid restart policy format: maximum retry count must be an integer") } p.MaximumRetryCount = count } diff --git a/opts/port.go b/opts/port.go index fe41cdd2881f..2f2aa329c8ee 100644 --- a/opts/port.go +++ b/opts/port.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "net" "regexp" @@ -102,7 +103,7 @@ func (p *PortOpt) Set(value string) error { for _, portBindings := range portBindingMap { for _, portBinding := range portBindings { if portBinding.HostIP != "" { - return fmt.Errorf("hostip is not supported") + return errors.New("hostip is not supported") } } } diff --git a/opts/secret.go b/opts/secret.go index 750dbe4f301d..09d2b2b3be0f 100644 --- a/opts/secret.go +++ b/opts/secret.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "os" "strconv" @@ -62,12 +63,12 @@ func (o *SecretOpt) Set(value string) error { options.File.Mode = os.FileMode(m) default: - return fmt.Errorf("invalid field in secret request: %s", key) + return errors.New("invalid field in secret request: " + key) } } if options.SecretName == "" { - return fmt.Errorf("source is required") + return errors.New("source is required") } if options.File.Name == "" { options.File.Name = options.SecretName From abf372a8715e1d25f60450c33adabcb6eea0b087 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 20:53:13 +0200 Subject: [PATCH 18/27] cli/command: TestGetDefaultAuthConfig: remove unused expectedErr Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 7db922cf9f8545cb895807007e9786991235e543) Signed-off-by: Cory Snider --- cli/command/registry_test.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/cli/command/registry_test.go b/cli/command/registry_test.go index 35e80200897a..78117941c31f 100644 --- a/cli/command/registry_test.go +++ b/cli/command/registry_test.go @@ -45,13 +45,11 @@ func TestGetDefaultAuthConfig(t *testing.T) { testCases := []struct { checkCredStore bool inputServerAddress string - expectedErr string expectedAuthConfig types.AuthConfig }{ { checkCredStore: false, inputServerAddress: "", - expectedErr: "", expectedAuthConfig: types.AuthConfig{ ServerAddress: "", Username: "", @@ -61,19 +59,16 @@ func TestGetDefaultAuthConfig(t *testing.T) { { checkCredStore: true, inputServerAddress: testAuthConfigs[0].ServerAddress, - expectedErr: "", expectedAuthConfig: testAuthConfigs[0], }, { checkCredStore: true, inputServerAddress: testAuthConfigs[1].ServerAddress, - expectedErr: "", expectedAuthConfig: testAuthConfigs[1], }, { checkCredStore: true, inputServerAddress: fmt.Sprintf("https://%s", testAuthConfigs[1].ServerAddress), - expectedErr: "", expectedAuthConfig: testAuthConfigs[1], }, } @@ -87,13 +82,8 @@ func TestGetDefaultAuthConfig(t *testing.T) { for _, tc := range testCases { serverAddress := tc.inputServerAddress authconfig, err := command.GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/") - if tc.expectedErr != "" { - assert.Check(t, err != nil) - assert.Check(t, is.Equal(tc.expectedErr, err.Error())) - } else { - assert.NilError(t, err) - assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, authconfig)) - } + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, authconfig)) } } From ac722bb368fad48c4882b86945624268b27b1abe Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 21:07:37 +0200 Subject: [PATCH 19/27] linting: fmt.Sprintf can be replaced with string concatenation (perfsprint) cli/registry/client/endpoint.go:128:34: fmt.Sprintf can be replaced with string concatenation (perfsprint) req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", th.token)) ^ cli/command/telemetry_docker.go:88:14: fmt.Sprintf can be replaced with string concatenation (perfsprint) endpoint = fmt.Sprintf("unix://%s", path.Join(u.Host, u.Path)) ^ cli/command/cli_test.go:195:47: fmt.Sprintf can be replaced with string concatenation (perfsprint) opts := &flags.ClientOptions{Hosts: []string{fmt.Sprintf("unix://%s", socket)}} ^ cli/command/registry_test.go:59:24: fmt.Sprintf can be replaced with string concatenation (perfsprint) inputServerAddress: fmt.Sprintf("https://%s", testAuthConfigs[1].ServerAddress), ^ cli/command/container/opts_test.go:338:35: fmt.Sprintf can be replaced with string concatenation (perfsprint) if config, _, _ := mustParse(t, fmt.Sprintf("--hostname=%s", hostname)); config.Hostname != expectedHostname { ^ cli/command/context/options.go:79:24: fmt.Sprintf can be replaced with string concatenation (perfsprint) errs = append(errs, fmt.Sprintf("%s: unrecognized config key", k)) ^ cli/command/image/build.go:461:68: fmt.Sprintf can be replaced with string concatenation (perfsprint) line = dockerfileFromLinePattern.ReplaceAllLiteralString(line, fmt.Sprintf("FROM %s", reference.FamiliarString(trustedRef))) ^ cli/command/image/remove_test.go:21:9: fmt.Sprintf can be replaced with string concatenation (perfsprint) return fmt.Sprintf("Error: No such image: %s", n.imageID) ^ cli/command/image/build/context.go:229:102: fmt.Sprintf can be replaced with string concatenation (perfsprint) progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", fmt.Sprintf("Downloading build context from remote url: %s", remoteURL)) ^ cli/command/service/logs.go:215:16: fmt.Sprintf can be replaced with string concatenation (perfsprint) taskName += fmt.Sprintf(".%s", task.ID) ^ cli/command/service/logs.go:217:16: fmt.Sprintf can be replaced with string concatenation (perfsprint) taskName += fmt.Sprintf(".%s", stringid.TruncateID(task.ID)) ^ cli/command/service/progress/progress_test.go:877:18: fmt.Sprintf can be replaced with string concatenation (perfsprint) ID: fmt.Sprintf("task%s", nodeID), ^ cli/command/stack/swarm/remove.go:61:24: fmt.Sprintf can be replaced with string concatenation (perfsprint) errs = append(errs, fmt.Sprintf("Failed to remove some resources from stack: %s", namespace)) ^ cli/command/swarm/ipnet_slice_test.go:32:9: fmt.Sprintf can be replaced with string concatenation (perfsprint) arg := fmt.Sprintf("--cidrs=%s", strings.Join(vals, ",")) ^ cli/command/swarm/ipnet_slice_test.go:137:30: fmt.Sprintf can be replaced with string concatenation (perfsprint) if err := f.Parse([]string{fmt.Sprintf("--cidrs=%s", strings.Join(test.FlagArg, ","))}); err != nil { ^ cli/compose/schema/schema.go:105:11: fmt.Sprintf can be replaced with string concatenation (perfsprint) return fmt.Sprintf("must be a %s", humanReadableType(expectedType)) ^ cli/manifest/store/store.go:165:9: fmt.Sprintf can be replaced with string concatenation (perfsprint) return fmt.Sprintf("No such manifest: %s", n.object) ^ e2e/image/push_test.go:340:4: fmt.Sprintf can be replaced with string concatenation (perfsprint) fmt.Sprintf("NOTARY_ROOT_PASSPHRASE=%s", pwd), ^ e2e/image/push_test.go:341:4: fmt.Sprintf can be replaced with string concatenation (perfsprint) fmt.Sprintf("NOTARY_TARGETS_PASSPHRASE=%s", pwd), ^ e2e/image/push_test.go:342:4: fmt.Sprintf can be replaced with string concatenation (perfsprint) fmt.Sprintf("NOTARY_SNAPSHOT_PASSPHRASE=%s", pwd), ^ e2e/image/push_test.go:343:4: fmt.Sprintf can be replaced with string concatenation (perfsprint) fmt.Sprintf("NOTARY_DELEGATION_PASSPHRASE=%s", pwd), ^ e2e/plugin/trust_test.go:23:16: fmt.Sprintf can be replaced with string concatenation (perfsprint) pluginName := fmt.Sprintf("%s/plugin-content-trust", registryPrefix) ^ e2e/plugin/trust_test.go:53:8: fmt.Sprintf can be replaced with string concatenation (perfsprint) Out: fmt.Sprintf("Installed plugin %s", pluginName), ^ e2e/trust/revoke_test.go:62:57: fmt.Sprintf can be replaced with string concatenation (perfsprint) icmd.RunCommand("docker", "tag", fixtures.AlpineImage, fmt.Sprintf("%s:v1", revokeRepo)).Assert(t, icmd.Success) ^ e2e/trust/revoke_test.go:64:49: fmt.Sprintf can be replaced with string concatenation (perfsprint) icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v1", revokeRepo)), ^ e2e/trust/revoke_test.go:68:58: fmt.Sprintf can be replaced with string concatenation (perfsprint) icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, fmt.Sprintf("%s:v2", revokeRepo)).Assert(t, icmd.Success) ^ e2e/trust/revoke_test.go:70:49: fmt.Sprintf can be replaced with string concatenation (perfsprint) icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v2", revokeRepo)), ^ e2e/trust/sign_test.go:36:47: fmt.Sprintf can be replaced with string concatenation (perfsprint) assert.Check(t, is.Contains(result.Stdout(), fmt.Sprintf("v1: digest: sha256:%s", fixtures.AlpineSha))) ^ e2e/trust/sign_test.go:53:47: fmt.Sprintf can be replaced with string concatenation (perfsprint) assert.Check(t, is.Contains(result.Stdout(), fmt.Sprintf("v1: digest: sha256:%s", fixtures.BusyboxSha))) ^ e2e/trust/sign_test.go:65:47: fmt.Sprintf can be replaced with string concatenation (perfsprint) assert.Check(t, is.Contains(result.Stdout(), fmt.Sprintf("v1: digest: sha256:%s", fixtures.AlpineSha))) ^ opts/file.go:21:9: fmt.Sprintf can be replaced with string concatenation (perfsprint) return fmt.Sprintf("poorly formatted environment: %s", e.msg) ^ opts/hosts_test.go:26:31: fmt.Sprintf can be replaced with string concatenation (perfsprint) "tcp://host:": fmt.Sprintf("tcp://host:%s", defaultHTTPPort), ^ Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0ba14fde41f4308f1d9fa73d03fb28bbb1650325) Signed-off-by: Cory Snider --- cli/command/cli_test.go | 2 +- cli/command/container/opts_test.go | 2 +- cli/command/context/options.go | 3 +-- cli/command/image/build.go | 2 +- cli/command/image/build/context.go | 5 +++-- cli/command/image/remove_test.go | 2 +- cli/command/registry_test.go | 3 +-- cli/command/service/logs.go | 4 ++-- cli/command/service/progress/progress_test.go | 2 +- cli/command/stack/swarm/remove.go | 2 +- cli/command/swarm/ipnet_slice_test.go | 4 ++-- cli/compose/schema/schema.go | 2 +- cli/manifest/store/store.go | 3 +-- cli/registry/client/endpoint.go | 3 +-- e2e/image/push_test.go | 8 ++++---- e2e/plugin/trust_test.go | 5 ++--- e2e/trust/revoke_test.go | 9 ++++----- e2e/trust/sign_test.go | 7 +++---- opts/file.go | 2 +- opts/hosts_test.go | 2 +- 20 files changed, 33 insertions(+), 39 deletions(-) diff --git a/cli/command/cli_test.go b/cli/command/cli_test.go index 7a0b4e727e2e..13fb5d790449 100644 --- a/cli/command/cli_test.go +++ b/cli/command/cli_test.go @@ -192,7 +192,7 @@ func TestInitializeFromClientHangs(t *testing.T) { ts.Start() defer ts.Close() - opts := &flags.ClientOptions{Hosts: []string{fmt.Sprintf("unix://%s", socket)}} + opts := &flags.ClientOptions{Hosts: []string{"unix://" + socket}} configFile := &configfile.ConfigFile{} apiClient, err := NewAPIClientFromFlags(opts, configFile) assert.NilError(t, err) diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index 6421f80a703c..17fa075d29cb 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -329,7 +329,7 @@ func TestParseHostname(t *testing.T) { hostnameWithDomain := "--hostname=hostname.domainname" hostnameWithDomainTld := "--hostname=hostname.domainname.tld" for hostname, expectedHostname := range validHostnames { - if config, _ := mustParse(t, fmt.Sprintf("--hostname=%s", hostname)); config.Hostname != expectedHostname { + if config, _ := mustParse(t, "--hostname="+hostname); config.Hostname != expectedHostname { t.Fatalf("Expected the config to have 'hostname' as %q, got %q", expectedHostname, config.Hostname) } } diff --git a/cli/command/context/options.go b/cli/command/context/options.go index 39707fe3e94f..80ddf3d6e9f6 100644 --- a/cli/command/context/options.go +++ b/cli/command/context/options.go @@ -1,7 +1,6 @@ package context import ( - "fmt" "strconv" "strings" @@ -77,7 +76,7 @@ func validateConfig(config map[string]string, allowedKeys map[string]struct{}) e var errs []string for k := range config { if _, ok := allowedKeys[k]; !ok { - errs = append(errs, fmt.Sprintf("%s: unrecognized config key", k)) + errs = append(errs, "unrecognized config key: "+k) } } if len(errs) == 0 { diff --git a/cli/command/image/build.go b/cli/command/image/build.go index 771f61ec66f0..cad1195319f6 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -459,7 +459,7 @@ func rewriteDockerfileFromForContentTrust(ctx context.Context, dockerfile io.Rea return nil, nil, err } - line = dockerfileFromLinePattern.ReplaceAllLiteralString(line, fmt.Sprintf("FROM %s", reference.FamiliarString(trustedRef))) + line = dockerfileFromLinePattern.ReplaceAllLiteralString(line, "FROM "+reference.FamiliarString(trustedRef)) resolvedTags = append(resolvedTags, &resolvedTag{ digestRef: trustedRef, tagRef: ref, diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index 141344a4072f..7131372f5fd8 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -223,7 +223,7 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read progressOutput := streamformatter.NewProgressOutput(out) // Pass the response body through a progress reader. - progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", fmt.Sprintf("Downloading build context from remote url: %s", remoteURL)) + progReader := progress.NewProgressReader(response.Body, progressOutput, response.ContentLength, "", "Downloading build context from remote url: "+remoteURL) return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName) } @@ -231,7 +231,8 @@ 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) { - if resp, err = http.Get(url); err != nil { //nolint:gosec // Ignore G107: Potential HTTP request made with variable url + // #nosec G107 -- Ignore G107: Potential HTTP request made with variable url + if resp, err = http.Get(url); err != nil { return nil, err } if resp.StatusCode < http.StatusBadRequest { diff --git a/cli/command/image/remove_test.go b/cli/command/image/remove_test.go index 55de3eb6a62e..7a45b614efd6 100644 --- a/cli/command/image/remove_test.go +++ b/cli/command/image/remove_test.go @@ -18,7 +18,7 @@ type notFound struct { } func (n notFound) Error() string { - return fmt.Sprintf("Error: No such image: %s", n.imageID) + return "Error: No such image: " + n.imageID } func (n notFound) NotFound() bool { diff --git a/cli/command/registry_test.go b/cli/command/registry_test.go index 78117941c31f..9ebe105f8339 100644 --- a/cli/command/registry_test.go +++ b/cli/command/registry_test.go @@ -3,7 +3,6 @@ package command_test import ( "bytes" "context" - "fmt" "path/filepath" "testing" @@ -68,7 +67,7 @@ func TestGetDefaultAuthConfig(t *testing.T) { }, { checkCredStore: true, - inputServerAddress: fmt.Sprintf("https://%s", testAuthConfigs[1].ServerAddress), + inputServerAddress: "https://" + testAuthConfigs[1].ServerAddress, expectedAuthConfig: testAuthConfigs[1], }, } diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index 215bad74d9cd..90252bf0ed69 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -214,9 +214,9 @@ func (f *taskFormatter) format(ctx context.Context, logCtx logContext) (string, taskName := fmt.Sprintf("%s.%d", serviceName, task.Slot) if !f.opts.noTaskIDs { if f.opts.noTrunc { - taskName += fmt.Sprintf(".%s", task.ID) + taskName += "." + task.ID } else { - taskName += fmt.Sprintf(".%s", stringid.TruncateID(task.ID)) + taskName += "." + stringid.TruncateID(task.ID) } } diff --git a/cli/command/service/progress/progress_test.go b/cli/command/service/progress/progress_test.go index 64cbde99cbd1..2edad317f42e 100644 --- a/cli/command/service/progress/progress_test.go +++ b/cli/command/service/progress/progress_test.go @@ -874,7 +874,7 @@ func TestGlobalJobProgressUpdaterLarge(t *testing.T) { tasks := []swarm.Task{} for nodeID := range activeNodes { tasks = append(tasks, swarm.Task{ - ID: fmt.Sprintf("task%s", nodeID), + ID: "task" + nodeID, NodeID: nodeID, DesiredState: swarm.TaskStateComplete, Status: swarm.TaskStatus{ diff --git a/cli/command/stack/swarm/remove.go b/cli/command/stack/swarm/remove.go index 4dedef12f356..8fa1eaa2726b 100644 --- a/cli/command/stack/swarm/remove.go +++ b/cli/command/stack/swarm/remove.go @@ -58,7 +58,7 @@ func RunRemove(dockerCli command.Cli, opts options.Remove) error { hasError = removeNetworks(ctx, dockerCli, networks) || hasError if hasError { - errs = append(errs, fmt.Sprintf("Failed to remove some resources from stack: %s", namespace)) + errs = append(errs, "Failed to remove some resources from stack: "+namespace) } } diff --git a/cli/command/swarm/ipnet_slice_test.go b/cli/command/swarm/ipnet_slice_test.go index 3f28466ea101..ef12ebba654f 100644 --- a/cli/command/swarm/ipnet_slice_test.go +++ b/cli/command/swarm/ipnet_slice_test.go @@ -29,7 +29,7 @@ func TestIPNets(t *testing.T) { f := setUpIPNetFlagSet(&ips) vals := []string{"192.168.1.1/24", "10.0.0.1/16", "fd00:0:0:0:0:0:0:2/64"} - arg := fmt.Sprintf("--cidrs=%s", strings.Join(vals, ",")) + arg := "--cidrs=" + strings.Join(vals, ",") err := f.Parse([]string{arg}) if err != nil { t.Fatal("expected no error; got", err) @@ -135,7 +135,7 @@ func TestIPNetBadQuoting(t *testing.T) { var cidrs []net.IPNet f := setUpIPNetFlagSet(&cidrs) - if err := f.Parse([]string{fmt.Sprintf("--cidrs=%s", strings.Join(test.FlagArg, ","))}); err != nil { + if err := f.Parse([]string{"--cidrs=" + strings.Join(test.FlagArg, ",")}); err != nil { t.Fatalf("flag parsing failed with error: %s\nparsing:\t%#v\nwant:\t\t%s", err, test.FlagArg, test.Want[i]) } diff --git a/cli/compose/schema/schema.go b/cli/compose/schema/schema.go index c7786f48fb83..291b8ba0ff46 100644 --- a/cli/compose/schema/schema.go +++ b/cli/compose/schema/schema.go @@ -99,7 +99,7 @@ func getDescription(err validationError) string { switch err.parent.Type() { case "invalid_type": if expectedType, ok := err.parent.Details()["expected"].(string); ok { - return fmt.Sprintf("must be a %s", humanReadableType(expectedType)) + return "must be a " + humanReadableType(expectedType) } case jsonschemaOneOf, jsonschemaAnyOf: if err.child == nil { diff --git a/cli/manifest/store/store.go b/cli/manifest/store/store.go index 39e576f6b2db..7a6964492735 100644 --- a/cli/manifest/store/store.go +++ b/cli/manifest/store/store.go @@ -2,7 +2,6 @@ package store import ( "encoding/json" - "fmt" "os" "path/filepath" "strings" @@ -162,7 +161,7 @@ func newNotFoundError(ref string) *notFoundError { } func (n *notFoundError) Error() string { - return fmt.Sprintf("No such manifest: %s", n.object) + return "No such manifest: " + n.object } // NotFound interface diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index ebb7192bd2b7..47dea00ed428 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -1,7 +1,6 @@ package client import ( - "fmt" "net" "net/http" "time" @@ -126,7 +125,7 @@ type existingTokenHandler struct { } func (th *existingTokenHandler) AuthorizeRequest(req *http.Request, _ map[string]string) error { - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", th.token)) + req.Header.Set("Authorization", "Bearer "+th.token) return nil } diff --git a/e2e/image/push_test.go b/e2e/image/push_test.go index 9695c99aa8cf..79f9fde0185c 100644 --- a/e2e/image/push_test.go +++ b/e2e/image/push_test.go @@ -329,10 +329,10 @@ func createImage(t *testing.T, repo string, tags ...string) string { func withNotaryPassphrase(pwd string) func(*icmd.Cmd) { return func(c *icmd.Cmd) { c.Env = append(c.Env, []string{ - fmt.Sprintf("NOTARY_ROOT_PASSPHRASE=%s", pwd), - fmt.Sprintf("NOTARY_TARGETS_PASSPHRASE=%s", pwd), - fmt.Sprintf("NOTARY_SNAPSHOT_PASSPHRASE=%s", pwd), - fmt.Sprintf("NOTARY_DELEGATION_PASSPHRASE=%s", pwd), + "NOTARY_ROOT_PASSPHRASE=" + pwd, + "NOTARY_TARGETS_PASSPHRASE=" + pwd, + "NOTARY_SNAPSHOT_PASSPHRASE=" + pwd, + "NOTARY_DELEGATION_PASSPHRASE=" + pwd, }...) } } diff --git a/e2e/plugin/trust_test.go b/e2e/plugin/trust_test.go index b89bdfb99aea..08c580a9aacd 100644 --- a/e2e/plugin/trust_test.go +++ b/e2e/plugin/trust_test.go @@ -2,7 +2,6 @@ package plugin import ( "encoding/json" - "fmt" "os" "os/exec" "path/filepath" @@ -23,7 +22,7 @@ const registryPrefix = "registry:5000" func TestInstallWithContentTrust(t *testing.T) { skip.If(t, environment.SkipPluginTests()) - pluginName := fmt.Sprintf("%s/plugin-content-trust", registryPrefix) + const pluginName = registryPrefix + "/plugin-content-trust" dir := fixtures.SetupConfigFile(t) defer dir.Remove() @@ -50,7 +49,7 @@ func TestInstallWithContentTrust(t *testing.T) { fixtures.WithNotary, ) result.Assert(t, icmd.Expected{ - Out: fmt.Sprintf("Status: Downloaded newer image for %s@sha", pluginName), + Out: "Status: Downloaded newer image for " + pluginName + "@sha", }) } diff --git a/e2e/trust/revoke_test.go b/e2e/trust/revoke_test.go index fe0f44de0424..e206329bc258 100644 --- a/e2e/trust/revoke_test.go +++ b/e2e/trust/revoke_test.go @@ -1,7 +1,6 @@ package trust import ( - "fmt" "testing" "github.com/docker/cli/e2e/internal/fixtures" @@ -57,15 +56,15 @@ func setupTrustedImagesForRevoke(t *testing.T, dir fs.Dir) { func setupTrustedImagesForRevokeRepo(t *testing.T, dir fs.Dir) { icmd.RunCmd(icmd.Command("docker", "pull", fixtures.AlpineImage)).Assert(t, icmd.Success) - icmd.RunCommand("docker", "tag", fixtures.AlpineImage, fmt.Sprintf("%s:v1", revokeRepo)).Assert(t, icmd.Success) + icmd.RunCommand("docker", "tag", fixtures.AlpineImage, revokeRepo+":v1").Assert(t, icmd.Success) icmd.RunCmd( - icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v1", revokeRepo)), + icmd.Command("docker", "-D", "trust", "sign", revokeRepo+":v1"), fixtures.WithPassphrase("root_password", "repo_password"), fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success) icmd.RunCmd(icmd.Command("docker", "pull", fixtures.BusyboxImage)).Assert(t, icmd.Success) - icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, fmt.Sprintf("%s:v2", revokeRepo)).Assert(t, icmd.Success) + icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, revokeRepo+":v2").Assert(t, icmd.Success) icmd.RunCmd( - icmd.Command("docker", "-D", "trust", "sign", fmt.Sprintf("%s:v2", revokeRepo)), + icmd.Command("docker", "-D", "trust", "sign", revokeRepo+":v2"), fixtures.WithPassphrase("root_password", "repo_password"), fixtures.WithConfig(dir.Path()), fixtures.WithNotary).Assert(t, icmd.Success) } diff --git a/e2e/trust/sign_test.go b/e2e/trust/sign_test.go index 9f953b4adb8c..c75fa3baf2b8 100644 --- a/e2e/trust/sign_test.go +++ b/e2e/trust/sign_test.go @@ -1,7 +1,6 @@ package trust import ( - "fmt" "testing" "github.com/docker/cli/e2e/internal/fixtures" @@ -30,7 +29,7 @@ func TestSignLocalImage(t *testing.T) { fixtures.WithPassphrase("root_password", "repo_password"), 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))) + assert.Check(t, is.Contains(result.Stdout(), "v1: digest: sha256:"+fixtures.AlpineSha)) } func TestSignWithLocalFlag(t *testing.T) { @@ -44,7 +43,7 @@ func TestSignWithLocalFlag(t *testing.T) { fixtures.WithPassphrase("root_password", "repo_password"), 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.BusyboxSha))) + assert.Check(t, is.Contains(result.Stdout(), "v1: digest: sha256:"+fixtures.BusyboxSha)) } func setupTrustedImageForOverwrite(t *testing.T, dir fs.Dir) { @@ -55,7 +54,7 @@ func setupTrustedImageForOverwrite(t *testing.T, dir fs.Dir) { fixtures.WithPassphrase("root_password", "repo_password"), 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))) + assert.Check(t, is.Contains(result.Stdout(), "v1: digest: sha256:"+fixtures.AlpineSha)) icmd.RunCmd(icmd.Command("docker", "pull", fixtures.BusyboxImage)).Assert(t, icmd.Success) icmd.RunCommand("docker", "tag", fixtures.BusyboxImage, localImage).Assert(t, icmd.Success) } diff --git a/opts/file.go b/opts/file.go index 72b90e117f73..5cdd8e1386d1 100644 --- a/opts/file.go +++ b/opts/file.go @@ -18,7 +18,7 @@ type ErrBadKey struct { } func (e ErrBadKey) Error() string { - return fmt.Sprintf("poorly formatted environment: %s", e.msg) + return "poorly formatted environment: " + e.msg } func parseKeyValueFile(filename string, emptyFn func(string) (string, bool)) ([]string, error) { diff --git a/opts/hosts_test.go b/opts/hosts_test.go index 9d38d164be72..8030a2e699f9 100644 --- a/opts/hosts_test.go +++ b/opts/hosts_test.go @@ -21,7 +21,7 @@ func TestParseHost(t *testing.T) { " ": defaultHost, "fd://": "fd://", "fd://something": "fd://something", - "tcp://host:": fmt.Sprintf("tcp://host:%s", defaultHTTPPort), + "tcp://host:": "tcp://host:" + defaultHTTPPort, "tcp://": defaultTCPHost, "tcp://:2375": fmt.Sprintf("tcp://%s:%s", defaultHTTPHost, defaultHTTPPort), "tcp://:2376": fmt.Sprintf("tcp://%s:%s", defaultHTTPHost, defaultTLSHTTPPort), From 5e5ccaa82997bca156000a38ff0e6c1121dec188 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 21:17:52 +0200 Subject: [PATCH 20/27] cli/command/image/build: fix nosec comment Looks like it's broken, so use a blanket "nolint:gosec" instead; cli/command/image/build/context.go:238:17: 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 df474d5176b8aa8645c76b2f1b50e969a729c1b9) Signed-off-by: Cory Snider --- cli/command/image/build/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index 7131372f5fd8..a02d23c6b7c1 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -231,7 +231,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 -- Ignore G107: Potential HTTP request made with variable url + //nolint:gosec // Ignore G107: Potential HTTP request made with variable url if resp, err = http.Get(url); err != nil { return nil, err } From 1dba0fa8ec0f5cea5fc541bb5d066f08e901db1c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 20:00:55 +0200 Subject: [PATCH 21/27] update golangci-lint to .v1.59.0 full diff: https://github.com/golangci/golangci-lint/compare/v1.55.2...v1.59.0 Updated config to address warnings: WARN [config_reader] The configuration option `run.skip-files` is deprecated, please use `issues.exclude-files`. WARN [config_reader] The configuration option `linters.govet.check-shadowing` is deprecated. Please enable `shadow` instead, if you are not using `enable-all`. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 43b97e8880385566780ecc9d86e400dba493f0b4) Signed-off-by: Cory Snider --- .golangci.yml | 13 +++++++++---- dockerfiles/Dockerfile.lint | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5553fb533792..2a0499d9681c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,9 +26,6 @@ linters: run: timeout: 5m - skip-files: - - cli/compose/schema/bindata.go - - .*generated.* linters-settings: depguard: @@ -40,7 +37,11 @@ linters-settings: gocyclo: min-complexity: 16 govet: - check-shadowing: false + enable: + - shadow + settings: + shadow: + strict: true lll: line-length: 200 nakedret: @@ -54,6 +55,10 @@ issues: exclude: - parameter .* always receives + exclude-files: + - cli/compose/schema/bindata.go + - .*generated.* + exclude-rules: # We prefer to use an "exclude-list" so that new "default" exclusions are not # automatically inherited. We can decide whether or not to follow upstream diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 108ce408abcc..d292e593f298 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -2,7 +2,7 @@ ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 -ARG GOLANGCI_LINT_VERSION=v1.55.0 +ARG GOLANGCI_LINT_VERSION=v1.59.0 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint From 72d8f66a686722d9d5d0090299973d97d1bf3754 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 24 Jun 2024 16:42:42 +0200 Subject: [PATCH 22/27] update golangci-lint to v1.59.1 full diff: https://github.com/golangci/golangci-lint/compare/v1.59.0...v1.59.1 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit b5d1b4de1a9c0462e6fcd05c05b3645e22b0ec1b) Signed-off-by: Cory Snider --- dockerfiles/Dockerfile.lint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index d292e593f298..3784b024bfd7 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -2,7 +2,7 @@ ARG GO_VERSION=1.21.13 ARG ALPINE_VERSION=3.20 -ARG GOLANGCI_LINT_VERSION=v1.59.0 +ARG GOLANGCI_LINT_VERSION=v1.59.1 FROM golangci/golangci-lint:${GOLANGCI_LINT_VERSION}-alpine AS golangci-lint From 069e27c1804a076402545e83977af5aa89cc69b7 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Wed, 4 Sep 2024 16:16:31 -0400 Subject: [PATCH 23/27] linting: format the codebase with gofumpt ...to appease the linter. Signed-off-by: Cory Snider --- cli/command/image/build/context_test.go | 1 - cli/command/plugin/create.go | 1 - 2 files changed, 2 deletions(-) diff --git a/cli/command/image/build/context_test.go b/cli/command/image/build/context_test.go index 15686e0be470..16c2f82f5e77 100644 --- a/cli/command/image/build/context_test.go +++ b/cli/command/image/build/context_test.go @@ -126,7 +126,6 @@ func TestGetContextFromReaderString(t *testing.T) { tarReader := tar.NewReader(tarArchive) _, err = tarReader.Next() - if err != nil { t.Fatalf("Error when reading tar archive: %s", err) } diff --git a/cli/command/plugin/create.go b/cli/command/plugin/create.go index bab0778cd39a..437c4736c287 100644 --- a/cli/command/plugin/create.go +++ b/cli/command/plugin/create.go @@ -114,7 +114,6 @@ func runCreate(dockerCli command.Cli, options pluginCreateOptions) error { createCtx, err = archive.TarWithOptions(absContextDir, &archive.TarOptions{ Compression: compression, }) - if err != nil { return err } From 2d468ad289826cdf46af16a59f86f04e70403e5e Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Wed, 4 Sep 2024 16:18:54 -0400 Subject: [PATCH 24/27] Linting: disable troublesome lint rules Unused named function parameters and shadowed variables are trivial code quality issues which are not worth addressing on a long-term maintenance branch without much activity aside from backports. Signed-off-by: Cory Snider --- .golangci.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2a0499d9681c..32ef636f69c1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,17 +36,16 @@ linters-settings: desc: The io/ioutil package has been deprecated, see https://go.dev/doc/go1.16#ioutil gocyclo: min-complexity: 16 - govet: - enable: - - shadow - settings: - shadow: - strict: true lll: line-length: 200 nakedret: command: nakedret pattern: ^(?P.*?\\.go):(?P\\d+)\\s*(?P.*)$ + revive: + rules: + - name: unused-parameter + severity: warning + disabled: true issues: # The default exclusion rules are a bit too permissive, so copying the relevant ones below From eb94fd0d819168d1b2312893e60a2976f255eb3f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 2 Sep 2024 15:49:35 +0200 Subject: [PATCH 25/27] update to go1.22.6 Signed-off-by: Sebastiaan van Stijn (cherry picked from commit d7d56599ca0d80f3b06b69b6a9a6e91321416775) Signed-off-by: Cory Snider --- .github/workflows/test.yml | 2 +- Dockerfile | 2 +- docker-bake.hcl | 2 +- dockerfiles/Dockerfile.dev | 2 +- dockerfiles/Dockerfile.lint | 2 +- dockerfiles/Dockerfile.vendor | 2 +- e2e/testdata/Dockerfile.gencerts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cfd7e197f351..eb9a30078d28 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,7 +63,7 @@ jobs: name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.21.13 + go-version: 1.22.6 - name: Test run: | diff --git a/Dockerfile b/Dockerfile index c365be9a755d..49b7aa1b753e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # syntax=docker/dockerfile:1 ARG BASE_VARIANT=alpine -ARG GO_VERSION=1.21.13 +ARG GO_VERSION=1.22.6 ARG ALPINE_VERSION=3.20 ARG XX_VERSION=1.1.1 ARG GOVERSIONINFO_VERSION=v1.3.0 diff --git a/docker-bake.hcl b/docker-bake.hcl index 2a3c8df015da..c1b8b741d22c 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,5 +1,5 @@ variable "GO_VERSION" { - default = "1.21.13" + default = "1.22.6" } variable "VERSION" { default = "" diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index 2e8042ff2a20..1471e3f791a3 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.13 +ARG GO_VERSION=1.22.6 ARG ALPINE_VERSION=3.20 ARG BUILDX_VERSION=0.11.2 diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 3784b024bfd7..786866ce1f51 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.13 +ARG GO_VERSION=1.22.6 ARG ALPINE_VERSION=3.20 ARG GOLANGCI_LINT_VERSION=v1.59.1 diff --git a/dockerfiles/Dockerfile.vendor b/dockerfiles/Dockerfile.vendor index 701d987334fe..b1b484507cc1 100644 --- a/dockerfiles/Dockerfile.vendor +++ b/dockerfiles/Dockerfile.vendor @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.13 +ARG GO_VERSION=1.22.6 ARG ALPINE_VERSION=3.20 ARG MODOUTDATED_VERSION=v0.8.0 diff --git a/e2e/testdata/Dockerfile.gencerts b/e2e/testdata/Dockerfile.gencerts index cd354a23ed55..f6868b299daa 100644 --- a/e2e/testdata/Dockerfile.gencerts +++ b/e2e/testdata/Dockerfile.gencerts @@ -1,6 +1,6 @@ # syntax=docker/dockerfile:1 -ARG GO_VERSION=1.21.13 +ARG GO_VERSION=1.22.6 FROM golang:${GO_VERSION}-alpine AS generated RUN go install github.com/dmcgowan/quicktls@master From 3768d285458b2f22b638a9b19b3d86e404a0f431 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 3 Sep 2024 10:49:50 +0200 Subject: [PATCH 26/27] scripts/build/plugins: don't override CGO_ENABLED set by .variables The `.variables` sets `CGO_ENABLED=1` on arm; https://github.com/docker/cli/blob/b0c41b78d8c80c5f8faa736cf3c74dc31092e443/scripts/build/.variables#L57-L68 And if enabled, it sets `-buildmode=pie`; https://github.com/docker/cli/blob/b0c41b78d8c80c5f8faa736cf3c74dc31092e443/scripts/build/.variables#L79-L88 But that looks to be conflicting with the hardcoded `CGO_ENABLED=0` in this script, which causes the build to fail on go1.22; > [build-plugins 1/1] RUN --mount=ro --mount=type=cache,target=/root/.cache xx-go --wrap && TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/*: 0.127 Building static docker-helloworld 0.127 + CGO_ENABLED=0 0.127 + GO111MODULE=auto 0.127 + go build -o /out/plugins-linux-arm/docker-helloworld -tags ' osusergo' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=5c123b1" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-02T13:52:17Z" -X "github.com/docker/cli/cli/version.Version=pr-5387" -extldflags -static' -buildmode=pie github.com/docker/cli/cli-plugins/examples/helloworld 0.135 -buildmode=pie requires external (cgo) linking, but cgo is not enabled This patch sets the CGO_ENABLED variable before sourcing `.variables`, so that other variables which are conditionally set are handled correctly. Before this PR: #18 [build-plugins 1/1] RUN --mount=ro --mount=type=cache,target=/root/.cache xx-go --wrap && TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/* #18 0.123 Building static docker-helloworld #18 0.124 + CGO_ENABLED=0 #18 0.124 + GO111MODULE=auto #18 0.124 + go build -o /out/plugins-linux-arm/docker-helloworld -tags ' osusergo' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=c8c402e" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-03T08:28:25Z" -X "github.com/docker/cli/cli/version.Version=pr-5381" -extldflags -static' -buildmode=pie github.com/docker/cli/cli-plugins/examples/helloworld .... With this PR: #18 [build-plugins 1/1] RUN --mount=ro --mount=type=cache,target=/root/.cache xx-go --wrap && TARGET=/out ./scripts/build/plugins e2e/cli-plugins/plugins/* #18 0.110 Building static docker-helloworld #18 0.110 + GO111MODULE=auto #18 0.110 + go build -o /out/plugins-linux-arm/docker-helloworld -tags '' -ldflags ' -X "github.com/docker/cli/cli/version.GitCommit=050d9d6" -X "github.com/docker/cli/cli/version.BuildTime=2024-09-03T09:19:05Z" -X "github.com/docker/cli/cli/version.Version=pr-5387"' github.com/docker/cli/cli-plugins/examples/helloworld .... Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 9e29967960d97303222e9009e0401008febdfb20) Signed-off-by: Sebastiaan van Stijn --- scripts/build/plugins | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/build/plugins b/scripts/build/plugins index fa78b9536bd1..634d3f9db740 100755 --- a/scripts/build/plugins +++ b/scripts/build/plugins @@ -5,6 +5,12 @@ set -eu -o pipefail +# Disable CGO - we don't need it for these plugins. +# +# Important: this must be done before sourcing "./scripts/build/.variables", +# because some other variables are conditionally set whether CGO is enabled. +export CGO_ENABLED=0 + source ./scripts/build/.variables for p in cli-plugins/examples/* "$@" ; do @@ -15,5 +21,5 @@ for p in cli-plugins/examples/* "$@" ; do mkdir -p "$(dirname "${TARGET_PLUGIN}")" echo "Building $GO_LINKMODE $(basename "${TARGET_PLUGIN}")" - (set -x ; CGO_ENABLED=0 GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}") + (set -x ; GO111MODULE=auto go build -o "${TARGET_PLUGIN}" -tags "${GO_BUILDTAGS}" -ldflags "${GO_LDFLAGS}" ${GO_BUILDMODE} "github.com/docker/cli/${p}") done From 6ce1dd5384e3916e93613f7728fbb97a1fd41090 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Wed, 4 Sep 2024 16:54:12 -0400 Subject: [PATCH 27/27] gha: pin codecov uploader to v0.7.3 Codecov uploader v0.8.0 for macOS is built for arm64, which fails to run on (Intel) macos-12 runners with "unknown error -86" (-EBADARCH). Signed-off-by: Cory Snider --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb9a30078d28..cc013df106eb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -77,3 +77,4 @@ jobs: with: file: /tmp/coverage.txt working-directory: ${{ env.GOPATH }}/src/github.com/docker/cli + version: v0.7.3 # Work around https://github.com/codecov/uploader/issues/1687 -- uploader v0.8.0 for mac is built for arm64, not x86_64