Skip to content

Commit 269845c

Browse files
committed
test: add unit test
Signed-off-by: Junjie Gao <junjiegao@microsoft.com>
1 parent da398fe commit 269845c

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

internal/mock/mocks.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ type Repository struct {
125125
FetchSignatureBlobError error
126126
MissMatchDigest bool
127127
ExceededNumOfSignatures bool
128+
PushSignatureError error
128129
}
129130

130131
func NewRepository() Repository {
@@ -163,6 +164,10 @@ func (t Repository) FetchSignatureBlob(ctx context.Context, desc ocispec.Descrip
163164
}
164165

165166
func (t Repository) PushSignature(ctx context.Context, mediaType string, blob []byte, subject ocispec.Descriptor, annotations map[string]string) (blobDesc, manifestDesc ocispec.Descriptor, err error) {
167+
if t.PushSignatureError != nil {
168+
return ocispec.Descriptor{}, ocispec.Descriptor{}, t.PushSignatureError
169+
}
170+
166171
return ocispec.Descriptor{}, ocispec.Descriptor{}, nil
167172
}
168173

notation_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ func TestSignSuccessWithUserMetadata(t *testing.T) {
155155
}
156156
}
157157

158+
func TestSignWithDanglingReferrersIndex(t *testing.T) {
159+
repo := mock.NewRepository()
160+
repo.PushSignatureError = errors.New("failed to delete dangling referrers index")
161+
opts := SignOptions{}
162+
opts.ArtifactReference = mock.SampleArtifactUri
163+
opts.SignatureMediaType = jws.MediaTypeEnvelope
164+
165+
_, err := Sign(context.Background(), &dummySigner{}, repo, opts)
166+
if err == nil {
167+
t.Fatalf("no error occurred, expected error: failed to delete dangling referrers index")
168+
}
169+
}
170+
158171
func TestSignWithInvalidExpiry(t *testing.T) {
159172
repo := mock.NewRepository()
160173
testCases := []struct {

0 commit comments

Comments
 (0)