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
30 changes: 15 additions & 15 deletions pkg/dockerinstall/detector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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")
}

Expand All @@ -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)
}

Expand All @@ -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")
}
Expand All @@ -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")
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerinstall/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerinstall/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
Loading