@@ -296,6 +296,80 @@ var _ = Describe("Generate", func() {
296
296
})
297
297
})
298
298
299
+ Context ("with an action using websocket" , func () {
300
+ BeforeEach (func () {
301
+ codegen .TempCount = 0
302
+ o := design.Object {
303
+ "fields[foo]" : & design.AttributeDefinition {Type : design .String },
304
+ "fields[bar]" : & design.AttributeDefinition {Type : & design.Array {ElemType : & design.AttributeDefinition {Type : design .String }}},
305
+ "fields[baz]" : & design.AttributeDefinition {Type : & design.Array {ElemType : & design.AttributeDefinition {Type : design .Integer }}},
306
+ "fields[bat]" : & design.AttributeDefinition {Type : design .DateTime },
307
+ }
308
+ design .Design = & design.APIDefinition {
309
+ Name : "testapi" ,
310
+ Resources : map [string ]* design.ResourceDefinition {
311
+ "foo" : {
312
+ Name : "foo" ,
313
+ Actions : map [string ]* design.ActionDefinition {
314
+ "show" : {
315
+ Name : "show" ,
316
+ Schemes : []string {"ws" },
317
+ Routes : []* design.RouteDefinition {
318
+ {
319
+ Verb : "GET" ,
320
+ Path : "" ,
321
+ },
322
+ },
323
+ QueryParams : & design.AttributeDefinition {Type : o },
324
+ },
325
+ },
326
+ },
327
+ },
328
+ }
329
+ fooRes := design .Design .Resources ["foo" ]
330
+ showAct := fooRes .Actions ["show" ]
331
+ showAct .Parent = fooRes
332
+ showAct .Routes [0 ].Parent = showAct
333
+ })
334
+
335
+ It ("generates param initialization code that uses the param name given in the design" , func () {
336
+ Ω (genErr ).Should (BeNil ())
337
+ Ω (files ).Should (HaveLen (9 ))
338
+ c , err := ioutil .ReadFile (filepath .Join (outDir , "client" , "foo.go" ))
339
+ Ω (err ).ShouldNot (HaveOccurred ())
340
+ content := string (c )
341
+ Ω (content ).Should (ContainSubstring ("func ShowFooPath(" ))
342
+ Ω (content ).Should (ContainSubstring (`values.Set("fields[foo]", *fieldsFoo)` ))
343
+ Ω (content ).Should (ContainSubstring (` if fieldsBar != nil {
344
+ for _, p := range fieldsBar {
345
+ tmp3 := p
346
+ values.Add("fields[bar]", tmp3)
347
+ }
348
+ }
349
+ ` ))
350
+ Ω (content ).Should (ContainSubstring (` if fieldsBaz != nil {
351
+ for _, p := range fieldsBaz {
352
+ tmp5 := strconv.Itoa(p)
353
+ values.Add("fields[baz]", tmp5)
354
+ }
355
+ }
356
+ ` ))
357
+ Ω (content ).Should (ContainSubstring (` tmp4 := fieldsBat.Format(time.RFC3339)
358
+ values.Set("fields[bat]", tmp4)` ))
359
+ })
360
+
361
+ Context ("with --notool" , func () {
362
+ BeforeEach (func () {
363
+ os .Args = append (os .Args , "--notool" )
364
+ })
365
+
366
+ It ("should not return an error" , func () {
367
+ Ω (genErr ).Should (BeNil ())
368
+ Ω (files ).Should (HaveLen (5 )) // 9, minus 4 entries for tool paths
369
+ })
370
+ })
371
+ })
372
+
299
373
Context ("with an action with multiple routes" , func () {
300
374
BeforeEach (func () {
301
375
design .Design = & design.APIDefinition {
0 commit comments