check for noattestationsfound err
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
af7f6996b9
commit
01260efddb
2 changed files with 18 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ package download
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
|
|
@ -128,14 +129,13 @@ func runDownload(opts *Options) error {
|
|||
}
|
||||
attestations, err := verification.GetRemoteAttestations(c)
|
||||
if err != nil {
|
||||
if errors.Is(err, api.ErrNoAttestations{}) {
|
||||
fmt.Fprintf(opts.Logger.IO.Out, "No attestations found for %s\n", opts.ArtifactPath)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("failed to fetch attestations: %w", err)
|
||||
}
|
||||
|
||||
if attestations == nil {
|
||||
fmt.Fprintf(opts.Logger.IO.Out, "No attestations found for %s\n", opts.ArtifactPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
filePath := createJSONLinesFilePath(artifact.DigestWithAlg(), opts.OutputPath)
|
||||
fmt.Fprintf(opts.Logger.IO.Out, "Writing attestations to file %s.\nAny previous content will be overwritten\n\n", filePath)
|
||||
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ func TestRunDownload(t *testing.T) {
|
|||
opts := baseOpts
|
||||
opts.APIClient = api.MockClient{
|
||||
OnGetByOwnerAndDigest: func(repo, digest string, limit int) ([]*api.Attestation, error) {
|
||||
return nil, nil
|
||||
return nil, api.ErrNoAttestations{}
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -264,6 +264,18 @@ func TestRunDownload(t *testing.T) {
|
|||
require.NoFileExists(t, artifact.DigestWithAlg())
|
||||
})
|
||||
|
||||
t.Run("failed to fetch attestations", func(t *testing.T) {
|
||||
opts := baseOpts
|
||||
opts.APIClient = api.MockClient{
|
||||
OnGetByOwnerAndDigest: func(repo, digest string, limit int) ([]*api.Attestation, error) {
|
||||
return nil, fmt.Errorf("failed to fetch attestations")
|
||||
},
|
||||
}
|
||||
|
||||
err := runDownload(&opts)
|
||||
require.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("cannot download OCI artifact", func(t *testing.T) {
|
||||
opts := baseOpts
|
||||
opts.ArtifactPath = "oci://ghcr.io/github/test"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue