forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformer_test.go
86 lines (83 loc) · 2.07 KB
/
transformer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package codegen
import (
"testing"
"goa.design/goa/v3/expr"
)
func TestIsPrimitivePointer(t *testing.T) {
newObj := func(fieldName string, fieldType expr.DataType, req bool) *expr.AttributeExpr {
attr := &expr.AttributeExpr{
Type: &expr.Object{
&expr.NamedAttributeExpr{fieldName, &expr.AttributeExpr{Type: fieldType}},
},
}
if req {
attr.Validation = &expr.ValidationExpr{Required: []string{fieldName}}
}
return attr
}
tc := []struct {
Test string
Context *AttributeContext
Attr *expr.AttributeExpr
Name string
Expected bool
}{
{
Test: "pointer attribute",
Context: &AttributeContext{},
Attr: newObj("foo", expr.String, false),
Name: "foo",
Expected: true,
},
{
Test: "non pointer attribute",
Context: &AttributeContext{},
Attr: newObj("foo", expr.String, true),
Name: "foo",
Expected: false,
},
{
Test: "pointer context with pointer attribute",
Context: &AttributeContext{Pointer: true},
Attr: newObj("foo", expr.String, false),
Name: "foo",
Expected: true,
},
{
Test: "pointer context with non pointer attribute",
Context: &AttributeContext{Pointer: true},
Attr: newObj("foo", expr.String, true),
Name: "foo",
Expected: true,
},
{
Test: "ignore required context with pointer attribute",
Context: &AttributeContext{IgnoreRequired: true},
Attr: newObj("foo", expr.String, false),
Name: "foo",
Expected: false,
},
{
Test: "ignore required context with non pointer attribute",
Context: &AttributeContext{IgnoreRequired: true},
Attr: newObj("foo", expr.String, true),
Name: "foo",
Expected: false,
},
{
Test: "missing attribute",
Context: &AttributeContext{},
Attr: newObj("foo", expr.String, false),
Name: "bar",
Expected: false,
},
}
for _, c := range tc {
t.Run(c.Test, func(t *testing.T) {
got := c.Context.IsPrimitivePointer(c.Name, c.Attr)
if got != c.Expected {
t.Errorf("expected %v, got %v", c.Expected, got)
}
})
}
}