174
func (s *ActionSuite) TestAddActionInsertsDefaults(c *gc.C) {
175
units := make(map[string]*state.Unit)
176
schemas := map[string]string{
206
// Prepare the units for this test
207
makeUnits(c, s, units, schemas)
209
for i, t := range []struct {
211
params map[string]interface{}
213
expectedParams map[string]interface{}
215
should: "do nothing with no defaults",
216
params: map[string]interface{}{},
218
expectedParams: map[string]interface{}{},
220
should: "insert a simple default value",
221
params: map[string]interface{}{"foo": "bar"},
223
expectedParams: map[string]interface{}{
228
should: "insert a default value when an empty map is passed",
229
params: map[string]interface{}{},
231
expectedParams: map[string]interface{}{
235
should: "insert a default value when a nil map is passed",
238
expectedParams: map[string]interface{}{
242
should: "insert a nested default value",
243
params: map[string]interface{}{"foo": "bar"},
244
schema: "complicated",
245
expectedParams: map[string]interface{}{
247
"val": map[string]interface{}{
248
"bar": map[string]interface{}{
252
c.Logf("test %d: should %s", i, t.should)
254
// Note that AddAction will only result in errors in the case
255
// of malformed schemas, and schema objects can only be
256
// created from valid schemas. The error handling for this
257
// is tested in the gojsonschema package.
258
action, err := u.AddAction("act", t.params)
259
c.Assert(err, jc.ErrorIsNil)
260
c.Check(action.Parameters(), jc.DeepEquals, t.expectedParams)
264
// makeUnits prepares units with given Action schemas
265
func makeUnits(c *gc.C, s *ActionSuite, units map[string]*state.Unit, schemas map[string]string) {
266
// A few dummy charms that haven't been used yet
267
freeCharms := map[string]string{
269
"complicated": "mysql-alternative",
273
for name, schema := range schemas {
274
svcName := name + "-defaults-service"
276
// Add a testing service
277
ch := s.AddActionsCharm(c, freeCharms[name], schema, 1)
278
svc := s.AddTestingService(c, svcName, ch)
281
sUrl, _ := svc.CharmURL()
282
c.Assert(sUrl, gc.NotNil)
286
u, err := svc.AddUnit()
287
c.Assert(err, jc.ErrorIsNil)
288
c.Assert(u.Series(), gc.Equals, "quantal")
289
err = u.SetCharmURL(sUrl)
290
c.Assert(err, jc.ErrorIsNil)
174
296
func (s *ActionSuite) TestEnqueueActionRequiresName(c *gc.C) {
742
864
func (r mockAR) Actions() ([]*state.Action, error) { return nil, nil }
743
865
func (r mockAR) CompletedActions() ([]*state.Action, error) { return nil, nil }
744
866
func (r mockAR) PendingActions() ([]*state.Action, error) { return nil, nil }
867
func (r mockAR) RunningActions() ([]*state.Action, error) { return nil, nil }
745
868
func (r mockAR) Tag() names.Tag { return names.NewUnitTag(r.id) }
747
870
// TestMock verifies the mock UUID generator works as expected.