...

Source file src/helm.sh/helm/v3/pkg/action/dependency_test.go

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

     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 action
    18  
    19  import (
    20  	"bytes"
    21  	"os"
    22  	"path/filepath"
    23  	"testing"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  
    27  	"helm.sh/helm/v3/internal/test"
    28  	"helm.sh/helm/v3/pkg/chart"
    29  	"helm.sh/helm/v3/pkg/chartutil"
    30  )
    31  
    32  func TestList(t *testing.T) {
    33  	for _, tcase := range []struct {
    34  		chart  string
    35  		golden string
    36  	}{
    37  		{
    38  			chart:  "testdata/charts/chart-with-compressed-dependencies",
    39  			golden: "output/list-compressed-deps.txt",
    40  		},
    41  		{
    42  			chart:  "testdata/charts/chart-with-compressed-dependencies-2.1.8.tgz",
    43  			golden: "output/list-compressed-deps-tgz.txt",
    44  		},
    45  		{
    46  			chart:  "testdata/charts/chart-with-uncompressed-dependencies",
    47  			golden: "output/list-uncompressed-deps.txt",
    48  		},
    49  		{
    50  			chart:  "testdata/charts/chart-with-uncompressed-dependencies-2.1.8.tgz",
    51  			golden: "output/list-uncompressed-deps-tgz.txt",
    52  		},
    53  		{
    54  			chart:  "testdata/charts/chart-missing-deps",
    55  			golden: "output/list-missing-deps.txt",
    56  		},
    57  	} {
    58  		buf := bytes.Buffer{}
    59  		if err := NewDependency().List(tcase.chart, &buf); err != nil {
    60  			t.Fatal(err)
    61  		}
    62  		test.AssertGoldenString(t, buf.String(), tcase.golden)
    63  	}
    64  }
    65  
    66  // TestDependencyStatus_Dashes is a regression test to make sure that dashes in
    67  // chart names do not cause resolution problems.
    68  func TestDependencyStatus_Dashes(t *testing.T) {
    69  	// Make a temp dir
    70  	dir := t.TempDir()
    71  
    72  	chartpath := filepath.Join(dir, "charts")
    73  	if err := os.MkdirAll(chartpath, 0700); err != nil {
    74  		t.Fatal(err)
    75  	}
    76  
    77  	// Add some fake charts
    78  	first := buildChart(withName("first-chart"))
    79  	_, err := chartutil.Save(first, chartpath)
    80  	if err != nil {
    81  		t.Fatal(err)
    82  	}
    83  
    84  	second := buildChart(withName("first-chart-second-chart"))
    85  	_, err = chartutil.Save(second, chartpath)
    86  	if err != nil {
    87  		t.Fatal(err)
    88  	}
    89  
    90  	dep := &chart.Dependency{
    91  		Name:    "first-chart",
    92  		Version: "0.1.0",
    93  	}
    94  
    95  	// Now try to get the deps
    96  	stat := NewDependency().dependencyStatus(dir, dep, first)
    97  	if stat != "ok" {
    98  		t.Errorf("Unexpected status: %q", stat)
    99  	}
   100  }
   101  
   102  func TestStatArchiveForStatus(t *testing.T) {
   103  	// Make a temp dir
   104  	dir := t.TempDir()
   105  
   106  	chartpath := filepath.Join(dir, "charts")
   107  	if err := os.MkdirAll(chartpath, 0700); err != nil {
   108  		t.Fatal(err)
   109  	}
   110  
   111  	// unsaved chart
   112  	lilith := buildChart(withName("lilith"))
   113  
   114  	// dep referring to chart
   115  	dep := &chart.Dependency{
   116  		Name:    "lilith",
   117  		Version: "1.2.3",
   118  	}
   119  
   120  	is := assert.New(t)
   121  
   122  	lilithpath := filepath.Join(chartpath, "lilith-1.2.3.tgz")
   123  	is.Empty(statArchiveForStatus(lilithpath, dep))
   124  
   125  	// save the chart (version 0.1.0, because that is the default)
   126  	where, err := chartutil.Save(lilith, chartpath)
   127  	is.NoError(err)
   128  
   129  	// Should get "wrong version" because we asked for 1.2.3 and got 0.1.0
   130  	is.Equal("wrong version", statArchiveForStatus(where, dep))
   131  
   132  	// Break version on dep
   133  	dep = &chart.Dependency{
   134  		Name:    "lilith",
   135  		Version: "1.2.3.4.5",
   136  	}
   137  	is.Equal("invalid version", statArchiveForStatus(where, dep))
   138  
   139  	// Break the name
   140  	dep = &chart.Dependency{
   141  		Name:    "lilith2",
   142  		Version: "1.2.3",
   143  	}
   144  	is.Equal("misnamed", statArchiveForStatus(where, dep))
   145  
   146  	// Now create the right version
   147  	dep = &chart.Dependency{
   148  		Name:    "lilith",
   149  		Version: "0.1.0",
   150  	}
   151  	is.Equal("ok", statArchiveForStatus(where, dep))
   152  }
   153  

View as plain text