github.com/sgoings/helm@v2.0.0-alpha.2.0.20170406211108-734e92851ac3+incompatible/pkg/lint/lint_test.go (about)

     1  /*
     2  Copyright 2016 The Kubernetes Authors All rights reserved.
     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  const badChartDir = "rules/testdata/badchartfile"
    28  const badValuesFileDir = "rules/testdata/badvaluesfile"
    29  const badYamlFileDir = "rules/testdata/albatross"
    30  const goodChartDir = "rules/testdata/goodone"
    31  
    32  func TestBadChart(t *testing.T) {
    33  	m := All(badChartDir).Messages
    34  	if len(m) != 5 {
    35  		t.Errorf("Number of errors %v", len(m))
    36  		t.Errorf("All didn't fail with expected errors, got %#v", m)
    37  	}
    38  	// There should be one INFO, 2 WARNINGs and one ERROR messages, check for them
    39  	var i, w, e, e2, e3 bool
    40  	for _, msg := range m {
    41  		if msg.Severity == support.InfoSev {
    42  			if strings.Contains(msg.Err.Error(), "icon is recommended") {
    43  				i = true
    44  			}
    45  		}
    46  		if msg.Severity == support.WarningSev {
    47  			if strings.Contains(msg.Err.Error(), "directory not found") {
    48  				w = true
    49  			}
    50  		}
    51  		if msg.Severity == support.ErrorSev {
    52  			if strings.Contains(msg.Err.Error(), "version 0.0.0 is less than or equal to 0") {
    53  				e = true
    54  			}
    55  			if strings.Contains(msg.Err.Error(), "name is required") {
    56  				e2 = true
    57  			}
    58  			if strings.Contains(msg.Err.Error(), "directory name (badchartfile) and chart name () must be the same") {
    59  				e3 = true
    60  			}
    61  		}
    62  	}
    63  	if !e || !e2 || !e3 || !w || !i {
    64  		t.Errorf("Didn't find all the expected errors, got %#v", m)
    65  	}
    66  }
    67  
    68  func TestInvalidYaml(t *testing.T) {
    69  	m := All(badYamlFileDir).Messages
    70  	if len(m) != 1 {
    71  		t.Errorf("All didn't fail with expected errors, got %#v", m)
    72  	}
    73  	if !strings.Contains(m[0].Err.Error(), "deliberateSyntaxError") {
    74  		t.Errorf("All didn't have the error for deliberateSyntaxError")
    75  	}
    76  }
    77  
    78  func TestBadValues(t *testing.T) {
    79  	m := All(badValuesFileDir).Messages
    80  	if len(m) != 1 {
    81  		t.Errorf("All didn't fail with expected errors, got %#v", m)
    82  	}
    83  	if !strings.Contains(m[0].Err.Error(), "cannot unmarshal") {
    84  		t.Errorf("All didn't have the error for invalid key format: %s", m[0].Err)
    85  	}
    86  }
    87  
    88  func TestGoodChart(t *testing.T) {
    89  	m := All(goodChartDir).Messages
    90  	if len(m) != 0 {
    91  		t.Errorf("All failed but shouldn't have: %#v", m)
    92  	}
    93  }