github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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  
     9  	"github.com/juju/names"
    10  	gitjujutesting "github.com/juju/testing"
    11  	jc "github.com/juju/testing/checkers"
    12  	"github.com/juju/utils"
    13  	gc "gopkg.in/check.v1"
    14  
    15  	"github.com/juju/juju/juju/osenv"
    16  	"github.com/juju/juju/testing"
    17  )
    18  
    19  type fakeHomeSuite struct {
    20  	testing.FakeJujuXDGDataHomeSuite
    21  }
    22  
    23  var _ = gc.Suite(&fakeHomeSuite{})
    24  
    25  func (s *fakeHomeSuite) SetUpTest(c *gc.C) {
    26  	utils.SetHome(home)
    27  	os.Setenv("JUJU_DATA", jujuXDGDataHome)
    28  	osenv.SetJujuXDGDataHome(jujuXDGDataHome)
    29  
    30  	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
    31  }
    32  
    33  func (s *fakeHomeSuite) TearDownTest(c *gc.C) {
    34  	s.FakeJujuXDGDataHomeSuite.TearDownTest(c)
    35  
    36  	// Test that the environment is restored.
    37  	c.Assert(utils.Home(), gc.Equals, jujuXDGDataHome)
    38  	c.Assert(os.Getenv("JUJU_DATA"), gc.Equals, jujuXDGDataHome)
    39  	c.Assert(osenv.JujuXDGDataHome(), gc.Equals, jujuXDGDataHome)
    40  }
    41  
    42  func (s *fakeHomeSuite) TestFakeHomeSetsUpJujuXDGDataHome(c *gc.C) {
    43  	jujuDir := gitjujutesting.JujuXDGDataHomePath()
    44  	c.Assert(jujuDir, jc.IsDirectory)
    45  }
    46  
    47  func (s *fakeHomeSuite) TestFakeHomeSetsConfigJujuXDGDataHome(c *gc.C) {
    48  	s.PatchEnvironment(osenv.XDGDataHome, "")
    49  	expected := gitjujutesting.JujuXDGDataHomePath()
    50  	c.Assert(osenv.JujuXDGDataHome(), gc.Equals, expected)
    51  }
    52  
    53  func (s *fakeHomeSuite) TestModelTagValid(c *gc.C) {
    54  	asString := testing.ModelTag.String()
    55  	tag, err := names.ParseModelTag(asString)
    56  	c.Assert(err, jc.ErrorIsNil)
    57  	c.Assert(tag, gc.Equals, testing.ModelTag)
    58  }
    59  
    60  func (s *fakeHomeSuite) TestEnvironUUIDValid(c *gc.C) {
    61  	c.Assert(utils.IsValidUUIDString(testing.ModelTag.Id()), jc.IsTrue)
    62  }