Skip to content

Commit

Permalink
extra test
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispatrick committed Mar 6, 2024
1 parent 11cec4d commit 182dcd2
Showing 1 changed file with 58 additions and 7 deletions.
65 changes: 58 additions & 7 deletions policy/policy_handler/mocks/base_image_details.test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ func (ds MockDs) Query(ctx context.Context, queryName string, query string, vari

r := output.(*BaseImagesByDigestResponse)
r.BaseImagesByDigest.Images = []BaseImage{
BaseImage{
{
Digest: "sha256:1234",
Repository: Repository{
HostName: "registry.com",
RepoName: "namespace/repository",
},
Tags: []Tag{
Tag{
{
Name: "latest",
Current: true,
},
Tag{
{
Name: "1.0",
Current: false,
},
Expand All @@ -42,7 +42,7 @@ func (ds MockDs) Query(ctx context.Context, queryName string, query string, vari
return &data.QueryResponse{}, nil
}

func Test_mockBaseImageDetails(t *testing.T) {
func Test_mockBaseImageDetails_isNotCurrent(t *testing.T) {
sbom := &types.SBOM{
Source: types.Source{
Image: &types.ImageSource{
Expand All @@ -51,8 +51,59 @@ func Test_mockBaseImageDetails(t *testing.T) {
Provenance: &types.Provenance{
BaseImage: &types.ProvenanceBaseImage{
Digest: "sha256:1234",
Tag: "1.0",
},
},
},
}

logger := skill.Logger{
Debug: func(msg string) {},
Debugf: func(format string, a ...any) {},
}
actual, err := mockBaseImageDetails(context.TODO(), skill.RequestContext{Log: logger}, sbom, MockDs{t})
assert.NoError(t, err)

Tag: "1.0",
expected := ImageDetailsByDigestResponse{
ImageDetailsByDigest: &ImageDetailsByDigest{
Digest: "sha256:9999",
BaseImage: &BaseImage{
Digest: "sha256:1234",
Repository: Repository{
HostName: "registry.com",
RepoName: "namespace/repository",
},
Tags: []Tag{
{
Name: "latest",
Current: true,
},
{
Name: "1.0",
Current: false,
},
},
},
BaseImageTag: &Tag{
Name: "1.0",
Current: false,
},
},
}

assert.Equal(t, expected, actual)
}

func Test_mockBaseImageDetails_isCurrent(t *testing.T) {
sbom := &types.SBOM{
Source: types.Source{
Image: &types.ImageSource{
Digest: "sha256:9999",
},
Provenance: &types.Provenance{
BaseImage: &types.ProvenanceBaseImage{
Digest: "sha256:1234",
Tag: "latest",
},
},
},
Expand All @@ -75,11 +126,11 @@ func Test_mockBaseImageDetails(t *testing.T) {
RepoName: "namespace/repository",
},
Tags: []Tag{
Tag{
{
Name: "latest",
Current: true,
},
Tag{
{
Name: "1.0",
Current: false,
},
Expand Down

0 comments on commit 182dcd2

Please sign in to comment.