~sinzui/ubuntu/wily/juju-core/wily-1.24.7

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-22 15:27:01 UTC
  • mfrom: (1.1.36)
  • Revision ID: package-import@ubuntu.com-20150922152701-lzq2yhn2uaahrdqu
Tags: 1.24.6-0ubuntu1
* New upstream release (LP: #1481556).
* d/copyright updated for Juju 1.24.6 (Last verified commit changes).
* d/tests/* Run tests with upstart when Juju version before 1.23.
* Prefer gccgo-5 for ppc64el and arm64 in build-deps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
                params: map[string]interface{}{
129
129
                        "outfile": 5.0,
130
130
                },
131
 
                expectedErr: "JSON validation failed: \\(root\\)\\.outfile : must be of type string, given 5",
 
131
                expectedErr: "validation failed: \\(root\\)\\.outfile : must be of type string, given 5",
132
132
        }} {
133
133
                c.Logf("Test %d: should %s", i, t.should)
134
134
                before := state.NowToTheSecond()
171
171
        }
172
172
}
173
173
 
 
174
func (s *ActionSuite) TestAddActionInsertsDefaults(c *gc.C) {
 
175
        units := make(map[string]*state.Unit)
 
176
        schemas := map[string]string{
 
177
                "simple": `
 
178
act:
 
179
  params:
 
180
    val:
 
181
      type: string
 
182
      default: somestr
 
183
`[1:],
 
184
                "complicated": `
 
185
act:
 
186
  params:
 
187
    val:
 
188
      type: object
 
189
      properties:
 
190
        foo:
 
191
          type: string
 
192
        bar:
 
193
          type: object
 
194
          properties:
 
195
            baz:
 
196
              type: string
 
197
              default: woz
 
198
`[1:],
 
199
                "none": `
 
200
act:
 
201
  params:
 
202
    val:
 
203
      type: string
 
204
`[1:]}
 
205
 
 
206
        // Prepare the units for this test
 
207
        makeUnits(c, s, units, schemas)
 
208
 
 
209
        for i, t := range []struct {
 
210
                should         string
 
211
                params         map[string]interface{}
 
212
                schema         string
 
213
                expectedParams map[string]interface{}
 
214
        }{{
 
215
                should:         "do nothing with no defaults",
 
216
                params:         map[string]interface{}{},
 
217
                schema:         "none",
 
218
                expectedParams: map[string]interface{}{},
 
219
        }, {
 
220
                should: "insert a simple default value",
 
221
                params: map[string]interface{}{"foo": "bar"},
 
222
                schema: "simple",
 
223
                expectedParams: map[string]interface{}{
 
224
                        "foo": "bar",
 
225
                        "val": "somestr",
 
226
                },
 
227
        }, {
 
228
                should: "insert a default value when an empty map is passed",
 
229
                params: map[string]interface{}{},
 
230
                schema: "simple",
 
231
                expectedParams: map[string]interface{}{
 
232
                        "val": "somestr",
 
233
                },
 
234
        }, {
 
235
                should: "insert a default value when a nil map is passed",
 
236
                params: nil,
 
237
                schema: "simple",
 
238
                expectedParams: map[string]interface{}{
 
239
                        "val": "somestr",
 
240
                },
 
241
        }, {
 
242
                should: "insert a nested default value",
 
243
                params: map[string]interface{}{"foo": "bar"},
 
244
                schema: "complicated",
 
245
                expectedParams: map[string]interface{}{
 
246
                        "foo": "bar",
 
247
                        "val": map[string]interface{}{
 
248
                                "bar": map[string]interface{}{
 
249
                                        "baz": "woz",
 
250
                                }}},
 
251
        }} {
 
252
                c.Logf("test %d: should %s", i, t.should)
 
253
                u := units[t.schema]
 
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)
 
261
        }
 
262
}
 
263
 
 
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{
 
268
                "simple":      "mysql",
 
269
                "complicated": "mysql-alternative",
 
270
                "none":        "wordpress",
 
271
        }
 
272
 
 
273
        for name, schema := range schemas {
 
274
                svcName := name + "-defaults-service"
 
275
 
 
276
                // Add a testing service
 
277
                ch := s.AddActionsCharm(c, freeCharms[name], schema, 1)
 
278
                svc := s.AddTestingService(c, svcName, ch)
 
279
 
 
280
                // Get its charm URL
 
281
                sUrl, _ := svc.CharmURL()
 
282
                c.Assert(sUrl, gc.NotNil)
 
283
 
 
284
                // Add a unit
 
285
                var err error
 
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)
 
291
 
 
292
                units[name] = u
 
293
        }
 
294
}
 
295
 
174
296
func (s *ActionSuite) TestEnqueueActionRequiresName(c *gc.C) {
175
297
        name := ""
176
298
 
409
531
        c.Assert(err, jc.ErrorIsNil)
410
532
 
411
533
        // per contract, there should be at minimum an initial empty Change() result
412
 
        wc.AssertChange()
 
534
        wc.AssertChangeMaybeIncluding(expectActionIds(a1, a2)...)
413
535
        wc.AssertNoChange()
414
536
}
415
537
 
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) }
746
869
 
747
870
// TestMock verifies the mock UUID generator works as expected.