~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/juju/osenv/vars_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
// Copyright 2014 Canonical Ltd.
 
2
// Copyright 2014 Cloudbase Solutions SRL
 
3
// Licensed under the AGPLv3, see LICENCE file for details.
 
4
 
 
5
package osenv_test
 
6
 
 
7
import (
 
8
        "runtime"
 
9
 
 
10
        jc "github.com/juju/testing/checkers"
 
11
        gc "gopkg.in/check.v1"
 
12
 
 
13
        "github.com/juju/juju/juju/osenv"
 
14
        "github.com/juju/juju/testing"
 
15
)
 
16
 
 
17
type varsSuite struct {
 
18
        testing.BaseSuite
 
19
}
 
20
 
 
21
var _ = gc.Suite(&varsSuite{})
 
22
 
 
23
func (s *varsSuite) TestJujuXDGDataHomeEnvVar(c *gc.C) {
 
24
        path := "/foo/bar/baz"
 
25
        s.PatchEnvironment(osenv.JujuXDGDataHomeEnvKey, path)
 
26
        c.Assert(osenv.JujuXDGDataHomeDir(), gc.Equals, path)
 
27
}
 
28
 
 
29
func (s *varsSuite) TestBlankJujuXDGDataHomeEnvVar(c *gc.C) {
 
30
        s.PatchEnvironment(osenv.JujuXDGDataHomeEnvKey, "")
 
31
 
 
32
        if runtime.GOOS == "windows" {
 
33
                s.PatchEnvironment("APPDATA", `P:\foobar`)
 
34
        } else {
 
35
                s.PatchEnvironment("HOME", "/foobar")
 
36
        }
 
37
        c.Assert(osenv.JujuXDGDataHomeDir(), gc.Not(gc.Equals), "")
 
38
 
 
39
        if runtime.GOOS == "windows" {
 
40
                c.Assert(osenv.JujuXDGDataHomeDir(), gc.Equals, osenv.JujuXDGDataHomeWin())
 
41
        } else {
 
42
                c.Assert(osenv.JujuXDGDataHomeDir(), gc.Equals, osenv.JujuXDGDataHomeLinux())
 
43
        }
 
44
}
 
45
 
 
46
func (s *varsSuite) TestMergeEnvironment(c *gc.C) {
 
47
        c.Check(osenv.MergeEnvironment(nil, nil), gc.HasLen, 0)
 
48
        newValues := map[string]string{"a": "baz", "c": "omg"}
 
49
        created := osenv.MergeEnvironment(nil, newValues)
 
50
        expected := map[string]string{"a": "baz", "c": "omg"}
 
51
        c.Check(created, jc.DeepEquals, expected)
 
52
        // Show that the map returned isn't the one passed in.
 
53
        newValues["d"] = "another"
 
54
        c.Check(created, jc.DeepEquals, expected)
 
55
}
 
56
 
 
57
func (s *varsSuite) TestMergeEnvWin(c *gc.C) {
 
58
        initial := map[string]string{"a": "foo", "b": "bar", "foo": "val"}
 
59
        newValues := map[string]string{"a": "baz", "c": "omg", "FOO": "val2", "d": "another"}
 
60
 
 
61
        created := osenv.MergeEnvWin(initial, newValues)
 
62
        expected := map[string]string{"a": "baz", "b": "bar", "c": "omg", "foo": "val2", "d": "another"}
 
63
        // The returned value is the inital map.
 
64
        c.Check(created, jc.DeepEquals, expected)
 
65
        c.Check(initial, jc.DeepEquals, expected)
 
66
}
 
67
 
 
68
func (s *varsSuite) TestMergeEnvUnix(c *gc.C) {
 
69
        initial := map[string]string{"a": "foo", "b": "bar"}
 
70
        newValues := map[string]string{"a": "baz", "c": "omg", "d": "another"}
 
71
 
 
72
        created := osenv.MergeEnvUnix(initial, newValues)
 
73
        expected := map[string]string{"a": "baz", "b": "bar", "c": "omg", "d": "another"}
 
74
        // The returned value is the inital map.
 
75
        c.Check(created, jc.DeepEquals, expected)
 
76
        c.Check(initial, jc.DeepEquals, expected)
 
77
}