From 8b16c5548e7400c23f32660f5f5cd795be3c8197 Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Tue, 23 May 2023 17:46:19 -0400 Subject: [PATCH 1/4] fix duplicate shorthand rels for 2.2 Signed-off-by: Brandon Lum --- spdx/v2/v2_2/document.go | 30 +++++- spdx/v2/v2_2/example/example.go | 10 ++ spdx/v2/v2_2/json/json_test.go | 177 +++++++++++++++++++++++++------- 3 files changed, 177 insertions(+), 40 deletions(-) diff --git a/spdx/v2/v2_2/document.go b/spdx/v2/v2_2/document.go index 3bd605f..d94f5b0 100644 --- a/spdx/v2/v2_2/document.go +++ b/spdx/v2/v2_2/document.go @@ -5,8 +5,9 @@ package v2_2 import ( "encoding/json" + "fmt" - "github.com/anchore/go-struct-converter" + converter "github.com/anchore/go-struct-converter" "github.com/spdx/tools-golang/spdx/v2/common" ) @@ -98,27 +99,46 @@ func (d *Document) UnmarshalJSON(b []byte) error { *d = Document(d2) + relationshipExists := map[string]bool{} + serializeRel := func(r *Relationship) string { + return fmt.Sprintf("%v-%v->%v", common.RenderDocElementID(r.RefA), r.Relationship, common.RenderDocElementID(r.RefB)) + } + + // index current list of relationships to ensure no duplication + for _, r := range d.Relationships { + relationshipExists[serializeRel(r)] = true + } + // build relationships for documentDescribes field for _, id := range e.DocumentDescribes { - d.Relationships = append(d.Relationships, &Relationship{ + r := &Relationship{ RefA: common.DocElementID{ ElementRefID: d.SPDXIdentifier, }, RefB: id, Relationship: common.TypeRelationshipDescribe, - }) + } + + if !relationshipExists[serializeRel(r)] { + d.Relationships = append(d.Relationships, r) + relationshipExists[serializeRel(r)] = true + } } // build relationships for package hasFiles field for _, p := range d.Packages { for _, f := range p.hasFiles { - d.Relationships = append(d.Relationships, &Relationship{ + r := &Relationship{ RefA: common.DocElementID{ ElementRefID: p.PackageSPDXIdentifier, }, RefB: f, Relationship: common.TypeRelationshipContains, - }) + } + if !relationshipExists[serializeRel(r)] { + d.Relationships = append(d.Relationships, r) + relationshipExists[serializeRel(r)] = true + } } p.hasFiles = nil diff --git a/spdx/v2/v2_2/example/example.go b/spdx/v2/v2_2/example/example.go index 010ed73..501eb77 100644 --- a/spdx/v2/v2_2/example/example.go +++ b/spdx/v2/v2_2/example/example.go @@ -373,6 +373,16 @@ var example = spdx.Document{ RefB: common.MakeDocElementID("", "Package"), Relationship: "CONTAINS", }, + { + RefA: common.MakeDocElementID("", "Package"), + RefB: common.MakeDocElementID("", "CommonsLangSrc"), + Relationship: "CONTAINS", + }, + { + RefA: common.MakeDocElementID("", "Package"), + RefB: common.MakeDocElementID("", "DoapSource"), + Relationship: "CONTAINS", + }, { RefA: common.MakeDocElementID("", "DOCUMENT"), RefB: common.MakeDocElementID("spdx-tool-1.2", "ToolsElement"), diff --git a/spdx/v2/v2_2/json/json_test.go b/spdx/v2/v2_2/json/json_test.go index d624627..3b87b4b 100644 --- a/spdx/v2/v2_2/json/json_test.go +++ b/spdx/v2/v2_2/json/json_test.go @@ -4,6 +4,7 @@ package json import ( "bytes" + jsonenc "encoding/json" "fmt" "os" "strings" @@ -21,35 +22,6 @@ import ( func TestLoad(t *testing.T) { want := example.Copy() - - want.Relationships = append(want.Relationships, []*spdx.Relationship{ - { - RefA: common.DocElementID{ElementRefID: "DOCUMENT"}, - RefB: common.DocElementID{ElementRefID: "File"}, - Relationship: "DESCRIBES", - }, - { - RefA: common.DocElementID{ElementRefID: "DOCUMENT"}, - RefB: common.DocElementID{ElementRefID: "Package"}, - Relationship: "DESCRIBES", - }, - { - RefA: common.DocElementID{ElementRefID: "Package"}, - RefB: common.DocElementID{ElementRefID: "CommonsLangSrc"}, - Relationship: "CONTAINS", - }, - { - RefA: common.DocElementID{ElementRefID: "Package"}, - RefB: common.DocElementID{ElementRefID: "JenaLib"}, - Relationship: "CONTAINS", - }, - { - RefA: common.DocElementID{ElementRefID: "Package"}, - RefB: common.DocElementID{ElementRefID: "DoapSource"}, - Relationship: "CONTAINS", - }, - }...) - file, err := os.Open("../../../../examples/sample-docs/json/SPDXJSONExample-v2.2.spdx.json") if err != nil { panic(fmt.Errorf("error opening File: %s", err)) @@ -62,8 +34,8 @@ func TestLoad(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after parsing YAML example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) return } } @@ -91,8 +63,8 @@ func Test_Write(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after writing and re-parsing JSON example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after writing and re-parsing JSON example: %s", diff) return } } @@ -149,7 +121,7 @@ func Test_ShorthandFields(t *testing.T) { } } - require.Equal(t, spdx.Document{ + want := spdx.Document{ SPDXVersion: spdx.Version, DataLicense: spdx.DataLicense, SPDXIdentifier: "DOCUMENT", @@ -200,7 +172,136 @@ func Test_ShorthandFields(t *testing.T) { Relationship: common.TypeRelationshipContains, }, }, - }, doc) + } + + if diff := cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}))) + return + } + +} + +func Test_ShorthandFieldsNoDuplicates(t *testing.T) { + contents := `{ + "spdxVersion": "SPDX-2.2", + "dataLicense": "CC0-1.0", + "SPDXID": "SPDXRef-DOCUMENT", + "name": "SPDX-Tools-v2.0", + "documentDescribes": [ + "SPDXRef-Container" + ], + "packages": [ + { + "name": "Container", + "SPDXID": "SPDXRef-Container" + }, + { + "name": "Package-1", + "SPDXID": "SPDXRef-Package-1", + "versionInfo": "1.1.1", + "hasFiles": [ + "SPDXRef-File-1", + "SPDXRef-File-2" + ] + }, + { + "name": "Package-2", + "SPDXID": "SPDXRef-Package-2", + "versionInfo": "2.2.2" + } + ], + "files": [ + { + "fileName": "./f1", + "SPDXID": "SPDXRef-File-1" + }, + { + "fileName": "./f2", + "SPDXID": "SPDXRef-File-2" + } + ], + "relationships": [ + { + "spdxElementId": "SPDXRef-Package-1", + "relationshipType": "CONTAINS", + "relatedSpdxElement": "SPDXRef-File-1" + }, + { + "spdxElementId": "SPDXRef-Package-1", + "relationshipType": "CONTAINS", + "relatedSpdxElement": "SPDXRef-File-2" + } + ] + }` + + doc := spdx.Document{} + err := json.ReadInto(strings.NewReader(contents), &doc) + + require.NoError(t, err) + + id := func(s string) common.DocElementID { + return common.DocElementID{ + ElementRefID: common.ElementID(s), + } + } + + want := spdx.Document{ + SPDXVersion: spdx.Version, + DataLicense: spdx.DataLicense, + SPDXIdentifier: "DOCUMENT", + DocumentName: "SPDX-Tools-v2.0", + Packages: []*spdx.Package{ + { + PackageName: "Container", + PackageSPDXIdentifier: "Container", + FilesAnalyzed: true, + }, + { + PackageName: "Package-1", + PackageSPDXIdentifier: "Package-1", + PackageVersion: "1.1.1", + FilesAnalyzed: true, + }, + { + PackageName: "Package-2", + PackageSPDXIdentifier: "Package-2", + PackageVersion: "2.2.2", + FilesAnalyzed: true, + }, + }, + Files: []*spdx.File{ + { + FileName: "./f1", + FileSPDXIdentifier: "File-1", + }, + { + FileName: "./f2", + FileSPDXIdentifier: "File-2", + }, + }, + Relationships: []*spdx.Relationship{ + { + RefA: id("DOCUMENT"), + RefB: id("Container"), + Relationship: common.TypeRelationshipDescribe, + }, + { + RefA: id("Package-1"), + RefB: id("File-1"), + Relationship: common.TypeRelationshipContains, + }, + { + RefA: id("Package-1"), + RefB: id("File-2"), + Relationship: common.TypeRelationshipContains, + }, + }, + } + + if diff := cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) + return + } } func Test_JsonEnums(t *testing.T) { @@ -344,3 +445,9 @@ func Test_JsonEnums(t *testing.T) { }, }, doc) } + +func relationshipLess(a, b *spdx.Relationship) bool { + aStr, _ := jsonenc.Marshal(a) + bStr, _ := jsonenc.Marshal(b) + return string(aStr) < string(bStr) +} From 3f743e1a0e0a4b1d8e52f5ed440abe14ec5bcaa6 Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Tue, 23 May 2023 17:57:47 -0400 Subject: [PATCH 2/4] fix duplicate shorthand rels for 2.3 Signed-off-by: Brandon Lum --- spdx/v2/v2_3/document.go | 29 ++++++- spdx/v2/v2_3/json/json_test.go | 147 +++++++++++++++++++++++++++++++-- 2 files changed, 166 insertions(+), 10 deletions(-) diff --git a/spdx/v2/v2_3/document.go b/spdx/v2/v2_3/document.go index 9dbb809..279e976 100644 --- a/spdx/v2/v2_3/document.go +++ b/spdx/v2/v2_3/document.go @@ -5,6 +5,7 @@ package v2_3 import ( "encoding/json" + "fmt" converter "github.com/anchore/go-struct-converter" @@ -97,27 +98,47 @@ func (d *Document) UnmarshalJSON(b []byte) error { *d = Document(d2) + relationshipExists := map[string]bool{} + serializeRel := func(r *Relationship) string { + return fmt.Sprintf("%v-%v->%v", common.RenderDocElementID(r.RefA), r.Relationship, common.RenderDocElementID(r.RefB)) + } + + // index current list of relationships to ensure no duplication + for _, r := range d.Relationships { + relationshipExists[serializeRel(r)] = true + } + // build relationships for documentDescribes field for _, id := range e.DocumentDescribes { - d.Relationships = append(d.Relationships, &Relationship{ + r := &Relationship{ RefA: common.DocElementID{ ElementRefID: d.SPDXIdentifier, }, RefB: id, Relationship: common.TypeRelationshipDescribe, - }) + } + + if !relationshipExists[serializeRel(r)] { + d.Relationships = append(d.Relationships, r) + relationshipExists[serializeRel(r)] = true + } } + // build relationships for package hasFiles field // build relationships for package hasFiles field for _, p := range d.Packages { for _, f := range p.hasFiles { - d.Relationships = append(d.Relationships, &Relationship{ + r := &Relationship{ RefA: common.DocElementID{ ElementRefID: p.PackageSPDXIdentifier, }, RefB: f, Relationship: common.TypeRelationshipContains, - }) + } + if !relationshipExists[serializeRel(r)] { + d.Relationships = append(d.Relationships, r) + relationshipExists[serializeRel(r)] = true + } } p.hasFiles = nil diff --git a/spdx/v2/v2_3/json/json_test.go b/spdx/v2/v2_3/json/json_test.go index 6980143..432aad2 100644 --- a/spdx/v2/v2_3/json/json_test.go +++ b/spdx/v2/v2_3/json/json_test.go @@ -4,6 +4,7 @@ package json import ( "bytes" + jsonenc "encoding/json" "flag" "fmt" "os" @@ -52,8 +53,8 @@ func Test_Read(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after parsing YAML example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) return } } @@ -81,8 +82,8 @@ func Test_Write(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after writing and re-parsing JSON example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) return } } @@ -139,7 +140,7 @@ func Test_ShorthandFields(t *testing.T) { } } - require.Equal(t, spdx.Document{ + want := spdx.Document{ SPDXVersion: spdx.Version, DataLicense: spdx.DataLicense, SPDXIdentifier: "DOCUMENT", @@ -190,7 +191,135 @@ func Test_ShorthandFields(t *testing.T) { Relationship: common.TypeRelationshipContains, }, }, - }, doc) + } + + if diff := cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}))) + return + } +} + +func Test_ShorthandFieldsNoDuplicates(t *testing.T) { + contents := `{ + "spdxVersion": "SPDX-2.3", + "dataLicense": "CC0-1.0", + "SPDXID": "SPDXRef-DOCUMENT", + "name": "SPDX-Tools-v2.0", + "documentDescribes": [ + "SPDXRef-Container" + ], + "packages": [ + { + "name": "Container", + "SPDXID": "SPDXRef-Container" + }, + { + "name": "Package-1", + "SPDXID": "SPDXRef-Package-1", + "versionInfo": "1.1.1", + "hasFiles": [ + "SPDXRef-File-1", + "SPDXRef-File-2" + ] + }, + { + "name": "Package-2", + "SPDXID": "SPDXRef-Package-2", + "versionInfo": "2.2.2" + } + ], + "files": [ + { + "fileName": "./f1", + "SPDXID": "SPDXRef-File-1" + }, + { + "fileName": "./f2", + "SPDXID": "SPDXRef-File-2" + } + ], + "relationships": [ + { + "spdxElementId": "SPDXRef-Package-1", + "relationshipType": "CONTAINS", + "relatedSpdxElement": "SPDXRef-File-1" + }, + { + "spdxElementId": "SPDXRef-Package-1", + "relationshipType": "CONTAINS", + "relatedSpdxElement": "SPDXRef-File-2" + } + ] + }` + + doc := spdx.Document{} + err := json.ReadInto(strings.NewReader(contents), &doc) + + require.NoError(t, err) + + id := func(s string) common.DocElementID { + return common.DocElementID{ + ElementRefID: common.ElementID(s), + } + } + + want := spdx.Document{ + SPDXVersion: spdx.Version, + DataLicense: spdx.DataLicense, + SPDXIdentifier: "DOCUMENT", + DocumentName: "SPDX-Tools-v2.0", + Packages: []*spdx.Package{ + { + PackageName: "Container", + PackageSPDXIdentifier: "Container", + FilesAnalyzed: true, + }, + { + PackageName: "Package-1", + PackageSPDXIdentifier: "Package-1", + PackageVersion: "1.1.1", + FilesAnalyzed: true, + }, + { + PackageName: "Package-2", + PackageSPDXIdentifier: "Package-2", + PackageVersion: "2.2.2", + FilesAnalyzed: true, + }, + }, + Files: []*spdx.File{ + { + FileName: "./f1", + FileSPDXIdentifier: "File-1", + }, + { + FileName: "./f2", + FileSPDXIdentifier: "File-2", + }, + }, + Relationships: []*spdx.Relationship{ + { + RefA: id("DOCUMENT"), + RefB: id("Container"), + Relationship: common.TypeRelationshipDescribe, + }, + { + RefA: id("Package-1"), + RefB: id("File-1"), + Relationship: common.TypeRelationshipContains, + }, + { + RefA: id("Package-1"), + RefB: id("File-2"), + Relationship: common.TypeRelationshipContains, + }, + }, + } + + if diff := cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) + return + } } func Test_JsonEnums(t *testing.T) { @@ -334,3 +463,9 @@ func Test_JsonEnums(t *testing.T) { }, }, doc) } + +func relationshipLess(a, b *spdx.Relationship) bool { + aStr, _ := jsonenc.Marshal(a) + bStr, _ := jsonenc.Marshal(b) + return string(aStr) < string(bStr) +} From 6b2ab7af0e62c49db66b14c50a0e302cb12a416f Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Wed, 24 May 2023 09:57:45 -0400 Subject: [PATCH 3/4] update yaml tests to ignore order of relationships Signed-off-by: Brandon Lum --- spdx/v2/v2_2/yaml/yaml_test.go | 44 +++++++++------------------------- spdx/v2/v2_3/yaml/yaml_test.go | 15 ++++++++---- 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/spdx/v2/v2_2/yaml/yaml_test.go b/spdx/v2/v2_2/yaml/yaml_test.go index bacfc80..404a261 100644 --- a/spdx/v2/v2_2/yaml/yaml_test.go +++ b/spdx/v2/v2_2/yaml/yaml_test.go @@ -4,6 +4,7 @@ package yaml import ( "bytes" + jsonenc "encoding/json" "fmt" "os" "testing" @@ -11,7 +12,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/spdx/tools-golang/spdx/v2/common" spdx "github.com/spdx/tools-golang/spdx/v2/v2_2" "github.com/spdx/tools-golang/spdx/v2/v2_2/example" "github.com/spdx/tools-golang/yaml" @@ -20,34 +20,6 @@ import ( func Test_Read(t *testing.T) { want := example.Copy() - want.Relationships = append(want.Relationships, []*spdx.Relationship{ - { - RefA: common.DocElementID{ElementRefID: "DOCUMENT"}, - RefB: common.DocElementID{ElementRefID: "File"}, - Relationship: "DESCRIBES", - }, - { - RefA: common.DocElementID{ElementRefID: "DOCUMENT"}, - RefB: common.DocElementID{ElementRefID: "Package"}, - Relationship: "DESCRIBES", - }, - { - RefA: common.DocElementID{ElementRefID: "Package"}, - RefB: common.DocElementID{ElementRefID: "CommonsLangSrc"}, - Relationship: "CONTAINS", - }, - { - RefA: common.DocElementID{ElementRefID: "Package"}, - RefB: common.DocElementID{ElementRefID: "JenaLib"}, - Relationship: "CONTAINS", - }, - { - RefA: common.DocElementID{ElementRefID: "Package"}, - RefB: common.DocElementID{ElementRefID: "DoapSource"}, - Relationship: "CONTAINS", - }, - }...) - file, err := os.Open("../../../../examples/sample-docs/yaml/SPDXYAMLExample-2.2.spdx.yaml") if err != nil { panic(fmt.Errorf("error opening File: %s", err)) @@ -60,8 +32,8 @@ func Test_Read(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after parsing YAML example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing YAML example: %s", diff) return } } @@ -88,8 +60,14 @@ func Test_Write(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after writing and re-parsing YAML example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after writing and re-parsing YAML example: %s", diff) return } } + +func relationshipLess(a, b *spdx.Relationship) bool { + aStr, _ := jsonenc.Marshal(a) + bStr, _ := jsonenc.Marshal(b) + return string(aStr) < string(bStr) +} diff --git a/spdx/v2/v2_3/yaml/yaml_test.go b/spdx/v2/v2_3/yaml/yaml_test.go index 766a7c3..c0f787d 100644 --- a/spdx/v2/v2_3/yaml/yaml_test.go +++ b/spdx/v2/v2_3/yaml/yaml_test.go @@ -4,6 +4,7 @@ package yaml import ( "bytes" + jsonenc "encoding/json" "flag" "fmt" "os" @@ -47,8 +48,8 @@ func Test_Read(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after parsing YAML example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing YAML example: %s", diff) return } } @@ -76,8 +77,14 @@ func Test_Write(t *testing.T) { return } - if !cmp.Equal(want, got, cmpopts.IgnoreUnexported(spdx.Package{})) { - t.Errorf("got incorrect struct after writing and re-parsing YAML example: %s", cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}))) + if diff := cmp.Diff(want, got, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { + t.Errorf("got incorrect struct after parsing YAML example: %s", diff) return } } + +func relationshipLess(a, b *spdx.Relationship) bool { + aStr, _ := jsonenc.Marshal(a) + bStr, _ := jsonenc.Marshal(b) + return string(aStr) < string(bStr) +} From fb0f8d8b593f51a2a60014d48a02c1b0d20d3b34 Mon Sep 17 00:00:00 2001 From: Brandon Lum Date: Fri, 26 May 2023 11:52:20 -0400 Subject: [PATCH 4/4] address pr comments Signed-off-by: Brandon Lum --- spdx/v2/v2_2/json/json_test.go | 2 +- spdx/v2/v2_3/json/json_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spdx/v2/v2_2/json/json_test.go b/spdx/v2/v2_2/json/json_test.go index 3b87b4b..a4a0275 100644 --- a/spdx/v2/v2_2/json/json_test.go +++ b/spdx/v2/v2_2/json/json_test.go @@ -175,7 +175,7 @@ func Test_ShorthandFields(t *testing.T) { } if diff := cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { - t.Errorf("got incorrect struct after parsing JSON example: %s", cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}))) + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) return } diff --git a/spdx/v2/v2_3/json/json_test.go b/spdx/v2/v2_3/json/json_test.go index 432aad2..ea648df 100644 --- a/spdx/v2/v2_3/json/json_test.go +++ b/spdx/v2/v2_3/json/json_test.go @@ -194,7 +194,7 @@ func Test_ShorthandFields(t *testing.T) { } if diff := cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}), cmpopts.SortSlices(relationshipLess)); len(diff) > 0 { - t.Errorf("got incorrect struct after parsing JSON example: %s", cmp.Diff(want, doc, cmpopts.IgnoreUnexported(spdx.Package{}))) + t.Errorf("got incorrect struct after parsing JSON example: %s", diff) return } }