github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/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  	gc "launchpad.net/gocheck"
    10  
    11  	"github.com/juju/juju/juju/osenv"
    12  )
    13  
    14  type JujuHomeSuite struct {
    15  	jujuHome string
    16  }
    17  
    18  var _ = gc.Suite(&JujuHomeSuite{})
    19  
    20  func (s *JujuHomeSuite) TestStandardHome(c *gc.C) {
    21  	testJujuHome := c.MkDir()
    22  	defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
    23  	c.Assert(osenv.JujuHome(), gc.Equals, testJujuHome)
    24  }
    25  
    26  func (s *JujuHomeSuite) TestErrorHome(c *gc.C) {
    27  	// Invalid juju home leads to panic when retrieving.
    28  	f := func() { _ = osenv.JujuHome() }
    29  	c.Assert(f, gc.PanicMatches, "juju home hasn't been initialized")
    30  	f = func() { _ = osenv.JujuHomePath("environments.yaml") }
    31  	c.Assert(f, gc.PanicMatches, "juju home hasn't been initialized")
    32  }
    33  
    34  func (s *JujuHomeSuite) TestHomePath(c *gc.C) {
    35  	testJujuHome := c.MkDir()
    36  	defer osenv.SetJujuHome(osenv.SetJujuHome(testJujuHome))
    37  	envPath := osenv.JujuHomePath("environments.yaml")
    38  	c.Assert(envPath, gc.Equals, filepath.Join(testJujuHome, "environments.yaml"))
    39  }