From df49fa9e55f60e89f761a94a06736acefa491291 Mon Sep 17 00:00:00 2001 From: "Lehman, Alex" Date: Thu, 20 Apr 2023 16:56:14 -0400 Subject: [PATCH] Update tests to check hasField template func --- syft/formats/internal/testutils/utils.go | 2 ++ syft/formats/syftjson/encoder_test.go | 1 + .../test-fixtures/snapshot/TestDirectoryEncoder.golden | 4 ++-- .../snapshot/TestEncodeFullJSONDocument.golden | 4 ++-- .../syftjson/test-fixtures/snapshot/TestImageEncoder.golden | 4 ++-- syft/formats/template/test-fixtures/csv.template | 4 ++-- .../test-fixtures/snapshot/TestFormatWithOption.golden | 6 +++--- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/syft/formats/internal/testutils/utils.go b/syft/formats/internal/testutils/utils.go index f214c4f07f34..743bfdbfb803 100644 --- a/syft/formats/internal/testutils/utils.go +++ b/syft/formats/internal/testutils/utils.go @@ -178,6 +178,7 @@ func populateImageCatalog(catalog *pkg.Catalog, img *image.Image) { Metadata: pkg.PythonPackageMetadata{ Name: "package-1", Version: "1.0.1", + Author: "package-author", }, PURL: "a-purl-1", // intentionally a bad pURL for test fixtures CPEs: []cpe.CPE{ @@ -253,6 +254,7 @@ func newDirectoryCatalog() *pkg.Catalog { Metadata: pkg.PythonPackageMetadata{ Name: "package-1", Version: "1.0.1", + Author: "package-author", Files: []pkg.PythonFileRecord{ { Path: "/some/path/pkg1/dependencies/foo", diff --git a/syft/formats/syftjson/encoder_test.go b/syft/formats/syftjson/encoder_test.go index 39510fcb84fc..de07ad78c4af 100644 --- a/syft/formats/syftjson/encoder_test.go +++ b/syft/formats/syftjson/encoder_test.go @@ -65,6 +65,7 @@ func TestEncodeFullJSONDocument(t *testing.T) { Metadata: pkg.PythonPackageMetadata{ Name: "package-1", Version: "1.0.1", + Author: "package-author", Files: []pkg.PythonFileRecord{}, }, PURL: "a-purl-1", diff --git a/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden b/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden index 3288035324ba..a21df29c6e6f 100644 --- a/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden +++ b/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden @@ -1,7 +1,7 @@ { "artifacts": [ { - "id": "1b1d0be59ac59d2c", + "id": "df2ba437ec3dfded", "name": "package-1", "version": "1.0.1", "type": "python", @@ -24,7 +24,7 @@ "name": "package-1", "version": "1.0.1", "license": "", - "author": "", + "author": "package-author", "authorEmail": "", "platform": "", "files": [ diff --git a/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden b/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden index 322e8cb0fdef..ae8cae25f964 100644 --- a/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden +++ b/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden @@ -1,7 +1,7 @@ { "artifacts": [ { - "id": "304a5a8e5958a49d", + "id": "bf332d3aaa83a147", "name": "package-1", "version": "1.0.1", "type": "python", @@ -24,7 +24,7 @@ "name": "package-1", "version": "1.0.1", "license": "", - "author": "", + "author": "package-author", "authorEmail": "", "platform": "", "sitePackagesRootPath": "" diff --git a/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden b/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden index eda15743f5f3..76e59c006726 100644 --- a/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden +++ b/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden @@ -1,7 +1,7 @@ { "artifacts": [ { - "id": "66ba429119b8bec6", + "id": "3b71b371e0f36e18", "name": "package-1", "version": "1.0.1", "type": "python", @@ -25,7 +25,7 @@ "name": "package-1", "version": "1.0.1", "license": "", - "author": "", + "author": "package-author", "authorEmail": "", "platform": "", "sitePackagesRootPath": "" diff --git a/syft/formats/template/test-fixtures/csv.template b/syft/formats/template/test-fixtures/csv.template index 8474271adb29..5566da37e3e9 100644 --- a/syft/formats/template/test-fixtures/csv.template +++ b/syft/formats/template/test-fixtures/csv.template @@ -1,4 +1,4 @@ -"Package","Version Installed", "Found by" +"Package","Version Installed", "Found by", "Author" {{- range .Artifacts}} -"{{.Name}}","{{.Version}}","{{.FoundBy}}" +"{{.Name}}","{{.Version}}","{{.FoundBy}}","{{ if hasField .Metadata "Author" }}{{ .Metadata.Author }}{{ else }}NO AUTHOR SUPPLIED{{end}}" {{- end}} \ No newline at end of file diff --git a/syft/formats/template/test-fixtures/snapshot/TestFormatWithOption.golden b/syft/formats/template/test-fixtures/snapshot/TestFormatWithOption.golden index a7bc3b7d3ffb..1a50ab0a9bcd 100644 --- a/syft/formats/template/test-fixtures/snapshot/TestFormatWithOption.golden +++ b/syft/formats/template/test-fixtures/snapshot/TestFormatWithOption.golden @@ -1,3 +1,3 @@ -"Package","Version Installed", "Found by" -"package-1","1.0.1","the-cataloger-1" -"package-2","2.0.1","the-cataloger-2" \ No newline at end of file +"Package","Version Installed", "Found by", "Author" +"package-1","1.0.1","the-cataloger-1","package-author" +"package-2","2.0.1","the-cataloger-2","NO AUTHOR SUPPLIED" \ No newline at end of file