Skip to content

Commit

Permalink
Avoid using keywords for arguments in TestHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tchssk committed Feb 28, 2017
1 parent 393cf48 commit 9bf616c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 26 additions & 1 deletion goagen/gen_app/test_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ func (g *Generator) createTestMethod(resource *design.ResourceDefinition, action
}
}

var tempCount = map[string]int{
"logBuf": 1,
"resp": 1,
"respSetter": 1,
"logger": 1,
"newEncoder": 1,
"err": 1,
"e": 1,
"ok": 1,
"rw": 1,
"query": 1,
"u": 1,
"req": 1,
"prms": 1,
"goaCtx": 1,
}

func tempvar(s string) string {
if v, ok := tempCount[s]; ok {
tempCount[s]++
return fmt.Sprintf("%s%d", s, v)
}
return s
}

// pathParams returns the path params for the given action and route.
func pathParams(action *design.ActionDefinition, route *design.RouteDefinition) []*ObjectType {
return paramFromNames(action, route.Params())
Expand Down Expand Up @@ -265,7 +290,7 @@ func paramFromNames(action *design.ActionDefinition, names []string) (params []*
func attToObject(name string, parent, att *design.AttributeDefinition) *ObjectType {
obj := &ObjectType{}
obj.Label = name
obj.Name = codegen.Goify(name, false)
obj.Name = tempvar(codegen.Goify(name, false))
obj.Type = codegen.GoTypeRef(att.Type, nil, 0, false)
if att.Type.IsPrimitive() && parent.IsPrimitivePointer(name) {
obj.Pointer = "*"
Expand Down
3 changes: 3 additions & 0 deletions goagen/gen_app/test_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var _ = Describe("Generate", func() {
"uuid": &design.AttributeDefinition{Type: design.UUID},
"optional": &design.AttributeDefinition{Type: design.Integer},
"required": &design.AttributeDefinition{Type: design.DateTime},
"query": &design.AttributeDefinition{Type: design.String},
},
Validation: &dslengine.ValidationDefinition{Required: []string{"required"}},
},
Expand All @@ -117,6 +118,7 @@ var _ = Describe("Generate", func() {
Type: design.Object{
"optional": &design.AttributeDefinition{Type: design.Integer},
"required": &design.AttributeDefinition{Type: design.DateTime},
"query": &design.AttributeDefinition{Type: design.String},
},
Validation: &dslengine.ValidationDefinition{Required: []string{"required"}},
},
Expand Down Expand Up @@ -211,6 +213,7 @@ var _ = Describe("Generate", func() {

Ω(content).Should(ContainSubstring(`if optional != nil`))
Ω(content).ShouldNot(ContainSubstring(`if required != nil`))
Ω(content).Should(And(ContainSubstring(`if query`), ContainSubstring(`!= nil`)))
})

It("properly handles headers", func() {
Expand Down

0 comments on commit 9bf616c

Please sign in to comment.