From 1844b1eba9dbbc51c525b8a4a312309c57446ebb Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:11:29 +0000 Subject: [PATCH] style: use distro constants in dockerinstall MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Replaces repeated `"ubuntu"`, `"debian"`, and `"raspbian"` string literals in `pkg/dockerinstall` with the existing named constants `DistroUbuntu`, `DistroDebian`, and `DistroRaspbian`, resolving the `goconst` "but such constant already exists" findings. ## Linter + category - **Linter:** `golangci-lint` → `goconst` - **Category:** "but such constant already exists" findings (string literals duplicated where an exported constant with the same value is already defined) ## Findings fixed Resolved 3 `goconst` "already exists" package-level findings, across 21 literal replacements (no behavioral change — each literal is replaced with the constant of identical value): - `"ubuntu"` (8 occurrences) → `DistroUbuntu` - `"debian"` (6 occurrences) → `DistroDebian` - `"raspbian"` (3 occurrences) → `DistroRaspbian` Files touched (single package, `pkg/dockerinstall`): - `pkg/dockerinstall/install.go` — `switch` case list - `pkg/dockerinstall/validator.go` — supported-distro map keys - `pkg/dockerinstall/detector_test.go` — `s.Equal` assertions + `Distro` table literals The remaining occurrences in `validator_test.go` were intentionally left as literals so the change stays minimal and does not surface adjacent pre-existing `goconst` ("make it a constant") findings for `22.04`/`stretch` as new. After this change each of the three strings appears fewer than 3 times as a literal, so the "already exists" findings no longer fire. ## Fix method Mechanical — literal-for-named-constant substitution. The constants already exist in `pkg/dockerinstall/constants.go`; no new constants, no logic changes. Raw-string `/etc/os-release` test fixtures (which simulate file content, not Go literals) were deliberately left untouched. ## Verification - `task cli:format` — clean - `task cli:lint:ci` — **0 new issues** (`--new-from-patch` against `origin/main`) - `go test ./pkg/dockerinstall/...` — `ok` (passes) - `task cli:test` — all packages pass except the known pre-existing `pkg/git` `TestRepoClone*` failures (a stale assertion on `origin/main`, unrelated to this change — verified failing on a clean checkout of `main`) This PR was created by an AI agent as part of an automated daily lint fix job. --- pkg/dockerinstall/detector_test.go | 30 +++++++++++++++--------------- pkg/dockerinstall/install.go | 2 +- pkg/dockerinstall/validator.go | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/dockerinstall/detector_test.go b/pkg/dockerinstall/detector_test.go index 3ec6337f95..395629b2e5 100644 --- a/pkg/dockerinstall/detector_test.go +++ b/pkg/dockerinstall/detector_test.go @@ -29,7 +29,7 @@ VERSION_ID="22.04" VERSION_CODENAME=jammy` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("ubuntu", distro.ID) + s.Equal(DistroUbuntu, distro.ID) s.Equal("jammy", distro.Version) } @@ -41,7 +41,7 @@ ID_LIKE=debian VERSION_ID="22.04"` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("ubuntu", distro.ID) + s.Equal(DistroUbuntu, distro.ID) s.Equal("22.04", distro.Version, "Should fall back to VERSION_ID when codename missing") } @@ -53,7 +53,7 @@ VERSION_ID="12" VERSION_CODENAME=bookworm` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("debian", distro.ID) + s.Equal(DistroDebian, distro.ID) s.Equal("bookworm", distro.Version) } @@ -71,7 +71,7 @@ SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("debian", distro.ID) + s.Equal(DistroDebian, distro.ID) s.Equal("trixie", distro.Version, "Should extract VERSION_CODENAME, not VERSION_ID") s.False(isNumericVersion(distro.Version), "Version should be codename, not numeric") } @@ -83,7 +83,7 @@ ID=debian VERSION_ID="12"` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("debian", distro.ID) + s.Equal(DistroDebian, distro.ID) s.Equal("12", distro.Version, "Should fall back to VERSION_ID") } @@ -103,7 +103,7 @@ func (s *DetectorTestSuite) TestParseOSRelease_QuotedValues() { VERSION_CODENAME="jammy"` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("ubuntu", distro.ID) + s.Equal(DistroUbuntu, distro.ID) s.Equal("jammy", distro.Version) } @@ -112,7 +112,7 @@ func (s *DetectorTestSuite) TestParseOSRelease_UnquotedValues() { VERSION_CODENAME=jammy` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) - s.Equal("ubuntu", distro.ID) + s.Equal(DistroUbuntu, distro.ID) s.Equal("jammy", distro.Version) } @@ -146,9 +146,9 @@ func (s *DetectorTestSuite) TestMapDebianVersion() { } func (s *DetectorTestSuite) TestMapDebianID() { - s.Equal("raspbian", s.detector.mapDebianID("osmc")) - s.Equal("debian", s.detector.mapDebianID("linuxmint")) - s.Equal("debian", s.detector.mapDebianID("unknown")) + s.Equal(DistroRaspbian, s.detector.mapDebianID("osmc")) + s.Equal(DistroDebian, s.detector.mapDebianID("linuxmint")) + s.Equal(DistroDebian, s.detector.mapDebianID("unknown")) } func (s *DetectorTestSuite) TestIsNumericVersion() { @@ -185,12 +185,12 @@ func (s *DetectorTestSuite) TestDistro_HasCodename() { distro *Distro expected bool }{ - {&Distro{ID: "ubuntu", Version: "jammy"}, true}, - {&Distro{ID: "debian", Version: "bookworm"}, true}, - {&Distro{ID: "ubuntu", Version: "22.04"}, false}, - {&Distro{ID: "debian", Version: "12"}, false}, + {&Distro{ID: DistroUbuntu, Version: "jammy"}, true}, + {&Distro{ID: DistroDebian, Version: "bookworm"}, true}, + {&Distro{ID: DistroUbuntu, Version: "22.04"}, false}, + {&Distro{ID: DistroDebian, Version: "12"}, false}, {&Distro{ID: "fedora", Version: "39"}, false}, - {&Distro{ID: "ubuntu", Version: ""}, false}, + {&Distro{ID: DistroUbuntu, Version: ""}, false}, } for _, tt := range tests { diff --git a/pkg/dockerinstall/install.go b/pkg/dockerinstall/install.go index 1a145a9613..bde2b8614f 100644 --- a/pkg/dockerinstall/install.go +++ b/pkg/dockerinstall/install.go @@ -58,7 +58,7 @@ func Install(stdout, stderr io.Writer) (string, error) { func createInstaller(distro *Distro, opts *InstallOptions) Installer { switch distro.ID { - case "ubuntu", "debian", "raspbian": + case DistroUbuntu, DistroDebian, DistroRaspbian: return NewDebianInstaller(distro, opts) default: return nil diff --git a/pkg/dockerinstall/validator.go b/pkg/dockerinstall/validator.go index 9497ea7ba8..e21396e085 100644 --- a/pkg/dockerinstall/validator.go +++ b/pkg/dockerinstall/validator.go @@ -103,7 +103,7 @@ ERROR: Unable to detect distribution`) } supported := map[string]bool{ - "ubuntu": true, "debian": true, "raspbian": true, + DistroUbuntu: true, DistroDebian: true, DistroRaspbian: true, "centos": true, "fedora": true, "rhel": true, "sles": true, }