From c6202a0261051cdbc604573441e40b2dd2767525 Mon Sep 17 00:00:00 2001 From: "devsy-app[bot]" <277138668+devsy-app[bot]@users.noreply.github.com> Date: Sun, 16 Aug 2026 11:02:34 +0000 Subject: [PATCH 1/3] test: cover dockerinstall packages Add packages_test.go covering the previously-untested BuildPackageList and versionGte in pkg/dockerinstall. Pure test-only addition: verifies version-gated package selection (cli/containerd 18.09+, compose 20.10+, buildx 23.0+), extra-package appending, the empty-version fallback, and pre-release suffix comparison. No behavioral change. --- pkg/dockerinstall/packages_test.go | 131 +++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 pkg/dockerinstall/packages_test.go diff --git a/pkg/dockerinstall/packages_test.go b/pkg/dockerinstall/packages_test.go new file mode 100644 index 000000000..138017795 --- /dev/null +++ b/pkg/dockerinstall/packages_test.go @@ -0,0 +1,131 @@ +package dockerinstall + +import ( + "strings" + "testing" + + "github.com/stretchr/testify/suite" +) + +type PackagesTestSuite struct { + suite.Suite +} + +func TestPackagesSuite(t *testing.T) { + suite.Run(t, new(PackagesTestSuite)) +} + +func (s *PackagesTestSuite) TestBuildPackageList_PreCLI() { + version := "17.09" + got := BuildPackageList(version, "=1:17.09.0", "", "docker-ce-rootless-extras") + + pkgs := strings.Split(got, " ") + s.Equal([]string{PkgDockerCE + "=1:17.09.0", "docker-ce-rootless-extras"}, pkgs) + s.NotContains(got, PkgDockerCECLI) + s.NotContains(got, PkgContainerd) + s.NotContains(got, PkgDockerCompose) + s.NotContains(got, PkgDockerBuildx) +} + +func (s *PackagesTestSuite) TestBuildPackageList_CLIWithPinnedCLI() { + version := "18.09" + got := BuildPackageList(version, "=1:18.09.0", "=1:18.09.0-3") + + pkgs := strings.Split(got, " ") + s.Equal( + []string{ + PkgDockerCE + "=1:18.09.0", + PkgDockerCECLI + "=1:18.09.0-3", + PkgContainerd, + }, + pkgs, + ) + s.NotContains(got, PkgDockerCompose) + s.NotContains(got, PkgDockerBuildx) +} + +func (s *PackagesTestSuite) TestBuildPackageList_CLIWithoutPinnedCLI() { + version := "18.09" + got := BuildPackageList(version, "=1:18.09.0", "") + + pkgs := strings.Split(got, " ") + s.Equal( + []string{PkgDockerCE + "=1:18.09.0", PkgDockerCECLI, PkgContainerd}, + pkgs, + ) +} + +func (s *PackagesTestSuite) TestBuildPackageList_ComposeAt2010() { + version := "20.10" + got := BuildPackageList(version, "=5:20.10.0", "=5:20.10.0") + + s.Contains(got, PkgDockerCompose) + s.NotContains(got, PkgDockerBuildx) +} + +func (s *PackagesTestSuite) TestBuildPackageList_BuildxAt230() { + version := "23.0" + got := BuildPackageList(version, "=5:23.0.0", "=5:23.0.0") + + pkgs := strings.Split(got, " ") + s.Equal( + []string{ + PkgDockerCE + "=5:23.0.0", + PkgDockerCECLI + "=5:23.0.0", + PkgContainerd, + PkgDockerCompose, + PkgDockerBuildx, + }, + pkgs, + ) +} + +func (s *PackagesTestSuite) TestBuildPackageList_EmptyVersionEnablesAllFeatures() { + got := BuildPackageList("", "", "") + + pkgs := strings.Split(got, " ") + s.Equal( + []string{ + PkgDockerCE, + PkgDockerCECLI, + PkgContainerd, + PkgDockerCompose, + PkgDockerBuildx, + }, + pkgs, + ) +} + +func (s *PackagesTestSuite) TestBuildPackageList_ExtraPackagesAppended() { + got := BuildPackageList("23.0", "", "", PkgDockerRootlessExtras, PkgDockerScan) + + s.True(strings.HasSuffix(got, PkgDockerRootlessExtras+" "+PkgDockerScan)) + s.Contains(got, PkgDockerBuildx) +} + +func (s *PackagesTestSuite) TestVersionGte_Table() { + tests := []struct { + version string + target string + want bool + }{ + {"", "18.09", true}, + {"18.09", "18.09", true}, + {"20.10", "18.09", true}, + {"18.08", "18.09", false}, + {"17.09", "18.09", false}, + {"22.04", "23.0", false}, + {"24.0", "23.0", true}, + {"23", "23.0", true}, + {"23.0", "23.0", true}, + {"20.10-ce", "20.10", true}, + {"18.09-0~debian", "18.09", true}, + {"abc.0", "18.09", false}, + {"1.2.3", "1.2", true}, + } + + for _, tt := range tests { + got := versionGte(tt.version, tt.target) + s.Equal(tt.want, got, "versionGte(%q, %q)", tt.version, tt.target) + } +} From 87792fbbeb1e80fef62d0c80473aff97202dd052 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Mon, 17 Aug 2026 05:29:08 +0000 Subject: [PATCH 2/3] fix: linting error by updating constants Signed-off-by: Samuel K --- pkg/dockerinstall/constants.go | 6 +++++ pkg/dockerinstall/debian.go | 2 +- pkg/dockerinstall/detector_test.go | 6 ++--- pkg/dockerinstall/install.go | 2 +- pkg/dockerinstall/packages.go | 6 ++--- pkg/dockerinstall/packages_test.go | 34 ++++++++++++++--------------- pkg/dockerinstall/validator_test.go | 4 ++-- 7 files changed, 33 insertions(+), 27 deletions(-) diff --git a/pkg/dockerinstall/constants.go b/pkg/dockerinstall/constants.go index 5c5462d0a..1b2c724b2 100644 --- a/pkg/dockerinstall/constants.go +++ b/pkg/dockerinstall/constants.go @@ -53,4 +53,10 @@ const ( CodenameBuster = "buster" CodenameStretch = "stretch" CodenameJessie = "jessie" + + // Ubuntu release. + ubuntuRelease1809 = "18.09" + ubuntuRelease2010 = "20.10" + ubuntuRelease2204 = "22.04" + ubuntuRelease230 = "23.0" ) diff --git a/pkg/dockerinstall/debian.go b/pkg/dockerinstall/debian.go index 7a10829bf..60ac4a490 100644 --- a/pkg/dockerinstall/debian.go +++ b/pkg/dockerinstall/debian.go @@ -94,7 +94,7 @@ func (i *DebianInstaller) findVersions() (string, string, error) { } cliPkgVersion := "" - if versionGte(i.opts.version, "18.09") { + if versionGte(i.opts.version, ubuntuRelease1809) { cliPkgVersion, err = i.findPackageVersion("docker-ce-cli") if err != nil { return "", "", err diff --git a/pkg/dockerinstall/detector_test.go b/pkg/dockerinstall/detector_test.go index 1f9fe50b6..df138a014 100644 --- a/pkg/dockerinstall/detector_test.go +++ b/pkg/dockerinstall/detector_test.go @@ -42,7 +42,7 @@ VERSION_ID="22.04"` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) s.Equal(DistroUbuntu, distro.ID) - s.Equal("22.04", distro.Version, "Should fall back to VERSION_ID when codename missing") + s.Equal(ubuntuRelease2204, distro.Version, "Should fall back to VERSION_ID when codename missing") } func (s *DetectorTestSuite) TestParseOSRelease_Debian_WithCodename() { @@ -156,7 +156,7 @@ func (s *DetectorTestSuite) TestIsNumericVersion() { version string expected bool }{ - {"22.04", true}, + {ubuntuRelease2204, true}, {"11", true}, {"12.5", true}, {"jammy", false}, @@ -187,7 +187,7 @@ func (s *DetectorTestSuite) TestDistro_HasCodename() { }{ {&Distro{ID: DistroUbuntu, Version: "jammy"}, true}, {&Distro{ID: DistroDebian, Version: CodenameBookworm}, true}, - {&Distro{ID: DistroUbuntu, Version: "22.04"}, false}, + {&Distro{ID: DistroUbuntu, Version: ubuntuRelease2204}, false}, {&Distro{ID: DistroDebian, Version: "12"}, false}, {&Distro{ID: "fedora", Version: "39"}, false}, {&Distro{ID: DistroUbuntu, Version: ""}, false}, diff --git a/pkg/dockerinstall/install.go b/pkg/dockerinstall/install.go index bde2b8614..601464a35 100644 --- a/pkg/dockerinstall/install.go +++ b/pkg/dockerinstall/install.go @@ -141,7 +141,7 @@ func echoDockerAsNonroot(opts *InstallOptions) { fprintln(opts.stdout, ` ================================================================================`) - if versionGte(opts.version, "20.10") { + if versionGte(opts.version, ubuntuRelease2010) { fprintln(opts.stdout, ` To run Docker as a non-privileged user, consider setting up the Docker daemon in rootless mode for your user: diff --git a/pkg/dockerinstall/packages.go b/pkg/dockerinstall/packages.go index 1cd55b7a0..8754d46ac 100644 --- a/pkg/dockerinstall/packages.go +++ b/pkg/dockerinstall/packages.go @@ -12,7 +12,7 @@ func BuildPackageList(version, pkgVersion, cliPkgVersion string, extraPkgs ...st pkgs = append(pkgs, PkgDockerCE+pkgVersion) // CLI and containerd (18.09+) - if versionGte(version, "18.09") { + if versionGte(version, ubuntuRelease1809) { if cliPkgVersion != "" { pkgs = append(pkgs, PkgDockerCECLI+cliPkgVersion, PkgContainerd) } else { @@ -21,12 +21,12 @@ func BuildPackageList(version, pkgVersion, cliPkgVersion string, extraPkgs ...st } // Compose plugin (20.10+) - if versionGte(version, "20.10") { + if versionGte(version, ubuntuRelease2010) { pkgs = append(pkgs, PkgDockerCompose) } // Buildx plugin (23.0+) - if versionGte(version, "23.0") { + if versionGte(version, ubuntuRelease230) { pkgs = append(pkgs, PkgDockerBuildx) } diff --git a/pkg/dockerinstall/packages_test.go b/pkg/dockerinstall/packages_test.go index 138017795..be5c17e84 100644 --- a/pkg/dockerinstall/packages_test.go +++ b/pkg/dockerinstall/packages_test.go @@ -28,7 +28,7 @@ func (s *PackagesTestSuite) TestBuildPackageList_PreCLI() { } func (s *PackagesTestSuite) TestBuildPackageList_CLIWithPinnedCLI() { - version := "18.09" + version := ubuntuRelease1809 got := BuildPackageList(version, "=1:18.09.0", "=1:18.09.0-3") pkgs := strings.Split(got, " ") @@ -45,7 +45,7 @@ func (s *PackagesTestSuite) TestBuildPackageList_CLIWithPinnedCLI() { } func (s *PackagesTestSuite) TestBuildPackageList_CLIWithoutPinnedCLI() { - version := "18.09" + version := ubuntuRelease1809 got := BuildPackageList(version, "=1:18.09.0", "") pkgs := strings.Split(got, " ") @@ -56,7 +56,7 @@ func (s *PackagesTestSuite) TestBuildPackageList_CLIWithoutPinnedCLI() { } func (s *PackagesTestSuite) TestBuildPackageList_ComposeAt2010() { - version := "20.10" + version := ubuntuRelease2010 got := BuildPackageList(version, "=5:20.10.0", "=5:20.10.0") s.Contains(got, PkgDockerCompose) @@ -64,7 +64,7 @@ func (s *PackagesTestSuite) TestBuildPackageList_ComposeAt2010() { } func (s *PackagesTestSuite) TestBuildPackageList_BuildxAt230() { - version := "23.0" + version := ubuntuRelease230 got := BuildPackageList(version, "=5:23.0.0", "=5:23.0.0") pkgs := strings.Split(got, " ") @@ -97,7 +97,7 @@ func (s *PackagesTestSuite) TestBuildPackageList_EmptyVersionEnablesAllFeatures( } func (s *PackagesTestSuite) TestBuildPackageList_ExtraPackagesAppended() { - got := BuildPackageList("23.0", "", "", PkgDockerRootlessExtras, PkgDockerScan) + got := BuildPackageList(ubuntuRelease230, "", "", PkgDockerRootlessExtras, PkgDockerScan) s.True(strings.HasSuffix(got, PkgDockerRootlessExtras+" "+PkgDockerScan)) s.Contains(got, PkgDockerBuildx) @@ -109,18 +109,18 @@ func (s *PackagesTestSuite) TestVersionGte_Table() { target string want bool }{ - {"", "18.09", true}, - {"18.09", "18.09", true}, - {"20.10", "18.09", true}, - {"18.08", "18.09", false}, - {"17.09", "18.09", false}, - {"22.04", "23.0", false}, - {"24.0", "23.0", true}, - {"23", "23.0", true}, - {"23.0", "23.0", true}, - {"20.10-ce", "20.10", true}, - {"18.09-0~debian", "18.09", true}, - {"abc.0", "18.09", false}, + {"", ubuntuRelease1809, true}, + {ubuntuRelease1809, ubuntuRelease1809, true}, + {ubuntuRelease2010, ubuntuRelease1809, true}, + {"18.08", ubuntuRelease1809, false}, + {"17.09", ubuntuRelease1809, false}, + {ubuntuRelease2204, ubuntuRelease230, false}, + {"24.0", ubuntuRelease230, true}, + {"23", ubuntuRelease230, true}, + {ubuntuRelease230, ubuntuRelease230, true}, + {"20.10-ce", ubuntuRelease2010, true}, + {"18.09-0~debian", ubuntuRelease1809, true}, + {"abc.0", ubuntuRelease1809, false}, {"1.2.3", "1.2", true}, } diff --git a/pkg/dockerinstall/validator_test.go b/pkg/dockerinstall/validator_test.go index 724470f6c..9e6d41035 100644 --- a/pkg/dockerinstall/validator_test.go +++ b/pkg/dockerinstall/validator_test.go @@ -66,7 +66,7 @@ func (s *ValidatorTestSuite) TestCheckWSL_IsWSL_DryRun() { func (s *ValidatorTestSuite) TestCheckDeprecation_NotDeprecated() { validator := NewValidator(s.opts) - distro := &Distro{ID: "ubuntu", Version: "22.04"} + distro := &Distro{ID: "ubuntu", Version: ubuntuRelease2204} validator.CheckDeprecation(distro) s.Empty(s.stdout.String()) } @@ -106,7 +106,7 @@ func (s *ValidatorTestSuite) TestCheckDeprecation_CurrentFedora() { func (s *ValidatorTestSuite) TestValidateDistro_EmptyID() { validator := NewValidator(s.opts) - distro := &Distro{ID: "", Version: "22.04"} + distro := &Distro{ID: "", Version: ubuntuRelease2204} err := validator.ValidateDistro(distro) s.Error(err) s.Contains(s.stderr.String(), "Unable to detect distribution") From 0183bce7f30eb582addebf01ac2dd444d09b8976 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Mon, 17 Aug 2026 05:35:52 +0000 Subject: [PATCH 3/3] fix: linting errors Signed-off-by: Samuel K --- pkg/dockerinstall/constants.go | 4 ++++ pkg/dockerinstall/detector_test.go | 6 +++++- pkg/dockerinstall/validator_test.go | 20 ++++++++++++++------ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pkg/dockerinstall/constants.go b/pkg/dockerinstall/constants.go index 1b2c724b2..bcf5f8140 100644 --- a/pkg/dockerinstall/constants.go +++ b/pkg/dockerinstall/constants.go @@ -45,6 +45,10 @@ const ( DistroRaspbian = "raspbian" DistroOSMC = "osmc" DistroDebian = "debian" + DistroCentOS = "centos" + DistroFedora = "fedora" + DistroRHEL = "rhel" + DistroSLES = "sles" // Debian release codenames. CodenameTrixie = "trixie" diff --git a/pkg/dockerinstall/detector_test.go b/pkg/dockerinstall/detector_test.go index df138a014..e80735c6a 100644 --- a/pkg/dockerinstall/detector_test.go +++ b/pkg/dockerinstall/detector_test.go @@ -42,7 +42,11 @@ VERSION_ID="22.04"` distro := s.detector.parseOSRelease(strings.NewReader(osRelease)) s.Equal(DistroUbuntu, distro.ID) - s.Equal(ubuntuRelease2204, distro.Version, "Should fall back to VERSION_ID when codename missing") + s.Equal( + ubuntuRelease2204, + distro.Version, + "Should fall back to VERSION_ID when codename missing", + ) } func (s *DetectorTestSuite) TestParseOSRelease_Debian_WithCodename() { diff --git a/pkg/dockerinstall/validator_test.go b/pkg/dockerinstall/validator_test.go index 9e6d41035..0297ca5d3 100644 --- a/pkg/dockerinstall/validator_test.go +++ b/pkg/dockerinstall/validator_test.go @@ -66,7 +66,7 @@ func (s *ValidatorTestSuite) TestCheckWSL_IsWSL_DryRun() { func (s *ValidatorTestSuite) TestCheckDeprecation_NotDeprecated() { validator := NewValidator(s.opts) - distro := &Distro{ID: "ubuntu", Version: ubuntuRelease2204} + distro := &Distro{ID: DistroUbuntu, Version: ubuntuRelease2204} validator.CheckDeprecation(distro) s.Empty(s.stdout.String()) } @@ -74,7 +74,7 @@ func (s *ValidatorTestSuite) TestCheckDeprecation_NotDeprecated() { func (s *ValidatorTestSuite) TestCheckDeprecation_DeprecatedUbuntu_DryRun() { s.opts.dryRun = true validator := NewValidator(s.opts) - distro := &Distro{ID: "ubuntu", Version: "xenial"} + distro := &Distro{ID: DistroUbuntu, Version: "xenial"} validator.CheckDeprecation(distro) s.Contains(s.stdout.String(), "DEPRECATION WARNING") s.Contains(s.stdout.String(), "ubuntu xenial") @@ -83,7 +83,7 @@ func (s *ValidatorTestSuite) TestCheckDeprecation_DeprecatedUbuntu_DryRun() { func (s *ValidatorTestSuite) TestCheckDeprecation_DeprecatedDebian() { s.opts.dryRun = true validator := NewValidator(s.opts) - distro := &Distro{ID: "debian", Version: CodenameStretch} + distro := &Distro{ID: DistroDebian, Version: CodenameStretch} validator.CheckDeprecation(distro) s.Contains(s.stdout.String(), "DEPRECATION WARNING") s.Contains(s.stdout.String(), "debian stretch") @@ -92,14 +92,14 @@ func (s *ValidatorTestSuite) TestCheckDeprecation_DeprecatedDebian() { func (s *ValidatorTestSuite) TestCheckDeprecation_DeprecatedFedora() { s.opts.dryRun = true validator := NewValidator(s.opts) - distro := &Distro{ID: "fedora", Version: "32"} + distro := &Distro{ID: DistroFedora, Version: "32"} validator.CheckDeprecation(distro) s.Contains(s.stdout.String(), "DEPRECATION WARNING") } func (s *ValidatorTestSuite) TestCheckDeprecation_CurrentFedora() { validator := NewValidator(s.opts) - distro := &Distro{ID: "fedora", Version: "39"} + distro := &Distro{ID: DistroFedora, Version: "39"} validator.CheckDeprecation(distro) s.Empty(s.stdout.String()) } @@ -113,7 +113,15 @@ func (s *ValidatorTestSuite) TestValidateDistro_EmptyID() { } func (s *ValidatorTestSuite) TestValidateDistro_Supported() { - supported := []string{"ubuntu", "debian", "raspbian", "centos", "fedora", "rhel", "sles"} + supported := []string{ + DistroUbuntu, + DistroDebian, + DistroRaspbian, + DistroCentOS, + DistroFedora, + DistroRHEL, + DistroSLES, + } for _, id := range supported { s.SetupTest() validator := NewValidator(s.opts)