diff --git a/converter/converter.go b/converter/converter.go index 3e50e8f4..a88f54c6 100644 --- a/converter/converter.go +++ b/converter/converter.go @@ -110,7 +110,7 @@ func ToSPDX23(r *scalibr.ScanResult, c SPDXConfig) *v2_3.Document { IsFilesAnalyzedTagPresent: false, PackageSourceInfo: pSourceInfo, PackageExternalReferences: []*v2_3.PackageExternalReference{ - &v2_3.PackageExternalReference{ + { Category: "PACKAGE-MANAGER", RefType: "purl", Locator: p.String(), @@ -138,7 +138,7 @@ func ToSPDX23(r *scalibr.ScanResult, c SPDXConfig) *v2_3.Document { namespace = "https://spdx.google/" + uuid.New().String() } creators := []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, diff --git a/converter/converter_test.go b/converter/converter_test.go index c9b8817a..21e89acb 100644 --- a/converter/converter_test.go +++ b/converter/converter_test.go @@ -47,7 +47,7 @@ func TestToSPDX23(t *testing.T) { { desc: "Package with no custom config", scanResult: &scalibr.ScanResult{ - Inventories: []*extractor.Inventory{&extractor.Inventory{ + Inventories: []*extractor.Inventory{{ Name: "software", Version: "1.2.3", Extractor: pipEx, }}, }, @@ -59,14 +59,14 @@ func TestToSPDX23(t *testing.T) { DocumentNamespace: "https://spdx.google/81855ad8-681d-4d86-91e9-1e00167939cb", CreationInfo: &v2_3.CreationInfo{ Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, }, }, Packages: []*v2_3.Package{ - &v2_3.Package{ + { PackageName: "main", PackageSPDXIdentifier: "SPDXRef-Package-main-52fdfc07-2182-454f-963f-5f0f9a621d72", PackageVersion: "0", @@ -77,7 +77,7 @@ func TestToSPDX23(t *testing.T) { PackageDownloadLocation: converter.NoAssertion, IsFilesAnalyzedTagPresent: false, }, - &v2_3.Package{ + { PackageName: "software", PackageSPDXIdentifier: "SPDXRef-Package-software-9566c74d-1003-4c4d-bbbb-0407d1e2c649", PackageVersion: "1.2.3", @@ -89,7 +89,7 @@ func TestToSPDX23(t *testing.T) { IsFilesAnalyzedTagPresent: false, PackageSourceInfo: "Identified by the python/wheelegg extractor", PackageExternalReferences: []*v2_3.PackageExternalReference{ - &v2_3.PackageExternalReference{ + { Category: "PACKAGE-MANAGER", RefType: "purl", Locator: "pkg:pypi/software@1.2.3", @@ -98,7 +98,7 @@ func TestToSPDX23(t *testing.T) { }, }, Relationships: []*v2_3.Relationship{ - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-main-52fdfc07-2182-454f-963f-5f0f9a621d72", }, @@ -107,7 +107,7 @@ func TestToSPDX23(t *testing.T) { }, Relationship: "CONTAINS", }, - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-software-9566c74d-1003-4c4d-bbbb-0407d1e2c649", }, @@ -122,7 +122,7 @@ func TestToSPDX23(t *testing.T) { { desc: "Package with custom config", scanResult: &scalibr.ScanResult{ - Inventories: []*extractor.Inventory{&extractor.Inventory{ + Inventories: []*extractor.Inventory{{ Name: "software", Version: "1.2.3", Extractor: pipEx, }}, }, @@ -130,7 +130,7 @@ func TestToSPDX23(t *testing.T) { DocumentName: "Custom name", DocumentNamespace: "Custom namespace", Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Person", Creator: "Custom creator", }, @@ -144,18 +144,18 @@ func TestToSPDX23(t *testing.T) { DocumentNamespace: "Custom namespace", CreationInfo: &v2_3.CreationInfo{ Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, - common.Creator{ + { CreatorType: "Person", Creator: "Custom creator", }, }, }, Packages: []*v2_3.Package{ - &v2_3.Package{ + { PackageName: "main", PackageSPDXIdentifier: "SPDXRef-Package-main-6694d2c4-22ac-4208-a007-2939487f6999", PackageVersion: "0", @@ -166,7 +166,7 @@ func TestToSPDX23(t *testing.T) { PackageDownloadLocation: converter.NoAssertion, IsFilesAnalyzedTagPresent: false, }, - &v2_3.Package{ + { PackageName: "software", PackageSPDXIdentifier: "SPDXRef-Package-software-eb9d18a4-4784-445d-87f3-c67cf22746e9", PackageVersion: "1.2.3", @@ -178,7 +178,7 @@ func TestToSPDX23(t *testing.T) { IsFilesAnalyzedTagPresent: false, PackageSourceInfo: "Identified by the python/wheelegg extractor", PackageExternalReferences: []*v2_3.PackageExternalReference{ - &v2_3.PackageExternalReference{ + { Category: "PACKAGE-MANAGER", RefType: "purl", Locator: "pkg:pypi/software@1.2.3", @@ -187,7 +187,7 @@ func TestToSPDX23(t *testing.T) { }, }, Relationships: []*v2_3.Relationship{ - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-main-6694d2c4-22ac-4208-a007-2939487f6999", }, @@ -196,7 +196,7 @@ func TestToSPDX23(t *testing.T) { }, Relationship: "CONTAINS", }, - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-software-eb9d18a4-4784-445d-87f3-c67cf22746e9", }, @@ -213,13 +213,13 @@ func TestToSPDX23(t *testing.T) { scanResult: &scalibr.ScanResult{ Inventories: []*extractor.Inventory{ // PURL field missing - &extractor.Inventory{Extractor: pipEx}, + {Extractor: pipEx}, // No name - &extractor.Inventory{ + { Version: "1.2.3", Extractor: pipEx, }, // No version - &extractor.Inventory{ + { Name: "software", Extractor: pipEx, }, }, @@ -232,13 +232,13 @@ func TestToSPDX23(t *testing.T) { DocumentNamespace: "https://spdx.google/5fb90bad-b37c-4821-b6d9-5526a41a9504", CreationInfo: &v2_3.CreationInfo{ Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, }, }, - Packages: []*v2_3.Package{&v2_3.Package{ + Packages: []*v2_3.Package{{ PackageName: "main", PackageSPDXIdentifier: "SPDXRef-Package-main-95af5a25-3679-41ba-a2ff-6cd471c483f1", PackageVersion: "0", @@ -255,7 +255,7 @@ func TestToSPDX23(t *testing.T) { { desc: "Invalid chars in package name replaced", scanResult: &scalibr.ScanResult{ - Inventories: []*extractor.Inventory{&extractor.Inventory{ + Inventories: []*extractor.Inventory{{ Name: "softw@re&", Version: "1.2.3", Extractor: pipEx, }}, }, @@ -267,14 +267,14 @@ func TestToSPDX23(t *testing.T) { DocumentNamespace: "https://spdx.google/0f070244-8615-4bda-8831-3f6a8eb668d2", CreationInfo: &v2_3.CreationInfo{ Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, }, }, Packages: []*v2_3.Package{ - &v2_3.Package{ + { PackageName: "main", PackageSPDXIdentifier: "SPDXRef-Package-main-680b4e7c-8b76-4a1b-9d49-d4955c848621", PackageVersion: "0", @@ -285,7 +285,7 @@ func TestToSPDX23(t *testing.T) { PackageDownloadLocation: converter.NoAssertion, IsFilesAnalyzedTagPresent: false, }, - &v2_3.Package{ + { PackageName: "softw@re&", PackageSPDXIdentifier: "SPDXRef-Package-softw-re--6325253f-ec73-4dd7-a9e2-8bf921119c16", PackageVersion: "1.2.3", @@ -297,7 +297,7 @@ func TestToSPDX23(t *testing.T) { IsFilesAnalyzedTagPresent: false, PackageSourceInfo: "Identified by the python/wheelegg extractor", PackageExternalReferences: []*v2_3.PackageExternalReference{ - &v2_3.PackageExternalReference{ + { Category: "PACKAGE-MANAGER", RefType: "purl", Locator: "pkg:pypi/softw%40re%26@1.2.3", @@ -306,7 +306,7 @@ func TestToSPDX23(t *testing.T) { }, }, Relationships: []*v2_3.Relationship{ - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-main-680b4e7c-8b76-4a1b-9d49-d4955c848621", }, @@ -315,7 +315,7 @@ func TestToSPDX23(t *testing.T) { }, Relationship: "CONTAINS", }, - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-softw-re--6325253f-ec73-4dd7-a9e2-8bf921119c16", }, @@ -330,7 +330,7 @@ func TestToSPDX23(t *testing.T) { { desc: "One location reported", scanResult: &scalibr.ScanResult{ - Inventories: []*extractor.Inventory{&extractor.Inventory{ + Inventories: []*extractor.Inventory{{ Name: "software", Version: "1.2.3", Extractor: pipEx, Locations: []string{"/file1"}, }}, }, @@ -342,14 +342,14 @@ func TestToSPDX23(t *testing.T) { DocumentNamespace: "https://spdx.google/6bf84c71-74cb-4476-b64c-c3dbd968b0f7", CreationInfo: &v2_3.CreationInfo{ Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, }, }, Packages: []*v2_3.Package{ - &v2_3.Package{ + { PackageName: "main", PackageSPDXIdentifier: "SPDXRef-Package-main-0bf50598-7592-4e66-8a5b-df2c7fc48445", PackageVersion: "0", @@ -360,7 +360,7 @@ func TestToSPDX23(t *testing.T) { PackageDownloadLocation: converter.NoAssertion, IsFilesAnalyzedTagPresent: false, }, - &v2_3.Package{ + { PackageName: "software", PackageSPDXIdentifier: "SPDXRef-Package-software-92d2572b-cd06-48d2-96c5-2f5054e2d083", PackageVersion: "1.2.3", @@ -372,7 +372,7 @@ func TestToSPDX23(t *testing.T) { IsFilesAnalyzedTagPresent: false, PackageSourceInfo: "Identified by the python/wheelegg extractor from /file1", PackageExternalReferences: []*v2_3.PackageExternalReference{ - &v2_3.PackageExternalReference{ + { Category: "PACKAGE-MANAGER", RefType: "purl", Locator: "pkg:pypi/software@1.2.3", @@ -381,7 +381,7 @@ func TestToSPDX23(t *testing.T) { }, }, Relationships: []*v2_3.Relationship{ - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-main-0bf50598-7592-4e66-8a5b-df2c7fc48445", }, @@ -390,7 +390,7 @@ func TestToSPDX23(t *testing.T) { }, Relationship: "CONTAINS", }, - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-software-92d2572b-cd06-48d2-96c5-2f5054e2d083", }, @@ -405,7 +405,7 @@ func TestToSPDX23(t *testing.T) { { desc: "Multiple locations reported", scanResult: &scalibr.ScanResult{ - Inventories: []*extractor.Inventory{&extractor.Inventory{ + Inventories: []*extractor.Inventory{{ Name: "software", Version: "1.2.3", Extractor: pipEx, Locations: []string{"/file1", "/file2", "/file3"}, }}, }, @@ -417,14 +417,14 @@ func TestToSPDX23(t *testing.T) { DocumentNamespace: "https://spdx.google/255aa5b7-d44b-4c40-b84c-892b9bffd436", CreationInfo: &v2_3.CreationInfo{ Creators: []common.Creator{ - common.Creator{ + { CreatorType: "Tool", Creator: "SCALIBR", }, }, }, Packages: []*v2_3.Package{ - &v2_3.Package{ + { PackageName: "main", PackageSPDXIdentifier: "SPDXRef-Package-main-172ed857-94bb-458b-8c3b-525da1786f9f", PackageVersion: "0", @@ -435,7 +435,7 @@ func TestToSPDX23(t *testing.T) { PackageDownloadLocation: converter.NoAssertion, IsFilesAnalyzedTagPresent: false, }, - &v2_3.Package{ + { PackageName: "software", PackageSPDXIdentifier: "SPDXRef-Package-software-ff094279-db19-44eb-97a1-9d0f7bbacbe0", PackageVersion: "1.2.3", @@ -447,7 +447,7 @@ func TestToSPDX23(t *testing.T) { IsFilesAnalyzedTagPresent: false, PackageSourceInfo: "Identified by the python/wheelegg extractor from 3 locations, including /file1 and /file2", PackageExternalReferences: []*v2_3.PackageExternalReference{ - &v2_3.PackageExternalReference{ + { Category: "PACKAGE-MANAGER", RefType: "purl", Locator: "pkg:pypi/software@1.2.3", @@ -456,7 +456,7 @@ func TestToSPDX23(t *testing.T) { }, }, Relationships: []*v2_3.Relationship{ - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-main-172ed857-94bb-458b-8c3b-525da1786f9f", }, @@ -465,7 +465,7 @@ func TestToSPDX23(t *testing.T) { }, Relationship: "CONTAINS", }, - &v2_3.Relationship{ + { RefA: common.DocElementID{ ElementRefID: "SPDXRef-Package-software-ff094279-db19-44eb-97a1-9d0f7bbacbe0", }, @@ -511,7 +511,7 @@ func TestToCDX(t *testing.T) { { desc: "Package with custom config", scanResult: &scalibr.ScanResult{ - Inventories: []*extractor.Inventory{&extractor.Inventory{ + Inventories: []*extractor.Inventory{{ Name: "software", Version: "1.2.3", Extractor: pipEx, }}, }, diff --git a/detector/detector_test.go b/detector/detector_test.go index 593b059f..10e427c9 100644 --- a/detector/detector_test.go +++ b/detector/detector_test.go @@ -79,8 +79,8 @@ func TestRun(t *testing.T) { withDetectorName(finding2, "det2"), }, wantStatus: []*plugin.Status{ - &plugin.Status{Name: "det1", Version: 1, Status: success}, - &plugin.Status{Name: "det2", Version: 2, Status: success}, + {Name: "det1", Version: 1, Status: success}, + {Name: "det2", Version: 2, Status: success}, }, }, { @@ -91,8 +91,8 @@ func TestRun(t *testing.T) { }, wantFindings: []*detector.Finding{withDetectorName(finding1, "det1")}, wantStatus: []*plugin.Status{ - &plugin.Status{Name: "det1", Version: 1, Status: success}, - &plugin.Status{Name: "det2", Version: 2, Status: &plugin.ScanStatus{ + {Name: "det1", Version: 1, Status: success}, + {Name: "det2", Version: 2, Status: &plugin.ScanStatus{ Status: plugin.ScanStatusFailed, FailureReason: "detection failed", }}, }, @@ -105,8 +105,8 @@ func TestRun(t *testing.T) { }, wantFindings: []*detector.Finding{withDetectorName(finding1, "det1"), withDetectorName(finding1, "det2")}, wantStatus: []*plugin.Status{ - &plugin.Status{Name: "det1", Version: 1, Status: success}, - &plugin.Status{Name: "det2", Version: 2, Status: success}, + {Name: "det1", Version: 1, Status: success}, + {Name: "det2", Version: 2, Status: success}, }, }, { @@ -119,8 +119,8 @@ func TestRun(t *testing.T) { }, wantFindings: []*detector.Finding{}, wantStatus: []*plugin.Status{ - &plugin.Status{Name: "det1", Version: 1, Status: success}, - &plugin.Status{Name: "det2", Version: 2, Status: success}, + {Name: "det1", Version: 1, Status: success}, + {Name: "det2", Version: 2, Status: success}, }, wantErr: cmpopts.AnyError, }, @@ -131,7 +131,7 @@ func TestRun(t *testing.T) { }, wantFindings: []*detector.Finding{}, wantStatus: []*plugin.Status{ - &plugin.Status{Name: "det1", Version: 1, Status: success}, + {Name: "det1", Version: 1, Status: success}, }, wantErr: cmpopts.AnyError, }, @@ -142,7 +142,7 @@ func TestRun(t *testing.T) { }, wantFindings: []*detector.Finding{}, wantStatus: []*plugin.Status{ - &plugin.Status{Name: "det1", Version: 1, Status: success}, + {Name: "det1", Version: 1, Status: success}, }, wantErr: cmpopts.AnyError, }, diff --git a/inventoryindex/inventory_index_test.go b/inventoryindex/inventory_index_test.go index 283265d8..0a1863e9 100644 --- a/inventoryindex/inventory_index_test.go +++ b/inventoryindex/inventory_index_test.go @@ -37,9 +37,9 @@ func TestGetAll(t *testing.T) { npmEx := packagejson.New(packagejson.DefaultConfig()) pipEx := wheelegg.New(wheelegg.DefaultConfig()) inv := []*extractor.Inventory{ - &extractor.Inventory{Name: "software1", Extractor: npmEx}, - &extractor.Inventory{Name: "software2", Extractor: pipEx}, - &extractor.Inventory{Name: "software3", Extractor: pipEx}, + {Name: "software1", Extractor: npmEx}, + {Name: "software2", Extractor: pipEx}, + {Name: "software3", Extractor: pipEx}, } want := inv @@ -58,13 +58,13 @@ func TestGetAllOfType(t *testing.T) { npmEx := packagejson.New(packagejson.DefaultConfig()) pipEx := wheelegg.New(wheelegg.DefaultConfig()) inv := []*extractor.Inventory{ - &extractor.Inventory{Name: "software1", Extractor: npmEx}, - &extractor.Inventory{Name: "software2", Extractor: pipEx}, - &extractor.Inventory{Name: "software3", Extractor: pipEx}, + {Name: "software1", Extractor: npmEx}, + {Name: "software2", Extractor: pipEx}, + {Name: "software3", Extractor: pipEx}, } want := []*extractor.Inventory{ - &extractor.Inventory{Name: "software2", Extractor: pipEx}, - &extractor.Inventory{Name: "software3", Extractor: pipEx}, + {Name: "software2", Extractor: pipEx}, + {Name: "software3", Extractor: pipEx}, } ix, err := inventoryindex.New(inv)