1
// Copyright 2014 Canonical Ltd.
2
// Copyright 2014 Cloudbase Solutions SRL
3
// Licensed under the AGPLv3, see LICENCE file for details.
10
jc "github.com/juju/testing/checkers"
11
gc "gopkg.in/check.v1"
13
"github.com/juju/juju/juju/osenv"
14
"github.com/juju/juju/testing"
17
type varsSuite struct {
21
var _ = gc.Suite(&varsSuite{})
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)
29
func (s *varsSuite) TestBlankJujuXDGDataHomeEnvVar(c *gc.C) {
30
s.PatchEnvironment(osenv.JujuXDGDataHomeEnvKey, "")
32
if runtime.GOOS == "windows" {
33
s.PatchEnvironment("APPDATA", `P:\foobar`)
35
s.PatchEnvironment("HOME", "/foobar")
37
c.Assert(osenv.JujuXDGDataHomeDir(), gc.Not(gc.Equals), "")
39
if runtime.GOOS == "windows" {
40
c.Assert(osenv.JujuXDGDataHomeDir(), gc.Equals, osenv.JujuXDGDataHomeWin())
42
c.Assert(osenv.JujuXDGDataHomeDir(), gc.Equals, osenv.JujuXDGDataHomeLinux())
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)
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"}
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)
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"}
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)