Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/dockerinstall/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const (
DistroRaspbian = "raspbian"
DistroOSMC = "osmc"
DistroDebian = "debian"
DistroCentOS = "centos"
DistroFedora = "fedora"
DistroRHEL = "rhel"
DistroSLES = "sles"

// Debian release codenames.
CodenameTrixie = "trixie"
Expand All @@ -53,4 +57,10 @@ const (
CodenameBuster = "buster"
CodenameStretch = "stretch"
CodenameJessie = "jessie"

// Ubuntu release.
ubuntuRelease1809 = "18.09"
ubuntuRelease2010 = "20.10"
ubuntuRelease2204 = "22.04"
ubuntuRelease230 = "23.0"
)
2 changes: 1 addition & 1 deletion pkg/dockerinstall/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions pkg/dockerinstall/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ 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() {
Expand Down Expand Up @@ -156,7 +160,7 @@ func (s *DetectorTestSuite) TestIsNumericVersion() {
version string
expected bool
}{
{"22.04", true},
{ubuntuRelease2204, true},
{"11", true},
{"12.5", true},
{"jammy", false},
Expand Down Expand Up @@ -187,7 +191,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},
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerinstall/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions pkg/dockerinstall/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down
131 changes: 131 additions & 0 deletions pkg/dockerinstall/packages_test.go
Original file line number Diff line number Diff line change
@@ -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 := ubuntuRelease1809
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 := ubuntuRelease1809
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 := ubuntuRelease2010
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 := ubuntuRelease230
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(ubuntuRelease230, "", "", 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
}{
{"", 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},
}

for _, tt := range tests {
got := versionGte(tt.version, tt.target)
s.Equal(tt.want, got, "versionGte(%q, %q)", tt.version, tt.target)
}
}
22 changes: 15 additions & 7 deletions pkg/dockerinstall/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ 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: DistroUbuntu, Version: ubuntuRelease2204}
validator.CheckDeprecation(distro)
s.Empty(s.stdout.String())
}

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")
Expand All @@ -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")
Expand All @@ -92,28 +92,36 @@ 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())
}

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")
}

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)
Expand Down
Loading