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