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

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package osenv_test
     5  
     6  import (
     7  	"path/filepath"
     8  
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/juju/osenv"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type JujuHomeSuite struct {
    17  	testing.BaseSuite
    18  }
    19  
    20  var _ = gc.Suite(&JujuHomeSuite{})
    21  
    22  func (s *JujuHomeSuite) TestStandardHome(c *gc.C) {
    23  	testJujuHome := c.MkDir()
    24  	osenv.SetJujuHome(testJujuHome)
    25  	c.Assert(osenv.JujuHome(), gc.Equals, testJujuHome)
    26  }
    27  
    28  func (s *JujuHomeSuite) TestErrorHome(c *gc.C) {
    29  	// Invalid juju home leads to panic when retrieving.
    30  	f := func() { _ = osenv.JujuHome() }
    31  	c.Assert(f, gc.PanicMatches, "juju home hasn't been initialized")
    32  	f = func() { _ = osenv.JujuHomePath("environments.yaml") }
    33  	c.Assert(f, gc.PanicMatches, "juju home hasn't been initialized")
    34  }
    35  
    36  func (s *JujuHomeSuite) TestHomePath(c *gc.C) {
    37  	testJujuHome := c.MkDir()
    38  	osenv.SetJujuHome(testJujuHome)
    39  	envPath := osenv.JujuHomePath("environments.yaml")
    40  	c.Assert(envPath, gc.Equals, filepath.Join(testJujuHome, "environments.yaml"))
    41  }
    42  
    43  func (s *JujuHomeSuite) TestIsHomeSet(c *gc.C) {
    44  	c.Assert(osenv.IsJujuHomeSet(), jc.IsFalse)
    45  	osenv.SetJujuHome(c.MkDir())
    46  	c.Assert(osenv.IsJujuHomeSet(), jc.IsTrue)
    47  }