From 0ad8c53ec2a9ad489633410acb998759fdd4cb3c Mon Sep 17 00:00:00 2001 From: Dan Luhring Date: Tue, 17 Nov 2020 10:07:20 -0500 Subject: [PATCH] Fix cyclonedx test fixture usage of dynamic digest value Signed-off-by: Dan Luhring --- syft/presenter/cyclonedx/presenter_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/syft/presenter/cyclonedx/presenter_test.go b/syft/presenter/cyclonedx/presenter_test.go index a4ba735fd..8829b6ec5 100644 --- a/syft/presenter/cyclonedx/presenter_test.go +++ b/syft/presenter/cyclonedx/presenter_test.go @@ -156,6 +156,14 @@ func TestCycloneDxImgsPresenter(t *testing.T) { t.Fatal(err) } + // This accounts for the non-deterministic digest value that we end up with when + // we build a container image dynamically during testing. Ultimately, we should + // use a golden image as a test fixture in place of building this image during + // testing. At that time, this line will no longer be necessary. + // + // This value is sourced from the "version" node in "./test-fixtures/snapshot/TestCycloneDxImgsPresenter.golden" + s.Metadata.ImageMetadata.Digest = "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368" + pres := NewPresenter(catalog, s.Metadata, d) // run presenter @@ -177,7 +185,7 @@ func TestCycloneDxImgsPresenter(t *testing.T) { if !bytes.Equal(expected, actual) { dmp := diffmatchpatch.New() - diffs := dmp.DiffMain(string(actual), string(expected), true) + diffs := dmp.DiffMain(string(expected), string(actual), true) t.Errorf("mismatched output:\n%s", dmp.DiffPrettyText(diffs)) } }