add missing nil struct checks and udpate error messages
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
cdfb1b7279
commit
13dafefcb5
4 changed files with 11 additions and 5 deletions
|
|
@ -31,9 +31,9 @@ func OnGetByDigestSuccess(params FetchParams) ([]*Attestation, error) {
|
|||
|
||||
func OnGetByDigestFailure(params FetchParams) ([]*Attestation, error) {
|
||||
if params.Repo != "" {
|
||||
return nil, fmt.Errorf("failed to fetch by repo and digest")
|
||||
return nil, fmt.Errorf("failed to fetch attestations from %s", params.Repo)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to fetch by owner and digest")
|
||||
return nil, fmt.Errorf("failed to fetch attestations from %s", params.Owner)
|
||||
}
|
||||
|
||||
func NewTestClient() *MockClient {
|
||||
|
|
|
|||
|
|
@ -162,6 +162,6 @@ func TestFilterAttestations(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
filtered, err = FilterAttestations("NonExistentPredicate", attestations)
|
||||
require.Len(t, filtered, 0)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, filtered)
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package verify
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/cli/cli/v2/internal/text"
|
||||
|
|
@ -13,6 +14,11 @@ func getAttestations(o *Options, a artifact.DigestedArtifact) ([]*api.Attestatio
|
|||
// Fetch attestations from GitHub API within this if block since predicate type
|
||||
// filter is done when the API is called
|
||||
if o.FetchAttestationsFromGitHubAPI() {
|
||||
if o.APIClient == nil {
|
||||
errMsg := "✗ No APIClient provided"
|
||||
return nil, errMsg, errors.New(errMsg)
|
||||
}
|
||||
|
||||
params := api.FetchParams{
|
||||
Digest: a.DigestWithAlg(),
|
||||
Limit: o.Limit,
|
||||
|
|
|
|||
|
|
@ -510,7 +510,7 @@ func TestRunVerify(t *testing.T) {
|
|||
|
||||
err := runVerify(&customOpts)
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "no matching predicate found")
|
||||
require.ErrorContains(t, err, "no attestations found with predicate type")
|
||||
})
|
||||
|
||||
t.Run("with valid OCI artifact with UseBundleFromRegistry flag but no bundle return from registry", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue