From 8f957435024cd492074207ebeb5f97fbe0652bc6 Mon Sep 17 00:00:00 2001 From: Teppei Fukuda Date: Sun, 11 Dec 2022 15:02:43 +0200 Subject: [PATCH] test(vm): import relevant analyzers (#3285) --- pkg/fanal/artifact/vm/vm_test.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/fanal/artifact/vm/vm_test.go b/pkg/fanal/artifact/vm/vm_test.go index f62b1dbd0c7b..787504b9edfd 100644 --- a/pkg/fanal/artifact/vm/vm_test.go +++ b/pkg/fanal/artifact/vm/vm_test.go @@ -19,7 +19,8 @@ import ( "github.com/aquasecurity/trivy/pkg/fanal/types" ebsfile "github.com/masahiro331/go-ebs-file" - _ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/all" + _ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/os/amazonlinux" + _ "github.com/aquasecurity/trivy/pkg/fanal/analyzer/pkg/rpm" ) const ( @@ -35,7 +36,7 @@ func TestNewArtifact(t *testing.T) { }{ { name: "happy path for file", - target: "testdata/rawdata.img", + target: filepath.Join("testdata", "rawdata.img"), wantErr: assert.NoError, }, { @@ -45,7 +46,7 @@ func TestNewArtifact(t *testing.T) { }, { name: "sad path unsupported vm format", - target: "testdata/monolithicSparse.vmdk", + target: filepath.Join("testdata", "monolithicSparse.vmdk"), wantErr: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.ErrorContains(t, err, "unsupported type error") }, @@ -85,7 +86,7 @@ func TestArtifact_Inspect(t *testing.T) { filePath: "testdata/AmazonLinux2.img.gz", putBlobExpectation: cache.ArtifactCachePutBlobExpectation{ Args: cache.ArtifactCachePutBlobArgs{ - BlobID: "sha256:d59c327eb3a3c71c8728f5e3d597b1c5dbf25adb54d7e9237a0f1c8a495032d6", + BlobID: "sha256:bdff805a4b2a96074c549dbb7912f5089df1a484cf0919639ecdba437a959e90", BlobInfo: types.BlobInfo{ SchemaVersion: types.BlobJSONSchemaVersion, OS: &types.OS{ @@ -105,7 +106,7 @@ func TestArtifact_Inspect(t *testing.T) { putArtifactExpectations: []cache.ArtifactCachePutArtifactExpectation{ { Args: cache.ArtifactCachePutArtifactArgs{ - ArtifactID: "sha256:d59c327eb3a3c71c8728f5e3d597b1c5dbf25adb54d7e9237a0f1c8a495032d6", + ArtifactID: "sha256:bdff805a4b2a96074c549dbb7912f5089df1a484cf0919639ecdba437a959e90", ArtifactInfo: types.ArtifactInfo{ SchemaVersion: types.ArtifactJSONSchemaVersion, }, @@ -116,9 +117,9 @@ func TestArtifact_Inspect(t *testing.T) { want: types.ArtifactReference{ Name: "testdata/AmazonLinux2.img.gz", Type: types.ArtifactVM, - ID: "sha256:d59c327eb3a3c71c8728f5e3d597b1c5dbf25adb54d7e9237a0f1c8a495032d6", + ID: "sha256:bdff805a4b2a96074c549dbb7912f5089df1a484cf0919639ecdba437a959e90", BlobIDs: []string{ - "sha256:d59c327eb3a3c71c8728f5e3d597b1c5dbf25adb54d7e9237a0f1c8a495032d6", + "sha256:bdff805a4b2a96074c549dbb7912f5089df1a484cf0919639ecdba437a959e90", }, }, }, @@ -127,13 +128,13 @@ func TestArtifact_Inspect(t *testing.T) { filePath: "ebs:ebs-012345", missingBlobsExpectation: cache.ArtifactCacheMissingBlobsExpectation{ Args: cache.ArtifactCacheMissingBlobsArgs{ - ArtifactID: "sha256:a0a5dc5e371203bcfe6e8d9d24c6910b3ca2fd661cb53de62b6371fc177dcb69", - BlobIDs: []string{"sha256:a0a5dc5e371203bcfe6e8d9d24c6910b3ca2fd661cb53de62b6371fc177dcb69"}, + ArtifactID: "sha256:284fbc20c2224e9ffc9dbc2fa1cdc4138fcfd5c55763ecb737864c0ee0d8163f", + BlobIDs: []string{"sha256:284fbc20c2224e9ffc9dbc2fa1cdc4138fcfd5c55763ecb737864c0ee0d8163f"}, }, }, putBlobExpectation: cache.ArtifactCachePutBlobExpectation{ Args: cache.ArtifactCachePutBlobArgs{ - BlobID: "sha256:a0a5dc5e371203bcfe6e8d9d24c6910b3ca2fd661cb53de62b6371fc177dcb69", + BlobID: "sha256:284fbc20c2224e9ffc9dbc2fa1cdc4138fcfd5c55763ecb737864c0ee0d8163f", BlobInfo: types.BlobInfo{ SchemaVersion: types.BlobJSONSchemaVersion, OS: &types.OS{ @@ -153,7 +154,7 @@ func TestArtifact_Inspect(t *testing.T) { putArtifactExpectations: []cache.ArtifactCachePutArtifactExpectation{ { Args: cache.ArtifactCachePutArtifactArgs{ - ArtifactID: "sha256:a0a5dc5e371203bcfe6e8d9d24c6910b3ca2fd661cb53de62b6371fc177dcb69", + ArtifactID: "sha256:284fbc20c2224e9ffc9dbc2fa1cdc4138fcfd5c55763ecb737864c0ee0d8163f", ArtifactInfo: types.ArtifactInfo{ SchemaVersion: types.ArtifactJSONSchemaVersion, }, @@ -163,9 +164,9 @@ func TestArtifact_Inspect(t *testing.T) { want: types.ArtifactReference{ Name: "ebs-012345", Type: types.ArtifactVM, - ID: "sha256:a0a5dc5e371203bcfe6e8d9d24c6910b3ca2fd661cb53de62b6371fc177dcb69", + ID: "sha256:284fbc20c2224e9ffc9dbc2fa1cdc4138fcfd5c55763ecb737864c0ee0d8163f", BlobIDs: []string{ - "sha256:a0a5dc5e371203bcfe6e8d9d24c6910b3ca2fd661cb53de62b6371fc177dcb69", + "sha256:284fbc20c2224e9ffc9dbc2fa1cdc4138fcfd5c55763ecb737864c0ee0d8163f", }, }, }, @@ -188,7 +189,7 @@ func TestArtifact_Inspect(t *testing.T) { if aa, ok := a.(*vm.EBS); ok { // blockSize: 512 KB, volumeSize: 40MB - ebs := ebsfile.NewMockEBS("testdata/AmazonLinux2.img.gz", 512<<10, 40<<20) + ebs := ebsfile.NewMockEBS(filepath.Join("testdata", "AmazonLinux2.img.gz"), 512<<10, 40<<20) aa.SetEBS(ebs) }