github.com/latiif/helm@v2.15.0+incompatible/pkg/lint/lint_test.go (about) 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 lint 18 19 import ( 20 "strings" 21 22 "k8s.io/helm/pkg/lint/support" 23 24 "testing" 25 ) 26 27 var values = []byte{} 28 29 const ( 30 namespace = "testNamespace" 31 strict = false 32 badChartDir = "rules/testdata/badchartfile" 33 badValuesFileDir = "rules/testdata/badvaluesfile" 34 badYamlFileDir = "rules/testdata/albatross" 35 goodChartDir = "rules/testdata/goodone" 36 ) 37 38 func TestBadChart(t *testing.T) { 39 m := All(badChartDir, values, namespace, strict).Messages 40 if len(m) != 6 { 41 t.Errorf("Number of errors %v", len(m)) 42 t.Errorf("All didn't fail with expected errors, got %#v", m) 43 } 44 // There should be one INFO, 2 WARNINGs and one ERROR messages, check for them 45 var i, w, e, e2, e3, e4 bool 46 for _, msg := range m { 47 if msg.Severity == support.InfoSev { 48 if strings.Contains(msg.Err.Error(), "icon is recommended") { 49 i = true 50 } 51 } 52 if msg.Severity == support.WarningSev { 53 if strings.Contains(msg.Err.Error(), "directory not found") { 54 w = true 55 } 56 } 57 if msg.Severity == support.ErrorSev { 58 if strings.Contains(msg.Err.Error(), "version '0.0.0.0' is not a valid SemVer") { 59 e = true 60 } 61 if strings.Contains(msg.Err.Error(), "name is required") { 62 e2 = true 63 } 64 if strings.Contains(msg.Err.Error(), "directory name (badchartfile) and chart name () must be the same") { 65 e3 = true 66 } 67 68 if strings.Contains(msg.Err.Error(), "apiVersion is required") { 69 e4 = true 70 } 71 } 72 } 73 if !e || !e2 || !e3 || !e4 || !w || !i { 74 t.Errorf("Didn't find all the expected errors, got %#v", m) 75 } 76 } 77 78 func TestInvalidYaml(t *testing.T) { 79 m := All(badYamlFileDir, values, namespace, strict).Messages 80 if len(m) != 1 { 81 t.Fatalf("All didn't fail with expected errors, got %#v", m) 82 } 83 if !strings.Contains(m[0].Err.Error(), "deliberateSyntaxError") { 84 t.Errorf("All didn't have the error for deliberateSyntaxError") 85 } 86 } 87 88 func TestBadValues(t *testing.T) { 89 m := All(badValuesFileDir, values, namespace, strict).Messages 90 if len(m) != 1 { 91 t.Fatalf("All didn't fail with expected errors, got %#v", m) 92 } 93 if !strings.Contains(m[0].Err.Error(), "cannot unmarshal") { 94 t.Errorf("All didn't have the error for invalid key format: %s", m[0].Err) 95 } 96 } 97 98 func TestGoodChart(t *testing.T) { 99 m := All(goodChartDir, values, namespace, strict).Messages 100 if len(m) != 0 { 101 t.Errorf("All failed but shouldn't have: %#v", m) 102 } 103 }