~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/resources_persistence_staged_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
        s.stub = &testing.Stub{}
29
29
        s.base = statetest.NewStubPersistence(s.stub)
 
30
        s.base.ReturnServiceExistsOps = []txn.Op{{
 
31
                C:      "service",
 
32
                Id:     "a-service",
 
33
                Assert: txn.DocExists,
 
34
        }}
30
35
}
31
36
 
32
37
func (s *StagedResourceSuite) newStagedResource(c *gc.C, serviceID, name string) (*StagedResource, resourceDoc) {
45
50
        staged, doc := s.newStagedResource(c, "a-service", "spam")
46
51
        doc.DocID += "#staged"
47
52
        ignoredErr := errors.New("<never reached>")
48
 
        s.stub.SetErrors(nil, nil, ignoredErr)
 
53
        s.stub.SetErrors(nil, nil, nil, ignoredErr)
49
54
 
50
55
        err := staged.stage()
51
56
        c.Assert(err, jc.ErrorIsNil)
52
57
 
53
 
        s.stub.CheckCallNames(c, "Run", "RunTransaction")
54
 
        s.stub.CheckCall(c, 1, "RunTransaction", []txn.Op{{
 
58
        s.stub.CheckCallNames(c, "Run", "ServiceExistsOps", "RunTransaction")
 
59
        s.stub.CheckCall(c, 2, "RunTransaction", []txn.Op{{
55
60
                C:      "resources",
56
61
                Id:     "resource#a-service/spam#staged",
57
62
                Assert: txn.DocMissing,
58
63
                Insert: &doc,
 
64
        }, {
 
65
                C:      "service",
 
66
                Id:     "a-service",
 
67
                Assert: txn.DocExists,
59
68
        }})
60
69
}
61
70
 
63
72
        staged, doc := s.newStagedResource(c, "a-service", "spam")
64
73
        doc.DocID += "#staged"
65
74
        ignoredErr := errors.New("<never reached>")
66
 
        s.stub.SetErrors(nil, txn.ErrAborted, nil, ignoredErr)
 
75
        s.stub.SetErrors(nil, nil, txn.ErrAborted, nil, nil, ignoredErr)
67
76
 
68
77
        err := staged.stage()
69
78
        c.Assert(err, jc.ErrorIsNil)
70
79
 
71
 
        s.stub.CheckCallNames(c, "Run", "RunTransaction", "RunTransaction")
72
 
        s.stub.CheckCall(c, 1, "RunTransaction", []txn.Op{{
 
80
        s.stub.CheckCallNames(c, "Run", "ServiceExistsOps", "RunTransaction", "ServiceExistsOps", "RunTransaction")
 
81
        s.stub.CheckCall(c, 2, "RunTransaction", []txn.Op{{
73
82
                C:      "resources",
74
83
                Id:     "resource#a-service/spam#staged",
75
84
                Assert: txn.DocMissing,
76
85
                Insert: &doc,
 
86
        }, {
 
87
                C:      "service",
 
88
                Id:     "a-service",
 
89
                Assert: txn.DocExists,
77
90
        }})
78
 
        s.stub.CheckCall(c, 2, "RunTransaction", []txn.Op{{
 
91
        s.stub.CheckCall(c, 4, "RunTransaction", []txn.Op{{
79
92
                C:      "resources",
80
93
                Id:     "resource#a-service/spam#staged",
81
94
                Assert: &doc,
 
95
        }, {
 
96
                C:      "service",
 
97
                Id:     "a-service",
 
98
                Assert: txn.DocExists,
82
99
        }})
83
100
}
84
101
 
101
118
func (s *StagedResourceSuite) TestActivateOkay(c *gc.C) {
102
119
        staged, doc := s.newStagedResource(c, "a-service", "spam")
103
120
        ignoredErr := errors.New("<never reached>")
104
 
        s.stub.SetErrors(nil, nil, nil, nil, ignoredErr)
 
121
        s.stub.SetErrors(nil, nil, nil, nil, nil, ignoredErr)
105
122
 
106
123
        err := staged.Activate()
107
124
        c.Assert(err, jc.ErrorIsNil)
108
125
 
109
 
        s.stub.CheckCallNames(c, "Run", "One", "IncCharmModifiedVersionOps", "RunTransaction")
110
 
        s.stub.CheckCall(c, 2, "IncCharmModifiedVersionOps", "a-service")
111
 
        s.stub.CheckCall(c, 3, "RunTransaction", []txn.Op{{
 
126
        s.stub.CheckCallNames(c, "Run", "ServiceExistsOps", "One", "IncCharmModifiedVersionOps", "RunTransaction")
 
127
        s.stub.CheckCall(c, 3, "IncCharmModifiedVersionOps", "a-service")
 
128
        s.stub.CheckCall(c, 4, "RunTransaction", []txn.Op{{
112
129
                C:      "resources",
113
130
                Id:     "resource#a-service/spam",
114
131
                Assert: txn.DocMissing,
115
132
                Insert: &doc,
116
133
        }, {
 
134
                C:      "service",
 
135
                Id:     "a-service",
 
136
                Assert: txn.DocExists,
 
137
        }, {
117
138
                C:      "resources",
118
139
                Id:     "resource#a-service/spam#staged",
119
140
                Remove: true,
123
144
func (s *StagedResourceSuite) TestActivateExists(c *gc.C) {
124
145
        staged, doc := s.newStagedResource(c, "a-service", "spam")
125
146
        ignoredErr := errors.New("<never reached>")
126
 
        s.stub.SetErrors(nil, nil, nil, txn.ErrAborted, nil, nil, nil, ignoredErr)
 
147
        s.stub.SetErrors(nil, nil, nil, nil, txn.ErrAborted, nil, nil, nil, nil, ignoredErr)
127
148
 
128
149
        err := staged.Activate()
129
150
        c.Assert(err, jc.ErrorIsNil)
130
151
 
131
 
        s.stub.CheckCallNames(c, "Run", "One", "IncCharmModifiedVersionOps", "RunTransaction", "One", "IncCharmModifiedVersionOps", "RunTransaction")
132
 
        s.stub.CheckCall(c, 2, "IncCharmModifiedVersionOps", "a-service")
133
 
        s.stub.CheckCall(c, 3, "RunTransaction", []txn.Op{{
 
152
        s.stub.CheckCallNames(c, "Run", "ServiceExistsOps", "One", "IncCharmModifiedVersionOps", "RunTransaction", "ServiceExistsOps", "One", "IncCharmModifiedVersionOps", "RunTransaction")
 
153
        s.stub.CheckCall(c, 3, "IncCharmModifiedVersionOps", "a-service")
 
154
        s.stub.CheckCall(c, 4, "RunTransaction", []txn.Op{{
134
155
                C:      "resources",
135
156
                Id:     "resource#a-service/spam",
136
157
                Assert: txn.DocMissing,
137
158
                Insert: &doc,
138
159
        }, {
 
160
                C:      "service",
 
161
                Id:     "a-service",
 
162
                Assert: txn.DocExists,
 
163
        }, {
139
164
                C:      "resources",
140
165
                Id:     "resource#a-service/spam#staged",
141
166
                Remove: true,
142
167
        }})
143
 
        s.stub.CheckCall(c, 5, "IncCharmModifiedVersionOps", "a-service")
144
 
        s.stub.CheckCall(c, 6, "RunTransaction", []txn.Op{{
 
168
        s.stub.CheckCall(c, 7, "IncCharmModifiedVersionOps", "a-service")
 
169
        s.stub.CheckCall(c, 8, "RunTransaction", []txn.Op{{
145
170
                C:      "resources",
146
171
                Id:     "resource#a-service/spam",
147
172
                Assert: txn.DocExists,
151
176
                Id:     "resource#a-service/spam",
152
177
                Assert: txn.DocMissing,
153
178
                Insert: &doc,
 
179
        }, {
 
180
                C:      "service",
 
181
                Id:     "a-service",
 
182
                Assert: txn.DocExists,
154
183
        }, {
155
184
                C:      "resources",
156
185
                Id:     "resource#a-service/spam#staged",