github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/juju/osenv/vars_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  	"runtime"
     9  
    10  	gc "launchpad.net/gocheck"
    11  
    12  	"github.com/juju/juju/juju/osenv"
    13  	"github.com/juju/juju/testing"
    14  )
    15  
    16  type varsSuite struct {
    17  	testing.BaseSuite
    18  }
    19  
    20  var _ = gc.Suite(&varsSuite{})
    21  
    22  func (s *varsSuite) TestJujuHomeWin(c *gc.C) {
    23  	path := `P:\FooBar\AppData`
    24  	s.PatchEnvironment("APPDATA", path)
    25  	c.Assert(osenv.JujuHomeWin(), gc.Equals, filepath.Join(path, "Juju"))
    26  }
    27  
    28  func (s *varsSuite) TestJujuHomeLinux(c *gc.C) {
    29  	path := `/foo/bar/baz/`
    30  	s.PatchEnvironment("HOME", path)
    31  	c.Assert(osenv.JujuHomeLinux(), gc.Equals, filepath.Join(path, ".juju"))
    32  }
    33  
    34  func (s *varsSuite) TestJujuHomeEnvVar(c *gc.C) {
    35  	path := "/foo/bar/baz"
    36  	s.PatchEnvironment(osenv.JujuHomeEnvKey, path)
    37  	c.Assert(osenv.JujuHomeDir(), gc.Equals, path)
    38  }
    39  
    40  func (s *varsSuite) TestBlankJujuHomeEnvVar(c *gc.C) {
    41  	s.PatchEnvironment(osenv.JujuHomeEnvKey, "")
    42  
    43  	if runtime.GOOS == "windows" {
    44  		s.PatchEnvironment("APPDATA", `P:\foobar`)
    45  	} else {
    46  		s.PatchEnvironment("HOME", "/foobar")
    47  	}
    48  	c.Assert(osenv.JujuHomeDir(), gc.Not(gc.Equals), "")
    49  
    50  	if runtime.GOOS == "windows" {
    51  		c.Assert(osenv.JujuHomeDir(), gc.Equals, osenv.JujuHomeWin())
    52  	} else {
    53  		c.Assert(osenv.JujuHomeDir(), gc.Equals, osenv.JujuHomeLinux())
    54  	}
    55  }