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

Function TestGoTransformUnionError

codegen/go_transform_union_test.go:46–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestGoTransformUnionError(t *testing.T) {
47 root := RunDSL(t, testdata.TestUnionDSL)
48 var (
49 scope = NewNameScope()
50
51 // types to test
52 unionString = root.UserType("Container").Attribute().Find("UnionString").Find("UnionString")
53 unionStringInt = root.UserType("Container").Attribute().Find("UnionStringInt").Find("UnionStringInt")
54 unionSomeType = root.UserType("Container").Attribute().Find("UnionSomeType").Find("UnionSomeType")
55 defaultCtx = NewAttributeContext(false, false, true, "", scope)
56 )
57 tc := []struct {
58 Name string
59 Source *expr.AttributeExpr
60 Target *expr.AttributeExpr
61 Error string
62 }{
63 {"UnionString to UnionStringInt", unionString, unionStringInt, "cannot transform union: number of union types differ (UnionString has 1, UnionStringInt has 2)"},
64 {"UnionString to UnionSomeType", unionString, unionSomeType, "cannot transform union UnionString to UnionSomeType: type at index 0: source is a string but target type is object"},
65 }
66 for _, c := range tc {
67 t.Run(c.Name, func(t *testing.T) {
68 _, _, err := GoTransform(c.Source, c.Target, "source", "target", defaultCtx, defaultCtx, "", true)
69 if err == nil {
70 t.Errorf("unexpected success")
71 return
72 }
73 if err.Error() != c.Error {
74 t.Errorf("unexpected error, got: %s, expected: %s", err, c.Error)
75 }
76 })
77 }
78}

Callers

nothing calls this directly

Calls 9

NewNameScopeFunction · 0.85
NewAttributeContextFunction · 0.85
GoTransformFunction · 0.85
FindMethod · 0.80
UserTypeMethod · 0.80
RunDSLFunction · 0.70
AttributeMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected