...

Source file src/helm.sh/helm/v3/pkg/pusher/ocipusher_test.go

Documentation: helm.sh/helm/v3/pkg/pusher

     1  /*
     2  Copyright The Helm Authors.
     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  
    16  package pusher
    17  
    18  import (
    19  	"path/filepath"
    20  	"testing"
    21  
    22  	"helm.sh/helm/v3/pkg/registry"
    23  )
    24  
    25  func TestNewOCIPusher(t *testing.T) {
    26  	p, err := NewOCIPusher()
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	if _, ok := p.(*OCIPusher); !ok {
    32  		t.Fatal("Expected NewOCIPusher to produce an *OCIPusher")
    33  	}
    34  
    35  	cd := "../../testdata"
    36  	join := filepath.Join
    37  	ca, pub, priv := join(cd, "rootca.crt"), join(cd, "crt.pem"), join(cd, "key.pem")
    38  	insecureSkipTLSverify := false
    39  	plainHTTP := false
    40  
    41  	// Test with options
    42  	p, err = NewOCIPusher(
    43  		WithTLSClientConfig(pub, priv, ca),
    44  		WithInsecureSkipTLSVerify(insecureSkipTLSverify),
    45  		WithPlainHTTP(plainHTTP),
    46  	)
    47  	if err != nil {
    48  		t.Fatal(err)
    49  	}
    50  
    51  	op, ok := p.(*OCIPusher)
    52  	if !ok {
    53  		t.Fatal("Expected NewOCIPusher to produce an *OCIPusher")
    54  	}
    55  
    56  	if op.opts.certFile != pub {
    57  		t.Errorf("Expected NewOCIPusher to contain %q as the public key file, got %q", pub, op.opts.certFile)
    58  	}
    59  
    60  	if op.opts.keyFile != priv {
    61  		t.Errorf("Expected NewOCIPusher to contain %q as the private key file, got %q", priv, op.opts.keyFile)
    62  	}
    63  
    64  	if op.opts.caFile != ca {
    65  		t.Errorf("Expected NewOCIPusher to contain %q as the CA file, got %q", ca, op.opts.caFile)
    66  	}
    67  
    68  	if op.opts.plainHTTP != plainHTTP {
    69  		t.Errorf("Expected NewOCIPusher to have plainHTTP as %t, got %t", plainHTTP, op.opts.plainHTTP)
    70  	}
    71  
    72  	if op.opts.insecureSkipTLSverify != insecureSkipTLSverify {
    73  		t.Errorf("Expected NewOCIPusher to have insecureSkipVerifyTLS as %t, got %t", insecureSkipTLSverify, op.opts.insecureSkipTLSverify)
    74  	}
    75  
    76  	// Test if setting registryClient is being passed to the ops
    77  	registryClient, err := registry.NewClient()
    78  	if err != nil {
    79  		t.Fatal(err)
    80  	}
    81  
    82  	p, err = NewOCIPusher(
    83  		WithRegistryClient(registryClient),
    84  	)
    85  	if err != nil {
    86  		t.Fatal(err)
    87  	}
    88  	op, ok = p.(*OCIPusher)
    89  	if !ok {
    90  		t.Fatal("expected NewOCIPusher to produce an *OCIPusher")
    91  	}
    92  
    93  	if op.opts.registryClient != registryClient {
    94  		t.Errorf("Expected NewOCIPusher to contain %p as RegistryClient, got %p", registryClient, op.opts.registryClient)
    95  	}
    96  }
    97  

View as plain text