Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1344)

Side by Side Diff: worker/uniter/state_test.go

Issue 6489083: combine charm and hook states as uniter state
Patch Set: combine charm and hook states as uniter state Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « worker/uniter/state.go ('k') | worker/uniter/uniter.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 package uniter_test
2
3 import (
4 . "launchpad.net/gocheck"
5 "launchpad.net/juju-core/charm"
6 "launchpad.net/juju-core/trivial"
7 "launchpad.net/juju-core/worker/uniter"
8 "launchpad.net/juju-core/worker/uniter/hook"
9 "path/filepath"
10 )
11
12 type StateFileSuite struct{}
13
14 var _ = Suite(&StateFileSuite{})
15
16 var stcurl = charm.MustParseURL("cs:series/service-name-123")
17 var relhook = &hook.Info{
18 Kind: hook.RelationJoined,
19 RemoteUnit: "some-thing/123",
20 Members: map[string]map[string]interface{}{
21 "blah/0": {"cheese": "gouda"},
22 },
23 }
24
25 var stateTests = []struct {
26 st uniter.State
27 err string
28 }{
29 // Invalid op/step.
30 {
31 st: uniter.State{Op: uniter.Op("bloviate")},
32 err: `unknown operation "bloviate"`,
33 }, {
34 st: uniter.State{
35 Op: uniter.Abide,
36 OpStep: uniter.OpStep("dudelike"),
37 Hook: &hook.Info{Kind: hook.ConfigChanged},
38 },
39 err: `unknown operation step "dudelike"`,
40 },
41 // Install operation.
42 {
43 st: uniter.State{
44 Op: uniter.Install,
45 OpStep: uniter.Pending,
46 Hook: &hook.Info{Kind: hook.ConfigChanged},
47 },
48 err: `unexpected hook info`,
49 }, {
50 st: uniter.State{
51 Op: uniter.Install,
52 OpStep: uniter.Pending,
53 },
54 err: `missing charm URL`,
55 }, {
56 st: uniter.State{
57 Op: uniter.Install,
58 OpStep: uniter.Pending,
59 CharmURL: stcurl,
60 },
61 },
62 // RunHook operation.
63 {
64 st: uniter.State{
65 Op: uniter.RunHook,
66 OpStep: uniter.Pending,
67 Hook: &hook.Info{Kind: hook.Kind("machine-exploded")},
68 },
69 err: `unknown hook kind "machine-exploded"`,
70 }, {
71 st: uniter.State{
72 Op: uniter.RunHook,
73 OpStep: uniter.Pending,
74 Hook: &hook.Info{Kind: hook.RelationJoined},
75 },
76 err: `"relation-joined" hook requires a remote unit`,
77 }, {
78 st: uniter.State{
79 Op: uniter.RunHook,
80 OpStep: uniter.Pending,
81 Hook: &hook.Info{Kind: hook.ConfigChanged},
82 CharmURL: stcurl,
83 },
84 err: `unexpected charm URL`,
85 }, {
86 st: uniter.State{
87 Op: uniter.RunHook,
88 OpStep: uniter.Pending,
89 Hook: &hook.Info{Kind: hook.ConfigChanged},
90 },
91 }, {
92 st: uniter.State{
93 Op: uniter.RunHook,
94 OpStep: uniter.Pending,
95 Hook: relhook,
96 },
97 },
98 // Upgrade operation.
99 {
100 st: uniter.State{
101 Op: uniter.Upgrade,
102 OpStep: uniter.Pending,
103 },
104 err: `missing charm URL`,
105 }, {
106 st: uniter.State{
107 Op: uniter.Upgrade,
108 OpStep: uniter.Pending,
109 CharmURL: stcurl,
110 },
111 }, {
112 st: uniter.State{
113 Op: uniter.Upgrade,
114 OpStep: uniter.Pending,
115 Hook: relhook,
116 CharmURL: stcurl,
117 },
118 },
119 // Abide operation.
120 {
121 st: uniter.State{
122 Op: uniter.Abide,
123 OpStep: uniter.Pending,
124 },
125 err: `missing hook info`,
126 }, {
127 st: uniter.State{
128 Op: uniter.Abide,
129 OpStep: uniter.Pending,
130 Hook: relhook,
131 CharmURL: stcurl,
132 },
133 err: `unexpected charm URL`,
134 }, {
135 st: uniter.State{
136 Op: uniter.Abide,
137 OpStep: uniter.Pending,
138 Hook: relhook,
139 },
140 },
141 }
142
143 func (s *StateFileSuite) TestStates(c *C) {
144 for i, t := range stateTests {
145 c.Logf("test %d", i)
146 path := filepath.Join(c.MkDir(), "uniter")
147 file := uniter.NewStateFile(path)
148 _, err := file.Read()
149 c.Assert(err, Equals, uniter.ErrNoStateFile)
150 write := func() {
151 err := file.Write(t.st.Op, t.st.OpStep, t.st.Hook, t.st. CharmURL)
152 c.Assert(err, IsNil)
153 }
154 if t.err != "" {
155 c.Assert(write, PanicMatches, t.err)
156 err := trivial.WriteYaml(path, &t.st)
157 c.Assert(err, IsNil)
158 _, err = file.Read()
159 c.Assert(err, ErrorMatches, "invalid uniter state at .*: "+t.err)
160 continue
161 }
162 write()
163 st, err := file.Read()
164 c.Assert(err, IsNil)
165 if st.Hook != nil {
166 c.Assert(st.Hook.Members, HasLen, 0)
167 st.Hook.Members = t.st.Hook.Members
168 }
169 c.Assert(*st, DeepEquals, t.st)
170 }
171 }
OLDNEW
« no previous file with comments | « worker/uniter/state.go ('k') | worker/uniter/uniter.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b