github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/version/current_test.go (about)

     1  // Copyright 2012, 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package version_test
     5  
     6  import (
     7  	"os/exec"
     8  	"runtime"
     9  
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/version"
    13  )
    14  
    15  type CurrentSuite struct{}
    16  
    17  var _ = gc.Suite(&CurrentSuite{})
    18  
    19  func (*CurrentSuite) TestCurrentSeries(c *gc.C) {
    20  	s := version.Current.Series
    21  	if s == "unknown" {
    22  		s = "n/a"
    23  	}
    24  	out, err := exec.Command("lsb_release", "-c").CombinedOutput()
    25  	if err != nil {
    26  		// If the command fails (for instance if we're running on some other
    27  		// platform) then CurrentSeries should be unknown.
    28  		switch runtime.GOOS {
    29  		case "darwin":
    30  			c.Check(s, gc.Matches, `mavericks|mountainlion|lion|snowleopard`)
    31  		case "windows":
    32  			c.Check(s, gc.Matches, `win2012hvr2|win2012hv|win2012|win2012r2|win8|win81|win7`)
    33  		default:
    34  			c.Assert(s, gc.Equals, "n/a")
    35  		}
    36  	} else {
    37  		os, err := version.GetOSFromSeries(s)
    38  		c.Assert(err, gc.IsNil)
    39  		// There is no lsb_release command on CentOS.
    40  		switch os {
    41  		case version.CentOS:
    42  			c.Check(s, gc.Matches, `centos7`)
    43  		default:
    44  			c.Assert(string(out), gc.Equals, "Codename:\t"+s+"\n")
    45  		}
    46  	}
    47  }