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

Function TestStructPkgPath_UnionImportsJSON

codegen/service/service_test.go:154–177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

152}
153
154func TestStructPkgPath_UnionImportsJSON(t *testing.T) {
155 root := codegen.RunDSL(t, testdata.PkgPathUnionDSL)
156 services := NewServicesData(root)
157 require.Len(t, root.Services, 1)
158
159 files := Files("goa.design/goa/example", root.Services[0], services, make(map[string][]string))
160 require.GreaterOrEqual(t, len(files), 2, "expected at least service.go + one struct:pkg:path file")
161
162 var typeFile *codegen.File
163 for _, f := range files {
164 if strings.HasSuffix(f.Path, filepath.Join("gen", "types", "type_with_union.go")) {
165 typeFile = f
166 break
167 }
168 }
169 require.NotNil(t, typeFile, "expected generated type file for struct:pkg:path type_with_union")
170
171 buf := new(bytes.Buffer)
172 for _, s := range typeFile.SectionTemplates {
173 require.NoError(t, s.Write(buf))
174 }
175 code := buf.String()
176 require.Contains(t, code, "\"encoding/json\"", "expected encoding/json import in generated file:\n%s", code)
177}
178
179func TestStructPkgPath_UnionJSONFieldBranchesGenerateAliases(t *testing.T) {
180 root := codegen.RunDSL(t, testdata.PkgPathUnionJSONFieldDSL)

Callers

nothing calls this directly

Calls 5

RunDSLFunction · 0.92
NewServicesDataFunction · 0.70
FilesFunction · 0.70
StringMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected