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)
50
55
err := staged.stage()
51
56
c.Assert(err, jc.ErrorIsNil)
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{{
56
61
Id: "resource#a-service/spam#staged",
57
62
Assert: txn.DocMissing,
67
Assert: txn.DocExists,
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)
68
77
err := staged.stage()
69
78
c.Assert(err, jc.ErrorIsNil)
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{{
74
83
Id: "resource#a-service/spam#staged",
75
84
Assert: txn.DocMissing,
89
Assert: txn.DocExists,
78
s.stub.CheckCall(c, 2, "RunTransaction", []txn.Op{{
91
s.stub.CheckCall(c, 4, "RunTransaction", []txn.Op{{
80
93
Id: "resource#a-service/spam#staged",
98
Assert: txn.DocExists,
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)
106
123
err := staged.Activate()
107
124
c.Assert(err, jc.ErrorIsNil)
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{{
113
130
Id: "resource#a-service/spam",
114
131
Assert: txn.DocMissing,
136
Assert: txn.DocExists,
118
139
Id: "resource#a-service/spam#staged",
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)
128
149
err := staged.Activate()
129
150
c.Assert(err, jc.ErrorIsNil)
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{{
135
156
Id: "resource#a-service/spam",
136
157
Assert: txn.DocMissing,
162
Assert: txn.DocExists,
140
165
Id: "resource#a-service/spam#staged",
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{{
146
171
Id: "resource#a-service/spam",
147
172
Assert: txn.DocExists,