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

Function TestGoTransformHelpers

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

Source from the content-addressed store, hash-verified

11)
12
13func TestGoTransformHelpers(t *testing.T) {
14 root := RunDSL(t, testdata.TestTypesDSL)
15 var (
16 scope = NewNameScope()
17 // types to test
18 simple = root.UserType("Simple")
19 recursive = root.UserType("Recursive")
20 composite = root.UserType("Composite")
21 deep = root.UserType("Deep")
22 deepArray = root.UserType("DeepArray")
23 simpleAlias = root.UserType("SimpleAlias")
24 mapAlias = root.UserType("NestedMapAlias")
25 arrayMapAlias = root.UserType("ArrayMapAlias")
26 collection = root.UserType("ResultTypeCollection")
27 // attribute contexts used in test cases
28 defaultCtx = NewAttributeContext(false, false, true, "", scope)
29 )
30 tc := []struct {
31 Name string
32 Type expr.DataType
33 HelperNames []string
34 }{
35 {"simple", simple, nil},
36 {"recursive", recursive, []string{"transformRecursiveToRecursive"}},
37 {"composite", composite, []string{"transformSimpleToSimple"}},
38 {"deep", deep, []string{"transformCompositeToComposite", "transformSimpleToSimple"}},
39 {"deep-array", deepArray, []string{"transformCompositeToComposite", "transformSimpleToSimple"}},
40 {"simple-alias", simpleAlias, nil},
41 {"nested-map-alias", mapAlias, nil},
42 {"array-map-alias", arrayMapAlias, nil},
43 {"result-type-collection", collection, []string{"transformResultTypeToResultType"}},
44 }
45 for _, c := range tc {
46 t.Run(c.Name, func(t *testing.T) {
47 require.NotNil(t, c.Type, "source type not found in testdata")
48 _, funcs, err := GoTransform(&expr.AttributeExpr{Type: c.Type}, &expr.AttributeExpr{Type: c.Type}, "source", "target", defaultCtx, defaultCtx, "", true)
49 require.NoError(t, err)
50 assert.Equal(t, len(c.HelperNames), len(funcs), "invalid helpers count")
51 var actual []string
52 if len(funcs) > 0 {
53 actual = make([]string, len(funcs))
54 for i, f := range funcs {
55 actual[i] = f.Name
56 }
57 }
58 assert.Equal(t, c.HelperNames, actual, "invalid helper names")
59 })
60 }
61}

Callers

nothing calls this directly

Calls 6

NewNameScopeFunction · 0.85
NewAttributeContextFunction · 0.85
GoTransformFunction · 0.85
UserTypeMethod · 0.80
RunDSLFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected