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

Function TestConvertFiles

codegen/service/convert_test.go:307–354  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

305}
306
307func TestConvertFiles(t *testing.T) {
308 cases := []struct {
309 Name string
310 DSL func()
311 ExpectedFiles map[string]int // path -> number of sections
312 }{
313 {
314 "multi-package-conversions",
315 testdata.ConvertMultiPkgDSL,
316 map[string]int{
317 "gen/types/convert.go": 5, // header + 2 convert-to + 2 create-from sections
318 "gen/models/convert.go": 5, // header + 2 convert-to + 2 create-from sections
319 },
320 },
321 }
322
323 for _, c := range cases {
324 t.Run(c.Name, func(t *testing.T) {
325 root := runDSL(t, c.DSL)
326 services := NewServicesData(root)
327
328 for _, svc := range root.Services {
329 files, err := ConvertFiles(root, svc, services)
330 require.NoError(t, err)
331
332 // Check expected number of files
333 require.Equal(t, len(c.ExpectedFiles), len(files))
334
335 // Verify each expected file
336 for expectedPath, expectedSections := range c.ExpectedFiles {
337 found := false
338 // Normalize expected path for cross-platform compatibility
339 normalizedExpected := filepath.FromSlash(expectedPath)
340 for _, file := range files {
341 if strings.HasSuffix(file.Path, normalizedExpected) {
342 found = true
343 require.Equal(t, expectedSections, len(file.SectionTemplates))
344 // First section should be header
345 require.Equal(t, "source-header", file.SectionTemplates[0].Name)
346 break
347 }
348 }
349 require.True(t, found, "Expected file %s not found", expectedPath)
350 }
351 }
352 })
353 }
354}

Callers

nothing calls this directly

Calls 4

ConvertFilesFunction · 0.85
runDSLFunction · 0.70
NewServicesDataFunction · 0.70
RunMethod · 0.45

Tested by

no test coverage detected