From 25e5d555efcd79e03e8178a54b8a3b55f310eeb8 Mon Sep 17 00:00:00 2001 From: William Murphy Date: Wed, 4 Dec 2024 15:21:07 -0500 Subject: [PATCH] chore: add and document target for updating unit snapshots (#3498) * chore: add and document target for updating unit snapshots Signed-off-by: Will Murphy * chore: rename to reflect narrower scope Signed-off-by: Will Murphy --------- Signed-off-by: Will Murphy --- DEVELOPING.md | 6 +++--- Taskfile.yaml | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index 5dd88e2746e9..fd14963dfd52 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -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. diff --git a/Taskfile.yaml b/Taskfile.yaml index 5e7f2c000ee8..248e2c8ee74a 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -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