~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/gopkg.in/goose.v1/testing/envsuite/envsuite_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package envsuite
 
2
 
 
3
import (
 
4
        "os"
 
5
        "testing"
 
6
 
 
7
        gc "gopkg.in/check.v1"
 
8
)
 
9
 
 
10
type EnvTestSuite struct {
 
11
        EnvSuite
 
12
}
 
13
 
 
14
func Test(t *testing.T) {
 
15
        gc.TestingT(t)
 
16
}
 
17
 
 
18
var _ = gc.Suite(&EnvTestSuite{})
 
19
 
 
20
func (s *EnvTestSuite) TestGrabsCurrentEnvironment(c *gc.C) {
 
21
        envsuite := &EnvSuite{}
 
22
        // EnvTestSuite is an EnvSuite, so we should have already isolated
 
23
        // ourselves from the world. So we set a single env value, and we
 
24
        // assert that SetUpSuite is able to see that.
 
25
        os.Setenv("TEST_KEY", "test-value")
 
26
        envsuite.SetUpSuite(c)
 
27
        c.Assert(envsuite.environ, gc.DeepEquals, []string{"TEST_KEY=test-value"})
 
28
}
 
29
 
 
30
func (s *EnvTestSuite) TestClearsEnvironment(c *gc.C) {
 
31
        envsuite := &EnvSuite{}
 
32
        os.Setenv("TEST_KEY", "test-value")
 
33
        envsuite.SetUpSuite(c)
 
34
        // SetUpTest should reset the current environment back to being
 
35
        // completely empty.
 
36
        envsuite.SetUpTest(c)
 
37
        c.Assert(os.Getenv("TEST_KEY"), gc.Equals, "")
 
38
        c.Assert(os.Environ(), gc.DeepEquals, []string{})
 
39
}
 
40
 
 
41
func (s *EnvTestSuite) TestRestoresEnvironment(c *gc.C) {
 
42
        envsuite := &EnvSuite{}
 
43
        os.Setenv("TEST_KEY", "test-value")
 
44
        envsuite.SetUpSuite(c)
 
45
        envsuite.SetUpTest(c)
 
46
        envsuite.TearDownTest(c)
 
47
        c.Assert(os.Getenv("TEST_KEY"), gc.Equals, "test-value")
 
48
        c.Assert(os.Environ(), gc.DeepEquals, []string{"TEST_KEY=test-value"})
 
49
}