Skip to content

Commit

Permalink
test(vm): import relevant analyzers (#3285)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 committed Dec 11, 2022
1 parent 8744534 commit 8f95743
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions pkg/fanal/artifact/vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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,
},
{
Expand All @@ -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")
},
Expand Down Expand Up @@ -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{
Expand All @@ -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,
},
Expand All @@ -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",
},
},
},
Expand All @@ -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{
Expand All @@ -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,
},
Expand All @@ -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",
},
},
},
Expand All @@ -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)
}

Expand Down

0 comments on commit 8f95743

Please sign in to comment.