From b7f6af03b59f9a697c879a0fda06e44fb134c07b Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Mon, 13 Jan 2025 12:42:10 -0700 Subject: [PATCH] update no attestations found err Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/api/attestation.go | 16 ++-------------- pkg/cmd/attestation/api/client.go | 2 +- pkg/cmd/attestation/api/client_test.go | 4 ++-- pkg/cmd/attestation/api/mock_httpClient_test.go | 13 ------------- pkg/cmd/attestation/download/download.go | 2 +- pkg/cmd/attestation/download/download_test.go | 2 +- pkg/cmd/attestation/verify/verify.go | 2 +- 7 files changed, 8 insertions(+), 33 deletions(-) diff --git a/pkg/cmd/attestation/api/attestation.go b/pkg/cmd/attestation/api/attestation.go index 16b062a96..fd6b484a7 100644 --- a/pkg/cmd/attestation/api/attestation.go +++ b/pkg/cmd/attestation/api/attestation.go @@ -1,8 +1,7 @@ package api import ( - "fmt" - + "errors" "github.com/sigstore/sigstore-go/pkg/bundle" ) @@ -11,18 +10,7 @@ const ( GetAttestationByOwnerAndSubjectDigestPath = "orgs/%s/attestations/%s" ) -type ErrNoAttestations struct { - name string - digest string -} - -func (e ErrNoAttestations) Error() string { - return fmt.Sprintf("no attestations found for digest %s in %s", e.name, e.digest) -} - -func newErrNoAttestations(name, digest string) ErrNoAttestations { - return ErrNoAttestations{name, digest} -} +var ErrNoAttestationsFound = errors.New("no attestations found") type Attestation struct { Bundle *bundle.Bundle `json:"bundle"` diff --git a/pkg/cmd/attestation/api/client.go b/pkg/cmd/attestation/api/client.go index c3670f42d..faa1609fc 100644 --- a/pkg/cmd/attestation/api/client.go +++ b/pkg/cmd/attestation/api/client.go @@ -137,7 +137,7 @@ func (c *LiveClient) getAttestations(url string, limit int) ([]*Attestation, err } if len(attestations) == 0 { - return nil, ErrNoAttestations{} + return nil, ErrNoAttestationsFound } if len(attestations) > limit { diff --git a/pkg/cmd/attestation/api/client_test.go b/pkg/cmd/attestation/api/client_test.go index 77cd22ee6..5a7c299c7 100644 --- a/pkg/cmd/attestation/api/client_test.go +++ b/pkg/cmd/attestation/api/client_test.go @@ -132,12 +132,12 @@ func TestGetByDigest_NoAttestationsFound(t *testing.T) { attestations, err := c.GetByRepoAndDigest(testRepo, testDigest, DefaultLimit) require.Error(t, err) - require.IsType(t, ErrNoAttestations{}, err) + require.IsType(t, ErrNoAttestationsFound, err) require.Nil(t, attestations) attestations, err = c.GetByOwnerAndDigest(testOwner, testDigest, DefaultLimit) require.Error(t, err) - require.IsType(t, ErrNoAttestations{}, err) + require.IsType(t, ErrNoAttestationsFound, err) require.Nil(t, attestations) } diff --git a/pkg/cmd/attestation/api/mock_httpClient_test.go b/pkg/cmd/attestation/api/mock_httpClient_test.go index 074979c2a..e11266a60 100644 --- a/pkg/cmd/attestation/api/mock_httpClient_test.go +++ b/pkg/cmd/attestation/api/mock_httpClient_test.go @@ -40,19 +40,6 @@ func (m *failHttpClient) Get(url string) (*http.Response, error) { }, fmt.Errorf("failed to fetch with %s", url) } -type failHttpClient5XX struct { - mock.Mock -} - -func (m *failHttpClient5XX) Get(url string) (*http.Response, error) { - m.On("OnGetFail").Return() - m.MethodCalled("OnGetFail") - - return &http.Response{ - StatusCode: 500, - }, nil -} - type failAfterNCallsHttpClient struct { mock.Mock FailOnCallN int diff --git a/pkg/cmd/attestation/download/download.go b/pkg/cmd/attestation/download/download.go index 7547e9e68..cdbdc0078 100644 --- a/pkg/cmd/attestation/download/download.go +++ b/pkg/cmd/attestation/download/download.go @@ -135,7 +135,7 @@ func runDownload(opts *Options) error { } attestations, err := verification.GetRemoteAttestations(opts.APIClient, params) if err != nil { - if errors.Is(err, api.ErrNoAttestations{}) { + if errors.Is(err, api.ErrNoAttestationsFound) { fmt.Fprintf(opts.Logger.IO.Out, "No attestations found for %s\n", opts.ArtifactPath) return nil } diff --git a/pkg/cmd/attestation/download/download_test.go b/pkg/cmd/attestation/download/download_test.go index 6c2986065..ddcd08c92 100644 --- a/pkg/cmd/attestation/download/download_test.go +++ b/pkg/cmd/attestation/download/download_test.go @@ -276,7 +276,7 @@ func TestRunDownload(t *testing.T) { opts := baseOpts opts.APIClient = api.MockClient{ OnGetByOwnerAndDigest: func(repo, digest string, limit int) ([]*api.Attestation, error) { - return nil, api.ErrNoAttestations{} + return nil, api.ErrNoAttestationsFound }, } diff --git a/pkg/cmd/attestation/verify/verify.go b/pkg/cmd/attestation/verify/verify.go index 016ec1fa8..a5e78a48e 100644 --- a/pkg/cmd/attestation/verify/verify.go +++ b/pkg/cmd/attestation/verify/verify.go @@ -220,7 +220,7 @@ func runVerify(opts *Options) error { attestations, logMsg, err := getAttestations(opts, *artifact) if err != nil { - if ok := errors.Is(err, api.ErrNoAttestations{}); ok { + if ok := errors.Is(err, api.ErrNoAttestationsFound); ok { opts.Logger.Printf(opts.Logger.ColorScheme.Red("✗ No attestations found for subject %s\n"), artifact.DigestWithAlg()) return err }