Skip to content

[Enhancement] bomio.WriteOutputFiles has no tests: filename sanitization and multi-BOM output are untested #27

@wiebe-vandendriessche

Description

@wiebe-vandendriessche

Problem or motivation

pkg/aibomgen/bomio.WriteOutputFiles generates output filenames by sanitizing the component name (replacing non-alphanumeric characters with underscores) and writing one file per discovered BOM. This function is the final step of both scan and generate commands and is not covered by any test in io_test.go. The sanitization logic (for _, r := range name { ... }) has edge cases: an all-special-character name produces "model" as fallback; a BOM with no metadata component name falls back through three sources. None of these paths are tested.

Proposed solution

Add tests to pkg/aibomgen/bomio/io_test.go covering:

  • A single BOM with a normal org/model name — verify the output filename is org_model_aibom.json
  • A BOM with an empty component name — verify fallback to Discovery.Name, then Discovery.ID, then "model"
  • Two BOMs with the same sanitized name — verify both are written (potential collision case)
  • A BOM where WriteBOM would fail (unwritable directory) — verify the error is propagated and written contains only successfully written paths

Alternatives considered

None.

Additional context

Affected function: pkg/aibomgen/bomio/io.go:WriteOutputFiles (line 188).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttestsWrite tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions