chore: add and document target for updating unit snapshots (#3498)

* chore: add and document target for updating unit snapshots

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>

* chore: rename to reflect narrower scope

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>

---------

Signed-off-by: Will Murphy <willmurphyscode@users.noreply.github.com>
This commit is contained in:
William Murphy 2024-12-04 15:21:07 -05:00 committed by GitHub
parent 48190233f4
commit 25e5d555ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -367,11 +367,11 @@ package under test and should always be updated by invoking `go test` on the spe
update flag provided. update flag provided.
Many of the `Format` tests make use of this approach, where the raw SBOM report is saved in the repo and the test Many of the `Format` tests make use of this approach, where the raw SBOM report is saved in the repo and the test
compares that SBOM with what is generated from the latest presenter code. For instance, at the time of this writing compares that SBOM with what is generated from the latest presenter code. The following command can be used to
the CycloneDX presenter snapshots can be updated by running: update the golden files for the various snapshot tests:
```bash ```bash
go test ./internal/formats -update-cyclonedx make update-format-golden-files
``` ```
These flags are defined at the top of the test files that have tests that use the snapshot files. These flags are defined at the top of the test files that have tests that use the snapshot files.

View File

@ -191,6 +191,14 @@ tasks:
## Testing tasks ################################# ## Testing tasks #################################
update-format-golden-files:
desc: "Update golden (i.e. snapshot) files used by unit tests"
cmds:
- go test ./syft/format/spdxjson -update-spdx-json
- go test ./syft/format/spdxtagvalue -update-spdx-tv
- go test ./syft/format/cyclonedxxml -update-cyclonedx-xml
- go test ./syft/format/cyclonedxjson -update-cyclonedx-json
- go test ./syft/format/syftjson -update-json
unit: unit:
desc: Run unit tests desc: Run unit tests