1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package meterstatus_test
9
jc "github.com/juju/testing/checkers"
10
"github.com/juju/utils/keyvalues"
11
gc "gopkg.in/check.v1"
13
"github.com/juju/juju/worker/meterstatus"
16
type ContextSuite struct{}
18
var _ = gc.Suite(&ContextSuite{})
20
type dummyPaths struct{}
22
func (*dummyPaths) GetToolsDir() string { return "/dummy/tools" }
23
func (*dummyPaths) GetCharmDir() string { return "/dummy/charm" }
24
func (*dummyPaths) GetJujucSocket() string { return "/dummy/jujuc.sock" }
25
func (*dummyPaths) GetMetricsSpoolDir() string { return "/dummy/spool" }
26
func (*dummyPaths) ComponentDir(name string) string { return "/dummy/" + name }
28
func (s *ContextSuite) TestHookContextEnv(c *gc.C) {
29
ctx := meterstatus.NewLimitedContext("u/0")
30
paths := &dummyPaths{}
31
vars, err := ctx.HookVars(paths)
32
c.Assert(err, jc.ErrorIsNil)
33
varMap, err := keyvalues.Parse(vars, true)
34
c.Assert(err, jc.ErrorIsNil)
35
c.Assert(varMap["JUJU_AGENT_SOCKET"], gc.Equals, "/dummy/jujuc.sock")
36
c.Assert(varMap["JUJU_UNIT_NAME"], gc.Equals, "u/0")
38
if runtime.GOOS == "windows" {
41
c.Assert(varMap[key], gc.Not(gc.Equals), "")
44
func (s *ContextSuite) TestHookContextSetEnv(c *gc.C) {
45
ctx := meterstatus.NewLimitedContext("u/0")
46
setVars := map[string]string{
47
"somekey": "somevalue",
48
"anotherkey": "anothervalue",
50
ctx.SetEnvVars(setVars)
51
paths := &dummyPaths{}
52
vars, err := ctx.HookVars(paths)
53
c.Assert(err, jc.ErrorIsNil)
54
varMap, err := keyvalues.Parse(vars, true)
55
c.Assert(err, jc.ErrorIsNil)
56
for key, value := range setVars {
57
c.Assert(varMap[key], gc.Equals, value)
59
c.Assert(varMap["JUJU_AGENT_SOCKET"], gc.Equals, "/dummy/jujuc.sock")
60
c.Assert(varMap["JUJU_UNIT_NAME"], gc.Equals, "u/0")