Skip to content

Commit

Permalink
release: implement review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chipaca committed Jul 14, 2016
1 parent 658491b commit 0538455
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
15 changes: 11 additions & 4 deletions release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ func (os *OS) ForceDevMode() bool {
case "ubuntu":
return false
case "elementary":
fallthrough
case "elementary OS":
switch os.VersionID {
case "0.4":
return false
Expand Down Expand Up @@ -94,11 +92,20 @@ func readOSRelease() OS {
}

k := strings.TrimSpace(ws[0])
v := strings.TrimFunc(ws[1], func(r rune) bool { return r == '"' || unicode.IsSpace(r) })
v := strings.TrimFunc(ws[1], func(r rune) bool { return r == '"' || r == '\'' || unicode.IsSpace(r) })
// XXX: should also unquote things as per os-release(5) but not needed yet in practice
switch k {
case "ID":
osRelease.ID = v
// ID should be “A lower-case string (no spaces or
// other characters outside of 0–9, a–z, ".", "_" and
// "-") identifying the operating system, excluding any
// version information and suitable for processing by
// scripts or usage in generated filenames.”
//
// So we mangle it a little bit to account for people
// not being too good at reading comprehension.
// Works around e.g. lp:1602317
osRelease.ID = strings.Fields(strings.ToLower(v))[0]
case "VERSION_ID":
osRelease.VersionID = v
}
Expand Down
24 changes: 22 additions & 2 deletions release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ func (s *ReleaseTestSuite) TestReadOSRelease(c *C) {
c.Check(os.VersionID, Equals, "18.09")
}

func (s *ReleaseTestSuite) TestReadWonkyOSRelease(c *C) {
mockOSRelease := filepath.Join(c.MkDir(), "mock-os-release")
dump := `NAME="elementary OS"
VERSION="0.4 Loki"
ID="elementary OS"
ID_LIKE=ubuntu
PRETTY_NAME="elementary OS Loki"
VERSION_ID="0.4"
HOME_URL="http://elementary.io/"
SUPPORT_URL="http://elementary.io/support/"
BUG_REPORT_URL="https://bugs.launchpad.net/elementary/+filebug"`
err := ioutil.WriteFile(mockOSRelease, []byte(dump), 0644)
c.Assert(err, IsNil)

reset := release.MockOSReleasePath(mockOSRelease)
defer reset()

os := release.ReadOSRelease()
c.Check(os.ID, Equals, "elementary")
c.Check(os.VersionID, Equals, "0.4")
}

func (s *ReleaseTestSuite) TestReadOSReleaseNotFound(c *C) {
reset := release.MockOSReleasePath("not-there")
defer reset()
Expand Down Expand Up @@ -111,8 +133,6 @@ func (s *ReleaseTestSuite) TestForceDevMode(c *C) {
{id: "debian", devmode: true},
{id: "elementary", devmode: true},
{id: "elementary", idVersion: "0.4", devmode: false},
{id: "elementary OS", devmode: true},
{id: "elementary OS", idVersion: "0.4", devmode: false},
{id: "fedora", devmode: true},
{id: "gentoo", devmode: true},
{id: "neon", devmode: false},
Expand Down

0 comments on commit 0538455

Please sign in to comment.