TestGenerateParallelSingleFile verifies that parallel file writing works correctly with just a single file (minimal parallelism edge case).
(t *testing.T)
| 252 | // TestGenerateParallelSingleFile verifies that parallel file writing works |
| 253 | // correctly with just a single file (minimal parallelism edge case). |
| 254 | func TestGenerateParallelSingleFile(t *testing.T) { |
| 255 | t.Cleanup(func() { Generators = generators }) |
| 256 | |
| 257 | Generators = func(cmd string) ([]Genfunc, error) { |
| 258 | return []Genfunc{ |
| 259 | func(genpkg string, roots []eval.Root) ([]*codegen.File, error) { |
| 260 | f := &codegen.File{Path: filepath.Join(codegen.Gendir, "types", "single.go")} |
| 261 | f.SectionTemplates = []*codegen.SectionTemplate{ |
| 262 | codegen.Header("Types", "types", nil), |
| 263 | {Name: "type", Source: "type Single struct{}\n"}, |
| 264 | } |
| 265 | return []*codegen.File{f}, nil |
| 266 | }, |
| 267 | }, nil |
| 268 | } |
| 269 | |
| 270 | dir := t.TempDir() |
| 271 | outputs, err := Generate(dir, "gen", false) |
| 272 | if err != nil { |
| 273 | t.Fatalf("Generate failed: %v", err) |
| 274 | } |
| 275 | outputs = assertVersionFile(t, dir, outputs) |
| 276 | |
| 277 | if len(outputs) != 1 { |
| 278 | t.Fatalf("expected 1 output file, got %d", len(outputs)) |
| 279 | } |
| 280 | |
| 281 | outpath := filepath.Join(dir, codegen.Gendir, "types", "single.go") |
| 282 | bs, err := os.ReadFile(outpath) |
| 283 | if err != nil { |
| 284 | t.Fatalf("failed reading file: %v", err) |
| 285 | } |
| 286 | content := string(bs) |
| 287 | if !strings.Contains(content, "type Single struct{}") { |
| 288 | t.Fatalf("file missing expected content:\n%s", content) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | // assertVersionFile checks that goa.json was emitted with the correct version |
| 293 | // and returns the remaining outputs (excluding goa.json) for further assertions. |
nothing calls this directly
no test coverage detected