-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartifact_test.go
58 lines (45 loc) · 1.4 KB
/
artifact_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package analyzer
import (
"context"
"testing"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"github.com/castai/image-analyzer/image"
)
func TestArtifact(t *testing.T) {
r := require.New(t)
ctx := context.Background()
log := logrus.New()
log.SetLevel(logrus.DebugLevel)
digest := "alpine@sha256:60eda2a7bc29a54fe6beae0d72312ea995eb3b8387535e8dbf6767fd1b765d34" // linux/amd64 digest
img, err := image.NewFromRemote(ctx, log, digest, types.ImageOptions{})
r.NoError(err)
artifact, err := NewArtifact(img, log, mockBlockCache{}, ArtifactOption{
Offline: true,
Parallel: 1,
})
r.NoError(err)
ref, err := artifact.Inspect(ctx)
r.NoError(err)
r.NotNil(ref)
r.NotNil(ref.BlobsInfo)
r.Len(ref.BlobsInfo, 1)
r.Len(ref.BlobsInfo[0].PackageInfos, 1)
r.Len(ref.BlobsInfo[0].PackageInfos[0].Packages, 15)
r.NotNil(ref.ConfigFile)
r.Equal("amd64", ref.ConfigFile.Architecture)
r.Equal("linux", ref.ConfigFile.OS)
r.NotNil(ref.ArtifactInfo)
r.Equal("amd64", ref.ArtifactInfo.Architecture)
r.Equal("linux", ref.ArtifactInfo.OS)
r.NotNil(ref.OsInfo)
r.Equal("alpine", string(ref.OsInfo.Family))
}
type mockBlockCache struct{}
func (mockBlockCache) PutBlob(ctx context.Context, key string, blob []byte) error {
return nil
}
func (mockBlockCache) GetBlob(ctx context.Context, key string) ([]byte, error) {
return nil, ErrCacheNotFound
}