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

Function TestGoTransformUnion

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

Source from the content-addressed store, hash-verified

11)
12
13func TestGoTransformUnion(t *testing.T) {
14 root := RunDSL(t, testdata.TestUnionDSL)
15 var (
16 scope = NewNameScope()
17
18 // types to test
19 unionString = root.UserType("Container").Attribute().Find("UnionString").Find("UnionString")
20 unionString2 = root.UserType("Container").Attribute().Find("UnionString2").Find("UnionString2")
21 unionStringInt = root.UserType("Container").Attribute().Find("UnionStringInt").Find("UnionStringInt")
22 unionStringInt2 = root.UserType("Container").Attribute().Find("UnionStringInt2").Find("UnionStringInt2")
23 unionSomeType = root.UserType("Container").Attribute().Find("UnionSomeType").Find("UnionSomeType")
24 unionSomeType2 = root.UserType("Container").Attribute().Find("UnionSomeType2").Find("UnionSomeType2")
25 defaultCtx = NewAttributeContext(false, false, true, "", scope)
26 )
27 tc := []struct {
28 Name string
29 Source *expr.AttributeExpr
30 Target *expr.AttributeExpr
31 }{
32 {"UnionString to UnionString2", unionString, unionString2},
33 {"UnionStringInt to UnionStringInt2", unionStringInt, unionStringInt2},
34 {"UnionSomeType to UnionSomeType2", unionSomeType, unionSomeType2},
35 }
36 for _, c := range tc {
37 t.Run(c.Name, func(t *testing.T) {
38 code, _, err := GoTransform(c.Source, c.Target, "source", "target", defaultCtx, defaultCtx, "", true)
39 require.NoError(t, err)
40 code = FormatTestCode(t, "package foo\nfunc transform(){\n"+code+"}")
41 testutil.AssertGo(t, "testdata/golden/go_transform_union_"+c.Name+".go.golden", code)
42 })
43 }
44}
45
46func TestGoTransformUnionError(t *testing.T) {
47 root := RunDSL(t, testdata.TestUnionDSL)

Callers

nothing calls this directly

Calls 10

AssertGoFunction · 0.92
NewNameScopeFunction · 0.85
NewAttributeContextFunction · 0.85
GoTransformFunction · 0.85
FormatTestCodeFunction · 0.85
FindMethod · 0.80
UserTypeMethod · 0.80
RunDSLFunction · 0.70
AttributeMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected