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

Function TestExampleServiceFiles

codegen/service/example_svc_test.go:14–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestExampleServiceFiles(t *testing.T) {
15 t.Run("package name check", func(t *testing.T) {
16 cases := []struct {
17 Name string
18 DSL func()
19 Expected string
20 }{
21 {
22 Name: "conflict with API name and service names",
23 DSL: testdata.ConflictWithAPINameAndServiceNameDSL,
24 Expected: "package alohaapi2",
25 },
26 {
27 Name: "conflict with goified API name and goified service names",
28 DSL: testdata.ConflictWithGoifiedAPINameAndServiceNamesDSL,
29 Expected: "package goodbyapi2",
30 },
31 }
32 for _, c := range cases {
33 t.Run(c.Name, func(t *testing.T) {
34 root := codegen.RunDSL(t, c.DSL)
35 services := NewServicesData(root)
36 require.Len(t, root.Services, 3)
37 fs := ExampleServiceFiles("", root, services)
38 require.Len(t, fs, 3)
39 for _, f := range fs {
40 require.Greater(t, len(f.SectionTemplates), 0)
41 var b bytes.Buffer
42 require.NoError(t, f.SectionTemplates[0].Write(&b))
43 line, err := b.ReadBytes('\n')
44 require.NoError(t, err)
45 got := string(bytes.TrimRight(line, "\r\n"))
46 assert.Equal(t, c.Expected, got)
47 }
48 })
49 }
50 })
51}

Callers

nothing calls this directly

Calls 5

RunDSLFunction · 0.92
ExampleServiceFilesFunction · 0.85
NewServicesDataFunction · 0.70
RunMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected