Skip to content

Commit

Permalink
chore: add and document target for updating unit snapshots (#3498)
Browse files Browse the repository at this point in the history
* chore: add and document target for updating unit snapshots

Signed-off-by: Will Murphy <[email protected]>

* chore: rename to reflect narrower scope

Signed-off-by: Will Murphy <[email protected]>

---------

Signed-off-by: Will Murphy <[email protected]>
  • Loading branch information
willmurphyscode authored Dec 4, 2024
1 parent 4819023 commit 25e5d55
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,11 @@ package under test and should always be updated by invoking `go test` on the spe
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
compares that SBOM with what is generated from the latest presenter code. For instance, at the time of this writing
the CycloneDX presenter snapshots can be updated by running:
compares that SBOM with what is generated from the latest presenter code. The following command can be used to
update the golden files for the various snapshot tests:

```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.
Expand Down
8 changes: 8 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ 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:
desc: Run unit tests
Expand Down

0 comments on commit 25e5d55

Please sign in to comment.