diff --git a/pkg/cmd/attestation/download/download_test.go b/pkg/cmd/attestation/download/download_test.go index a162002cc..a1d621c45 100644 --- a/pkg/cmd/attestation/download/download_test.go +++ b/pkg/cmd/attestation/download/download_test.go @@ -301,4 +301,14 @@ func TestRunDownload(t *testing.T) { customOpts.APIClient = nil require.Error(t, runDownload(&customOpts)) }) + + t.Run("fail to write attestations to metadata file", func(t *testing.T) { + opts := baseOpts + opts.Store = &MockStore{ + OnCreateMetadataFile: OnCreateMetadataFileFailure, + } + + err := runDownload(&opts) + require.Error(t, err) + }) } diff --git a/pkg/cmd/attestation/download/metadata.go b/pkg/cmd/attestation/download/metadata.go index a461f4302..6635aa943 100644 --- a/pkg/cmd/attestation/download/metadata.go +++ b/pkg/cmd/attestation/download/metadata.go @@ -9,7 +9,6 @@ import ( ) type MetadataStore interface { - createJSONLinesFilePath(artifact string) string createMetadataFile(artifactDigest string, attestationsResp []*api.Attestation) (string, error) } @@ -57,3 +56,15 @@ func (s *LiveStore) createMetadataFile(artifactDigest string, attestationsResp [ return metadataFilePath, nil } + +type MockStore struct { + OnCreateMetadataFile func(artifactDigest string, attestationsResp []*api.Attestation) (string, error) +} + +func (s *MockStore) createMetadataFile(artifact string, attestationsResp []*api.Attestation) (string, error) { + return s.OnCreateMetadataFile(artifact, attestationsResp) +} + +func OnCreateMetadataFileFailure(artifactDigest string, attestationsResp []*api.Attestation) (string, error) { + return "", fmt.Errorf("failed to create trusted metadata file") +}