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

Function TestViews

codegen/service/views_test.go:16–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestViews(t *testing.T) {
17 cases := []struct {
18 Name string
19 DSL func()
20 Code string
21 }{
22 {"result-with-multiple-views", testdata.ResultWithMultipleViewsDSL, testdata.ResultWithMultipleViewsCode},
23 {"result-collection-multiple-views", testdata.ResultCollectionMultipleViewsDSL, testdata.ResultCollectionMultipleViewsCode},
24 {"result-with-user-type", testdata.ResultWithUserTypeDSL, testdata.ResultWithUserTypeCode},
25 {"result-with-result-type", testdata.ResultWithResultTypeDSL, testdata.ResultWithResultTypeCode},
26 {"result-with-recursive-result-type", testdata.ResultWithRecursiveResultTypeDSL, testdata.ResultWithRecursiveResultTypeCode},
27 {"result-type-with-custom-fields", testdata.ResultWithCustomFieldsDSL, testdata.ResultWithCustomFieldsCode},
28 {"result-with-recursive-collection-of-result-type", testdata.ResultWithRecursiveCollectionOfResultTypeDSL, testdata.ResultWithRecursiveCollectionOfResultTypeCode},
29 {"result-with-multiple-methods", testdata.ResultWithMultipleMethodsDSL, testdata.ResultWithMultipleMethodsCode},
30 {"result-with-enum-type", testdata.ResultWithEnumTypeDSL, testdata.ResultWithEnumType},
31 {"result-with-pkg-path", testdata.ResultWithPkgPathDSL, testdata.ResultWithPkgPathCode},
32 {"result-with-oneof-in-result-type", testdata.ResultWithOneOfInResultTypeDSL, testdata.ResultWithOneOfInResultTypeCode},
33 }
34 for _, c := range cases {
35 t.Run(c.Name, func(t *testing.T) {
36 root := codegen.RunDSL(t, c.DSL)
37 services := NewServicesData(root)
38 require.Len(t, root.Services, 1)
39 fs := ViewsFile("goa.design/goa/example", root.Services[0], services)
40 require.NotNil(t, fs)
41 buf := new(bytes.Buffer)
42 for _, s := range fs.SectionTemplates[1:] {
43 require.NoError(t, s.Write(buf))
44 }
45 bs, err := format.Source(buf.Bytes())
46 require.NoError(t, err, buf.String())
47 code := string(bs)
48 code = strings.ReplaceAll(code, "\r\n", "\n")
49 assert.Equal(t, c.Code, code)
50 })
51 }
52}

Callers

nothing calls this directly

Calls 6

RunDSLFunction · 0.92
ViewsFileFunction · 0.85
NewServicesDataFunction · 0.70
StringMethod · 0.65
RunMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected