github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/version/osversion_linux_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package version_test
     5  
     6  import (
     7  	"io/ioutil"
     8  	"path/filepath"
     9  
    10  	jc "github.com/juju/testing/checkers"
    11  	gc "gopkg.in/check.v1"
    12  
    13  	"github.com/juju/juju/testing"
    14  	"github.com/juju/juju/version"
    15  )
    16  
    17  type linuxVersionSuite struct {
    18  	testing.BaseSuite
    19  }
    20  
    21  var futureReleaseFileContents = `NAME="Ubuntu"
    22  VERSION="99.04 LTS, Star Trek"
    23  ID=ubuntu
    24  ID_LIKE=debian
    25  PRETTY_NAME="Ubuntu spock (99.04 LTS)"
    26  VERSION_ID="99.04"
    27  `
    28  
    29  var distroInfoContents = `version,codename,series,created,release,eol,eol-server
    30  12.04 LTS,Precise Pangolin,precise,2011-10-13,2012-04-26,2017-04-26
    31  99.04,Star Trek,spock,2364-04-25,2364-10-17,2365-07-17
    32  `
    33  
    34  var _ = gc.Suite(&linuxVersionSuite{})
    35  
    36  func (s *linuxVersionSuite) SetUpTest(c *gc.C) {
    37  	cleanup := version.SetSeriesVersions(make(map[string]string))
    38  	s.AddCleanup(func(*gc.C) { cleanup() })
    39  }
    40  
    41  func (s *linuxVersionSuite) TestOSVersion(c *gc.C) {
    42  	// Set up fake /etc/os-release file from the future.
    43  	d := c.MkDir()
    44  	release := filepath.Join(d, "future-release")
    45  	s.PatchValue(version.OSReleaseFile, release)
    46  	err := ioutil.WriteFile(release, []byte(futureReleaseFileContents), 0666)
    47  	c.Assert(err, jc.ErrorIsNil)
    48  
    49  	// Set up fake /usr/share/distro-info/ubuntu.csv, also from the future.
    50  	distroInfo := filepath.Join(d, "ubuntu.csv")
    51  	err = ioutil.WriteFile(distroInfo, []byte(distroInfoContents), 0644)
    52  	c.Assert(err, jc.ErrorIsNil)
    53  	s.PatchValue(version.DistroInfo, distroInfo)
    54  
    55  	// Ensure the future series can be read even though Juju doesn't
    56  	// know about it.
    57  	version, err := version.ReadSeries()
    58  	c.Assert(err, jc.ErrorIsNil)
    59  	c.Assert(version, gc.Equals, "spock")
    60  }