mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
Merge pull request #7026 from sco11morgan/remove-lint-chart-name-check
fix(lint): Remove requirement that directory name and chart name match
This commit is contained in:
commit
0b9e24d824
3 changed files with 15 additions and 51 deletions
|
|
@ -35,12 +35,12 @@ const goodChartDir = "rules/testdata/goodone"
|
|||
|
||||
func TestBadChart(t *testing.T) {
|
||||
m := All(badChartDir, values, namespace, strict).Messages
|
||||
if len(m) != 8 {
|
||||
if len(m) != 7 {
|
||||
t.Errorf("Number of errors %v", len(m))
|
||||
t.Errorf("All didn't fail with expected errors, got %#v", m)
|
||||
}
|
||||
// There should be one INFO, 2 WARNINGs and one ERROR messages, check for them
|
||||
var i, w, e, e2, e3, e4, e5, e6 bool
|
||||
var i, w, e, e2, e3, e4, e5 bool
|
||||
for _, msg := range m {
|
||||
if msg.Severity == support.InfoSev {
|
||||
if strings.Contains(msg.Err.Error(), "icon is recommended") {
|
||||
|
|
@ -59,24 +59,21 @@ func TestBadChart(t *testing.T) {
|
|||
if strings.Contains(msg.Err.Error(), "name is required") {
|
||||
e2 = true
|
||||
}
|
||||
if strings.Contains(msg.Err.Error(), "directory name (badchartfile) and chart name () must be the same") {
|
||||
|
||||
if strings.Contains(msg.Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") {
|
||||
e3 = true
|
||||
}
|
||||
|
||||
if strings.Contains(msg.Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") {
|
||||
if strings.Contains(msg.Err.Error(), "chart type is not valid in apiVersion") {
|
||||
e4 = true
|
||||
}
|
||||
|
||||
if strings.Contains(msg.Err.Error(), "chart type is not valid in apiVersion") {
|
||||
e5 = true
|
||||
}
|
||||
|
||||
if strings.Contains(msg.Err.Error(), "dependencies are not valid in the Chart file with apiVersion") {
|
||||
e6 = true
|
||||
e5 = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if !e || !e2 || !e3 || !e4 || !e5 || !e6 || !w || !i {
|
||||
if !e || !e2 || !e3 || !e4 || !e5 || !w || !i {
|
||||
t.Errorf("Didn't find all the expected errors, got %#v", m)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ func Chartfile(linter *support.Linter) {
|
|||
}
|
||||
|
||||
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartName(chartFile))
|
||||
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartNameDirMatch(linter.ChartDir, chartFile))
|
||||
|
||||
// Chart metadata
|
||||
linter.RunLinterRule(support.ErrorSev, chartFileName, validateChartAPIVersion(chartFile))
|
||||
|
|
@ -82,13 +81,6 @@ func validateChartName(cf *chart.Metadata) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func validateChartNameDirMatch(chartDir string, cf *chart.Metadata) error {
|
||||
if cf.Name != filepath.Base(chartDir) {
|
||||
return errors.Errorf("directory name (%s) and chart name (%s) must be the same", filepath.Base(chartDir), cf.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateChartAPIVersion(cf *chart.Metadata) error {
|
||||
if cf.APIVersion == "" {
|
||||
return errors.New("apiVersion is required. The value must be either \"v1\" or \"v2\"")
|
||||
|
|
|
|||
|
|
@ -30,18 +30,15 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
badChartDir = "testdata/badchartfile"
|
||||
goodChartDir = "testdata/goodone"
|
||||
badChartDir = "testdata/badchartfile"
|
||||
)
|
||||
|
||||
var (
|
||||
badChartFilePath = filepath.Join(badChartDir, "Chart.yaml")
|
||||
goodChartFilePath = filepath.Join(goodChartDir, "Chart.yaml")
|
||||
nonExistingChartFilePath = filepath.Join(os.TempDir(), "Chart.yaml")
|
||||
)
|
||||
|
||||
var badChart, _ = chartutil.LoadChartfile(badChartFilePath)
|
||||
var goodChart, _ = chartutil.LoadChartfile(goodChartFilePath)
|
||||
|
||||
// Validation functions Test
|
||||
func TestValidateChartYamlNotDirectory(t *testing.T) {
|
||||
|
|
@ -73,24 +70,6 @@ func TestValidateChartName(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestValidateChartNameDirMatch(t *testing.T) {
|
||||
err := validateChartNameDirMatch(goodChartDir, goodChart)
|
||||
if err != nil {
|
||||
t.Errorf("validateChartNameDirMatch to return no error, gor a linter error")
|
||||
}
|
||||
// It has not name
|
||||
err = validateChartNameDirMatch(badChartDir, badChart)
|
||||
if err == nil {
|
||||
t.Errorf("validatechartnamedirmatch to return a linter error, got no error")
|
||||
}
|
||||
|
||||
// Wrong path
|
||||
err = validateChartNameDirMatch(badChartDir, goodChart)
|
||||
if err == nil {
|
||||
t.Errorf("validatechartnamedirmatch to return a linter error, got no error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateChartVersion(t *testing.T) {
|
||||
var failTest = []struct {
|
||||
Version string
|
||||
|
|
@ -209,36 +188,32 @@ func TestChartfile(t *testing.T) {
|
|||
Chartfile(&linter)
|
||||
msgs := linter.Messages
|
||||
|
||||
if len(msgs) != 7 {
|
||||
t.Errorf("Expected 7 errors, got %d", len(msgs))
|
||||
if len(msgs) != 6 {
|
||||
t.Errorf("Expected 6 errors, got %d", len(msgs))
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[0].Err.Error(), "name is required") {
|
||||
t.Errorf("Unexpected message 0: %s", msgs[0].Err)
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[1].Err.Error(), "directory name (badchartfile) and chart name () must be the same") {
|
||||
if !strings.Contains(msgs[1].Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") {
|
||||
t.Errorf("Unexpected message 1: %s", msgs[1].Err)
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[2].Err.Error(), "apiVersion is required. The value must be either \"v1\" or \"v2\"") {
|
||||
if !strings.Contains(msgs[2].Err.Error(), "version '0.0.0.0' is not a valid SemVer") {
|
||||
t.Errorf("Unexpected message 2: %s", msgs[2].Err)
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[3].Err.Error(), "version '0.0.0.0' is not a valid SemVer") {
|
||||
if !strings.Contains(msgs[3].Err.Error(), "icon is recommended") {
|
||||
t.Errorf("Unexpected message 3: %s", msgs[3].Err)
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[4].Err.Error(), "icon is recommended") {
|
||||
if !strings.Contains(msgs[4].Err.Error(), "chart type is not valid in apiVersion") {
|
||||
t.Errorf("Unexpected message 4: %s", msgs[4].Err)
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[5].Err.Error(), "chart type is not valid in apiVersion") {
|
||||
if !strings.Contains(msgs[5].Err.Error(), "dependencies are not valid in the Chart file with apiVersion") {
|
||||
t.Errorf("Unexpected message 5: %s", msgs[5].Err)
|
||||
}
|
||||
|
||||
if !strings.Contains(msgs[6].Err.Error(), "dependencies are not valid in the Chart file with apiVersion") {
|
||||
t.Errorf("Unexpected message 6: %s", msgs[6].Err)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue