From ff1e8e46de0eb9d6f8780006a7df65c4c819a96c Mon Sep 17 00:00:00 2001 From: Meredith Lancaster Date: Thu, 14 Mar 2024 19:54:36 -0600 Subject: [PATCH] move mock client to test file Signed-off-by: Meredith Lancaster --- pkg/cmd/attestation/download/metadata.go | 12 ------------ pkg/cmd/attestation/download/metadata_test.go | 13 +++++++++++++ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/attestation/download/metadata.go b/pkg/cmd/attestation/download/metadata.go index 668d2fd27..49b152859 100644 --- a/pkg/cmd/attestation/download/metadata.go +++ b/pkg/cmd/attestation/download/metadata.go @@ -59,15 +59,3 @@ 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") -} diff --git a/pkg/cmd/attestation/download/metadata_test.go b/pkg/cmd/attestation/download/metadata_test.go index 4b947dc76..8ee3b2a45 100644 --- a/pkg/cmd/attestation/download/metadata_test.go +++ b/pkg/cmd/attestation/download/metadata_test.go @@ -7,12 +7,25 @@ import ( "path" "testing" + "github.com/cli/cli/v2/pkg/cmd/attestation/api" "github.com/cli/cli/v2/pkg/cmd/attestation/artifact" "github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci" "github.com/stretchr/testify/require" ) +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") +} + func TestCreateJSONLinesFilePath(t *testing.T) { tempDir := t.TempDir() artifact, err := artifact.NewDigestedArtifact(oci.MockClient{}, "../test/data/sigstore-js-2.1.0.tgz", "sha512")