Skip to content

Commit 541f863

Browse files
authored
fix: using regex to match uuids and versions (#704)
Made spdx unit tests version agnostic using regex to match uuids and versions
1 parent 6e2e3d7 commit 541f863

1 file changed

Lines changed: 30 additions & 21 deletions

File tree

build_test.go

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"os"
88
"path/filepath"
9+
"regexp"
910
"testing"
1011

1112
dotnetcoreaspnetruntime "github.com/paketo-buildpacks/dotnet-core-aspnet-runtime"
@@ -175,20 +176,28 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
175176
Expect(spdx.Extension).To(Equal("spdx.json"))
176177
content, err = io.ReadAll(spdx.Content)
177178
Expect(err).NotTo(HaveOccurred())
178-
Expect(string(content)).To(MatchJSON(`{
179+
180+
versionPattern := regexp.MustCompile(`"licenseListVersion": "\d+\.\d+"`)
181+
contentReplaced := versionPattern.ReplaceAllString(string(content), `"licenseListVersion": "x.x"`)
182+
183+
uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}`)
184+
185+
contentReplaced = uuidRegex.ReplaceAllString(contentReplaced, "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
186+
187+
Expect(string(contentReplaced)).To(MatchJSON(`{
179188
"SPDXID": "SPDXRef-DOCUMENT",
180-
"creationInfo": {
181-
"created": "0001-01-01T00:00:00Z",
182-
"creators": [
183-
"Organization: Anchore, Inc",
184-
"Tool: -"
185-
],
186-
"licenseListVersion": "3.27"
187-
},
188-
"dataLicense": "CC0-1.0",
189-
"documentNamespace": "https://paketo.io/unknown-source-type/unknown-33ef57ff-45c2-53a8-8899-1c2b7e94d0dd",
190-
"name": "unknown",
191-
"packages": [
189+
"creationInfo": {
190+
"created": "0001-01-01T00:00:00Z",
191+
"creators": [
192+
"Organization: Anchore, Inc",
193+
"Tool: -"
194+
],
195+
"licenseListVersion": "x.x"
196+
},
197+
"dataLicense": "CC0-1.0",
198+
"documentNamespace": "https://paketo.io/unknown-source-type/unknown-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
199+
"name": "unknown",
200+
"packages": [
192201
{
193202
"SPDXID": "SPDXRef-DocumentRoot-Unknown-",
194203
"copyrightText": "NOASSERTION",
@@ -200,14 +209,14 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
200209
"supplier": "NOASSERTION"
201210
}
202211
],
203-
"relationships": [
204-
{
205-
"relatedSpdxElement": "SPDXRef-DocumentRoot-Unknown-",
206-
"relationshipType": "DESCRIBES",
207-
"spdxElementId": "SPDXRef-DOCUMENT"
208-
}
209-
],
210-
"spdxVersion": "SPDX-2.2"
212+
"relationships": [
213+
{
214+
"relatedSpdxElement": "SPDXRef-DocumentRoot-Unknown-",
215+
"relationshipType": "DESCRIBES",
216+
"spdxElementId": "SPDXRef-DOCUMENT"
217+
}
218+
],
219+
"spdxVersion": "SPDX-2.2"
211220
}`))
212221

213222
Expect(result.Launch.BOM).To(HaveLen(1))

0 commit comments

Comments
 (0)