...

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

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

     1  // Copyright 2023 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 crane
    16  
    17  import (
    18  	"errors"
    19  	"net/http"
    20  	"testing"
    21  
    22  	"github.com/google/go-containerregistry/pkg/v1/remote"
    23  )
    24  
    25  func TestInsecureOptionTracking(t *testing.T) {
    26  	want := true
    27  	opts := GetOptions(Insecure)
    28  
    29  	if got := opts.insecure; got != want {
    30  		t.Errorf("got %t\nwant: %t", got, want)
    31  	}
    32  }
    33  
    34  func TestTransportSetting(t *testing.T) {
    35  	opts := GetOptions(WithTransport(remote.DefaultTransport))
    36  
    37  	if opts.Transport == nil {
    38  		t.Error("expected crane transport to be set when user passes WithTransport")
    39  	}
    40  }
    41  
    42  func TestInsecureTransport(t *testing.T) {
    43  	want := true
    44  	opts := GetOptions(Insecure)
    45  	var transport *http.Transport
    46  	var ok bool
    47  	if transport, ok = opts.Transport.(*http.Transport); !ok {
    48  		t.Fatal("Unable to successfully assert default transport")
    49  	}
    50  
    51  	if transport.TLSClientConfig == nil {
    52  		t.Fatal(errors.New("TLSClientConfig was nil and should be set"))
    53  	}
    54  
    55  	if got := transport.TLSClientConfig.InsecureSkipVerify; got != want {
    56  		t.Errorf("got: %t\nwant: %t", got, want)
    57  	}
    58  }
    59  

View as plain text