github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/release/chart_internal_test.go (about)

     1  package release
     2  
     3  import (
     4  	"reflect"
     5  	"slices"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/suite"
     9  	"helm.sh/helm/v3/pkg/action"
    10  	"helm.sh/helm/v3/pkg/chart"
    11  )
    12  
    13  type ChartInternalTestSuite struct {
    14  	suite.Suite
    15  }
    16  
    17  func TestChartInternalTestSuite(t *testing.T) {
    18  	t.Parallel()
    19  	suite.Run(t, new(ChartInternalTestSuite))
    20  }
    21  
    22  // TestChartTypeFields checks that all fields of helm upgrade action exist in config structure.
    23  func (ts *ChartInternalTestSuite) TestChartTypeFields() {
    24  	skipFields := []string{
    25  		"Name",
    26  	}
    27  
    28  	a := Chart{}
    29  	aa := reflect.ValueOf(a).Type()
    30  	fieldsR := make([]string, aa.NumField())
    31  
    32  	b := action.ChartPathOptions{}
    33  	bb := reflect.ValueOf(b).Type()
    34  
    35  	for i := range fieldsR {
    36  		f := aa.Field(i)
    37  		fieldsR[i] = f.Name
    38  	}
    39  
    40  	for i := range bb.NumField() {
    41  		f := bb.Field(i)
    42  		if !f.IsExported() {
    43  			continue
    44  		}
    45  		if !slices.Contains(skipFields, f.Name) {
    46  			ts.Require().Contains(fieldsR, f.Name)
    47  		}
    48  	}
    49  }
    50  
    51  func (ts *ChartInternalTestSuite) TestChartCheckMissingDependency() {
    52  	rel := NewConfig()
    53  	err := rel.chartCheck(&chart.Chart{
    54  		Metadata: &chart.Metadata{
    55  			Dependencies: []*chart.Dependency{
    56  				{
    57  					Name: ts.T().Name(),
    58  				},
    59  			},
    60  		},
    61  	})
    62  
    63  	ts.Require().ErrorContains(err, "found in Chart.yaml, but missing in charts/ directory")
    64  }
    65  
    66  func (ts *ChartInternalTestSuite) TestChartCheckInvalidType() {
    67  	rel := NewConfig()
    68  	err := rel.chartCheck(&chart.Chart{
    69  		Metadata: &chart.Metadata{
    70  			Type: "library",
    71  		},
    72  	})
    73  
    74  	ts.Require().NoError(err)
    75  }
    76  
    77  func (ts *ChartInternalTestSuite) TestChartCheckDeprecated() {
    78  	rel := NewConfig()
    79  	err := rel.chartCheck(&chart.Chart{
    80  		Metadata: &chart.Metadata{
    81  			Deprecated: true,
    82  		},
    83  	})
    84  
    85  	ts.Require().NoError(err)
    86  }