...

Source file src/github.com/sigstore/cosign/v2/pkg/oci/layout/signatures_test.go

Documentation: github.com/sigstore/cosign/v2/pkg/oci/layout

     1  // Copyright 2024 The Sigstore Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package layout
    16  
    17  import (
    18  	"errors"
    19  	"testing"
    20  
    21  	v1 "github.com/google/go-containerregistry/pkg/v1"
    22  	"github.com/google/go-containerregistry/pkg/v1/fake"
    23  )
    24  
    25  func TestGet(t *testing.T) {
    26  	tests := []struct {
    27  		name      string
    28  		layers    int
    29  		wantError error
    30  	}{
    31  		{
    32  			name:      "within limit",
    33  			layers:    23,
    34  			wantError: nil,
    35  		},
    36  		{
    37  			name:      "exceeds limit",
    38  			layers:    4242,
    39  			wantError: errors.New("number of layers (4242) exceeded the limit (1000)"),
    40  		},
    41  	}
    42  	for _, test := range tests {
    43  		t.Run(test.name, func(t *testing.T) {
    44  			s := sigs{
    45  				Image: &fake.FakeImage{
    46  					ManifestStub: func() (*v1.Manifest, error) {
    47  						return &v1.Manifest{
    48  							Layers: make([]v1.Descriptor, test.layers),
    49  						}, nil
    50  					},
    51  				},
    52  			}
    53  			_, err := s.Get()
    54  			if test.wantError != nil && test.wantError.Error() != err.Error() {
    55  				t.Fatalf("Get() = %v, wanted %v", err, test.wantError)
    56  			}
    57  			if test.wantError == nil && err != nil {
    58  				t.Fatalf("Get() = %v, wanted %v", err, test.wantError)
    59  			}
    60  		})
    61  	}
    62  }
    63  

View as plain text