...

Source file src/helm.sh/helm/v3/pkg/registry/client_http_test.go

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

     1  /*
     2  Copyright The Helm Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package registry
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"testing"
    23  
    24  	"github.com/containerd/containerd/errdefs"
    25  	"github.com/stretchr/testify/suite"
    26  )
    27  
    28  type HTTPRegistryClientTestSuite struct {
    29  	TestSuite
    30  }
    31  
    32  func (suite *HTTPRegistryClientTestSuite) SetupSuite() {
    33  	// init test client
    34  	dockerRegistry := setup(&suite.TestSuite, false, false)
    35  
    36  	// Start Docker registry
    37  	go dockerRegistry.ListenAndServe()
    38  }
    39  
    40  func (suite *HTTPRegistryClientTestSuite) TearDownSuite() {
    41  	teardown(&suite.TestSuite)
    42  	os.RemoveAll(suite.WorkspaceDir)
    43  }
    44  
    45  func (suite *HTTPRegistryClientTestSuite) Test_1_Push() {
    46  	testPush(&suite.TestSuite)
    47  }
    48  
    49  func (suite *HTTPRegistryClientTestSuite) Test_2_Pull() {
    50  	testPull(&suite.TestSuite)
    51  }
    52  
    53  func (suite *HTTPRegistryClientTestSuite) Test_3_Tags() {
    54  	testTags(&suite.TestSuite)
    55  }
    56  
    57  func (suite *HTTPRegistryClientTestSuite) Test_4_ManInTheMiddle() {
    58  	ref := fmt.Sprintf("%s/testrepo/supposedlysafechart:9.9.9", suite.CompromisedRegistryHost)
    59  
    60  	// returns content that does not match the expected digest
    61  	_, err := suite.RegistryClient.Pull(ref)
    62  	suite.NotNil(err)
    63  	suite.True(errdefs.IsFailedPrecondition(err))
    64  }
    65  
    66  func TestHTTPRegistryClientTestSuite(t *testing.T) {
    67  	suite.Run(t, new(HTTPRegistryClientTestSuite))
    68  }
    69  

View as plain text