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

     1  package release
     2  
     3  import (
     4  	"reflect"
     5  	"slices"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/suite"
    10  )
    11  
    12  type ConfigInternalTestSuite struct {
    13  	suite.Suite
    14  }
    15  
    16  // TestConfigHelmTypeFields checks that all fields of helm upgrade action exist in config structure.
    17  func (s *ConfigInternalTestSuite) TestConfigHelmTypeFields() {
    18  	skipFields := []string{
    19  		"ChartPathOptions",
    20  		"Install",
    21  		"Namespace",
    22  		"DryRun",
    23  		"DryRunOption",
    24  		"Description",
    25  		"PostRenderer",
    26  		"DependencyUpdate",
    27  		"Lock",
    28  		"Devel", // we removed that to force everyone specify the version
    29  	}
    30  
    31  	r := NewConfig()
    32  	rr := reflect.ValueOf(r).Elem().Type()
    33  	fieldsR := make([]string, 0, rr.NumField())
    34  
    35  	c := r.newUpgrade()
    36  	rc := reflect.ValueOf(c).Elem().Type()
    37  
    38  	for i := range rr.NumField() {
    39  		f := rr.Field(i)
    40  		if !f.IsExported() {
    41  			continue
    42  		}
    43  		if strings.HasSuffix(f.Name, "F") {
    44  			continue
    45  		}
    46  
    47  		fieldsR = append(fieldsR, f.Name)
    48  	}
    49  
    50  	for i := range rc.NumField() {
    51  		f := rc.Field(i)
    52  		if !f.IsExported() {
    53  			continue
    54  		}
    55  		if slices.Contains(skipFields, f.Name) {
    56  			continue
    57  		}
    58  
    59  		s.Containsf(fieldsR, f.Name, "helm upgrade field %q is not supported by helmwave config", f.Name)
    60  	}
    61  }
    62  
    63  func TestConfigInternalTestSuite(t *testing.T) {
    64  	t.Parallel()
    65  	suite.Run(t, new(ConfigInternalTestSuite))
    66  }