github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/terraform/cataloger_test.go (about) 1 package terraform 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "github.com/anchore/syft/syft/file" 8 "github.com/anchore/syft/syft/internal/fileresolver" 9 "github.com/anchore/syft/syft/pkg" 10 "github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest" 11 ) 12 13 func TestTerraformCataloger(t *testing.T) { 14 c := NewLockCataloger() 15 16 fileLoc := file.NewLocation(".terraform.lock.hcl") 17 location := fileLoc.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation) 18 19 awsProviderPkg := pkg.Package{ 20 Name: "registry.terraform.io/hashicorp/aws", 21 Version: "5.72.1", 22 FoundBy: "terraform-lock-cataloger", 23 Locations: file.NewLocationSet(location), 24 Type: pkg.TerraformPkg, 25 Language: pkg.Go, 26 Metadata: pkg.TerraformLockProviderEntry{ 27 URL: "registry.terraform.io/hashicorp/aws", 28 Version: "5.72.1", 29 Constraints: "> 5.72.0", 30 Hashes: []string{ 31 "h1:jhd5O5o0CfZCNEwwN0EiDAzb7ApuFrtxJqa6HXW4EKE=", 32 "zh:0dea6843836e926d33469b48b948744079023816d16a2ff7666bcfb6aa3522d4", 33 "zh:195fa9513f75800a0d62797ebec75ee73e9b8c28d713fe9b63d3b1d1eec129b3", 34 "zh:1ed92f3961715bf0e024bcde3c12dfbdc50b00c1f8a43cc00802cfc45a256208", 35 "zh:2ac687e3a52606466cae4a6813e81d923042488df88d2424e28d3f8530f091bb", 36 "zh:32e7ca75f9314557daada3c44628fe1f3bf964a4f833bfb4b2295d833fe64b6f", 37 "zh:374ee0e6b4327cc6ef666908ce5d6450a3a56e90cd2b785e83c2bcfc100021d2", 38 "zh:5500fd6fdac44f96411fcf9c6d01691159ec35455ed127eb4c3a498e1cc92a64", 39 "zh:723a2dc4b064c12e7ee62ad4fbfd72fa5e025206ea47b735994ef53f3c373152", 40 "zh:89d97b87605f1d734f27e642567cbecf785b521af8ea81dac55c77ccde876221", 41 "zh:951ee1e5731e8d65d521d71b95927e55055b3c4656eef6d46fa580a63328befc", 42 "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 43 "zh:9b2b362470b64ec227b2da64762ab8bc4111c6b80365fd9d82fc5e1e33f44038", 44 "zh:aa6e57d0cb974ff0da5dee5d43ad2745cbbc4a2b507d4c799839b9fa96daf688", 45 "zh:ba0d14c4a6b7aa844a830d47c0bf995b632e37f0795394b5b60c638b62b7fc03", 46 "zh:c9764065a9c5d324db0b02bd201b9e3a2118e49c4960884acdeea377173302e9", 47 }, 48 }, 49 } 50 awsProviderPkg.SetID() 51 52 gcpProviderPkg := pkg.Package{ 53 Name: "registry.terraform.io/hashicorp/google", 54 Version: "6.8.0", 55 FoundBy: "terraform-lock-cataloger", 56 Locations: file.NewLocationSet(location), 57 Type: pkg.TerraformPkg, 58 Language: pkg.Go, 59 Metadata: pkg.TerraformLockProviderEntry{ 60 URL: "registry.terraform.io/hashicorp/google", 61 Version: "6.8.0", 62 Constraints: "", 63 Hashes: []string{ 64 "h1:GlCaVPk6eKMg2ZbRY7C5tUeHGNIABT+qFtMl8+XWZHM=", 65 "zh:1b78f4451f1617092eb6891c9c13eda79671060601c40947feea6794c732157a", 66 "zh:4c6d7231ce32c6ff2a98218ef363c133d27d423b009354e7fe18459d9feb41d4", 67 "zh:6ae0112e9c733ab6c72436a334ffe3f197a613bb04f49538462b83b236d37a2d", 68 "zh:8bd5651838ad674e0a173a453b76c80b94d08ebcb8ea0b6263ce6da0599b42f5", 69 "zh:94ee7bcd77b0b7c2777113e35282da014e61e813fe46c058a49bf3d616fecdf4", 70 "zh:c0bf014422c2971985d34ad45ddb6aa737373398f83b325884ea5608ac1264aa", 71 "zh:c2cbbf0c249c3d1842ad0ad77fb7ef85bd3e92c688618c4087173bc1d69cd098", 72 "zh:cefa3e06cb353d08b83dafa6135cd78e17540ae735b7c5687833cc1925c3fd8e", 73 "zh:d20bc0216bf7f054f6318467d3902ced05e9f0bfa500ee55bf43b1b41ef0b854", 74 "zh:e54ad5959e53b9e9acafc243d6f4039ab5005cec32c7435a122da964888d184c", 75 "zh:e833c8de147268b3ffc14c60915eccb9347ade5f25b37b3771240a4d68b6aac4", 76 "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", 77 }, 78 }, 79 } 80 gcpProviderPkg.SetID() 81 82 tests := []struct { 83 name string 84 expected []pkg.Package 85 }{ 86 { 87 name: "two-providers", 88 expected: []pkg.Package{ 89 awsProviderPkg, 90 gcpProviderPkg, 91 }, 92 }, 93 } 94 95 for _, tt := range tests { 96 t.Run(tt.name, func(t *testing.T) { 97 pkgtest.NewCatalogTester(). 98 WithResolver(fileresolver.NewFromUnindexedDirectory(filepath.Join("test-fixtures", tt.name))). 99 Expects(tt.expected, nil). 100 TestCataloger(t, c) 101 }) 102 } 103 }