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

Function TestExampleServerFiles

http/codegen/example_server_test.go:19–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestExampleServerFiles(t *testing.T) {
20 t.Run("package name check", func(t *testing.T) {
21 cases := []struct {
22 Name string
23 DSL func()
24 Expected string
25 }{
26 {
27 Name: "conflict with API name and service names including multipart",
28 DSL: ctestdata.ConflictWithAPINameAndServiceNamesIncludingMultipartDSL,
29 Expected: "package alohaapi2",
30 },
31 }
32 for _, c := range cases {
33 t.Run(c.Name, func(t *testing.T) {
34 // reset global variable
35 example.Servers = make(example.ServersData)
36 root := codegen.RunDSL(t, c.DSL)
37 require.Len(t, root.Services, 3)
38 httpServices := NewServicesData(service.NewServicesData(root), root.API.HTTP)
39 fs := ExampleServerFiles("", httpServices)
40 require.Len(t, fs, 2)
41 for i, f := range fs {
42 if i < len(fs)-1 {
43 // Skip example http server.
44 continue
45 }
46 require.Greater(t, len(f.SectionTemplates), 0)
47 var b bytes.Buffer
48 require.NoError(t, f.SectionTemplates[0].Write(&b))
49 line, err := b.ReadBytes('\n')
50 assert.NoError(t, err)
51 got := string(bytes.TrimRight(line, "\n"))
52 assert.Equal(t, c.Expected, got)
53 }
54 })
55 }
56 })
57
58 t.Run("code check", func(t *testing.T) {
59 cases := []struct {
60 Name string
61 DSL func()
62 }{
63 {"no-server", ctestdata.NoServerDSL},
64 {"server-hosting-service-with-file-server", ctestdata.ServerHostingServiceWithFileServerDSL},
65 {"server-hosting-service-subset", ctestdata.ServerHostingServiceSubsetDSL},
66 {"server-hosting-multiple-services", ctestdata.ServerHostingMultipleServicesDSL},
67 {"streaming", testdata.StreamingMultipleServicesDSL},
68 }
69 for _, c := range cases {
70 t.Run(c.Name, func(t *testing.T) {
71 // reset global variable
72 example.Servers = make(example.ServersData)
73 root := codegen.RunDSL(t, c.DSL)
74 httpServices := NewServicesData(service.NewServicesData(root), root.API.HTTP)
75 fs := ExampleServerFiles("", httpServices)
76 require.Len(t, fs, 1)

Callers

nothing calls this directly

Calls 9

RunDSLFunction · 0.92
NewServicesDataFunction · 0.92
FormatTestCodeFunction · 0.92
CompareOrUpdateGoldenFunction · 0.92
NewServicesDataFunction · 0.70
ExampleServerFilesFunction · 0.70
StringMethod · 0.65
RunMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected