github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/testing/environ_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing_test 5 6 import ( 7 "os" 8 "path/filepath" 9 10 gitjujutesting "github.com/juju/testing" 11 jc "github.com/juju/testing/checkers" 12 "github.com/juju/utils" 13 gc "launchpad.net/gocheck" 14 15 "github.com/juju/juju/juju/osenv" 16 "github.com/juju/juju/testing" 17 ) 18 19 type fakeHomeSuite struct { 20 testing.FakeJujuHomeSuite 21 } 22 23 var _ = gc.Suite(&fakeHomeSuite{}) 24 25 func (s *fakeHomeSuite) SetUpTest(c *gc.C) { 26 utils.SetHome("/home/eric") 27 os.Setenv("JUJU_HOME", "/home/eric/juju") 28 osenv.SetJujuHome("/home/eric/juju") 29 30 s.FakeJujuHomeSuite.SetUpTest(c) 31 } 32 33 func (s *fakeHomeSuite) TearDownTest(c *gc.C) { 34 s.FakeJujuHomeSuite.TearDownTest(c) 35 36 // Test that the environment is restored. 37 c.Assert(utils.Home(), gc.Equals, "/home/eric") 38 c.Assert(os.Getenv("JUJU_HOME"), gc.Equals, "/home/eric/juju") 39 c.Assert(osenv.JujuHome(), gc.Equals, "/home/eric/juju") 40 } 41 42 func (s *fakeHomeSuite) TestFakeHomeSetsUpJujuHome(c *gc.C) { 43 jujuDir := gitjujutesting.HomePath(".juju") 44 c.Assert(jujuDir, jc.IsDirectory) 45 envFile := filepath.Join(jujuDir, "environments.yaml") 46 c.Assert(envFile, jc.IsNonEmptyFile) 47 } 48 49 func (s *fakeHomeSuite) TestFakeHomeSetsConfigJujuHome(c *gc.C) { 50 expected := filepath.Join(utils.Home(), ".juju") 51 c.Assert(osenv.JujuHome(), gc.Equals, expected) 52 }