-
Notifications
You must be signed in to change notification settings - Fork 0
/
agentconf_test.go
80 lines (61 loc) · 1.57 KB
/
agentconf_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package main
import (
"github.com/juju/errors"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/agent"
coretesting "github.com/juju/juju/testing"
)
var _ = gc.Suite(&agentConfSuite{})
type agentConfSuite struct {
coretesting.BaseSuite
}
func (s *agentConfSuite) TestChangeConfigSuccess(c *gc.C) {
mcsw := &mockConfigSetterWriter{}
conf := AgentConf{
dataDir: c.MkDir(),
_config: mcsw,
}
err := conf.ChangeConfig(func(agent.ConfigSetter) error {
return nil
})
c.Assert(err, gc.IsNil)
c.Assert(mcsw.WriteCalled, jc.IsTrue)
}
func (s *agentConfSuite) TestChangeConfigMutateFailure(c *gc.C) {
mcsw := &mockConfigSetterWriter{}
conf := AgentConf{
dataDir: c.MkDir(),
_config: mcsw,
}
err := conf.ChangeConfig(func(agent.ConfigSetter) error {
return errors.New("blam")
})
c.Assert(err, gc.ErrorMatches, "blam")
c.Assert(mcsw.WriteCalled, jc.IsFalse)
}
func (s *agentConfSuite) TestChangeConfigWriteFailure(c *gc.C) {
mcsw := &mockConfigSetterWriter{
WriteError: errors.New("boom"),
}
conf := AgentConf{
dataDir: c.MkDir(),
_config: mcsw,
}
err := conf.ChangeConfig(func(agent.ConfigSetter) error {
return nil
})
c.Assert(err, gc.ErrorMatches, "cannot write agent configuration: boom")
c.Assert(mcsw.WriteCalled, jc.IsTrue)
}
type mockConfigSetterWriter struct {
agent.ConfigSetterWriter
WriteError error
WriteCalled bool
}
func (c *mockConfigSetterWriter) Write() error {
c.WriteCalled = true
return c.WriteError
}