...

Source file src/github.com/google/go-containerregistry/pkg/gcrane/options_test.go

Documentation: github.com/google/go-containerregistry/pkg/gcrane

     1  // Copyright 2021 Google LLC All Rights Reserved.
     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 gcrane
    16  
    17  import (
    18  	"context"
    19  	"net/http"
    20  	"testing"
    21  
    22  	"github.com/google/go-containerregistry/pkg/authn"
    23  )
    24  
    25  func TestOptions(t *testing.T) {
    26  	o := makeOptions()
    27  	if len(o.remote) != 1 {
    28  		t.Errorf("remote should default to Keychain")
    29  	}
    30  	if len(o.crane) != 1 {
    31  		t.Errorf("crane should default to Keychain")
    32  	}
    33  	if len(o.google) != 1 {
    34  		t.Errorf("google should default to Keychain")
    35  	}
    36  
    37  	o = makeOptions(WithAuth(authn.Anonymous), WithKeychain(authn.DefaultKeychain))
    38  	if len(o.remote) != 1 {
    39  		t.Errorf("WithKeychain should replace remote[0]")
    40  	}
    41  	if len(o.crane) != 1 {
    42  		t.Errorf("WithKeychain should replace crane[0]")
    43  	}
    44  	if len(o.google) != 1 {
    45  		t.Errorf("WithKeychain should replace google[0]")
    46  	}
    47  
    48  	o = makeOptions(WithTransport(http.DefaultTransport), WithUserAgent("hi"), WithContext(context.TODO()))
    49  	if len(o.remote) != 4 {
    50  		t.Errorf("wrong number of options: %d", len(o.remote))
    51  	}
    52  	if len(o.crane) != 4 {
    53  		t.Errorf("wrong number of options: %d", len(o.crane))
    54  	}
    55  	if len(o.google) != 4 {
    56  		t.Errorf("wrong number of options: %d", len(o.google))
    57  	}
    58  }
    59  

View as plain text