MCPcopy Create free account
hub / github.com/goadesign/goa / TestCollectAttributes

Function TestCollectAttributes

codegen/service/interceptors_test.go:94–218  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestCollectAttributes(t *testing.T) {
95 cases := []struct {
96 name string
97 attrNames *expr.AttributeExpr
98 parent *expr.AttributeExpr
99 want []*AttributeData
100 }{
101 {
102 name: "nil-attributes",
103 attrNames: nil,
104 parent: &expr.AttributeExpr{Type: &expr.Object{}},
105 want: nil,
106 },
107 {
108 name: "non-object-attributes",
109 attrNames: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)},
110 parent: &expr.AttributeExpr{Type: &expr.Object{}},
111 want: nil,
112 },
113 {
114 name: "simple-string-attribute",
115 attrNames: &expr.AttributeExpr{
116 Type: &expr.Object{
117 {Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}},
118 },
119 },
120 parent: &expr.AttributeExpr{
121 Type: &expr.Object{
122 {Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}},
123 },
124 Validation: &expr.ValidationExpr{Required: []string{"name"}},
125 },
126 want: []*AttributeData{
127 {Name: "Name", TypeRef: "string", Pointer: false},
128 },
129 },
130 {
131 name: "pointer-primitive",
132 attrNames: &expr.AttributeExpr{
133 Type: &expr.Object{
134 {Name: "age", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.IntKind)}},
135 },
136 },
137 parent: &expr.AttributeExpr{
138 Type: &expr.Object{
139 {Name: "age", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.IntKind), Meta: map[string][]string{"struct:field:pointer": {"true"}}}},
140 },
141 },
142 want: []*AttributeData{
143 {Name: "Age", TypeRef: "int", Pointer: true},
144 },
145 },
146 {
147 name: "multiple-attributes",
148 attrNames: &expr.AttributeExpr{
149 Type: &expr.Object{
150 {Name: "name", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.StringKind)}},
151 {Name: "age", Attribute: &expr.AttributeExpr{Type: expr.Primitive(expr.IntKind)}},

Callers

nothing calls this directly

Calls 4

PrimitiveTypeAlias · 0.92
NewNameScopeFunction · 0.92
collectAttributesFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected