Unverified Commit 0a9bf4f9 authored by Matt Farina's avatar Matt Farina Committed by GitHub

Merge pull request #6754 from karuppiah7890/fix-lint-for-no-package-found-v2

fix silent lint ignore for non existing packaged charts
parents 1f692330 23926365
......@@ -17,7 +17,6 @@ limitations under the License.
package main
import (
"errors"
"fmt"
"io"
"io/ioutil"
......@@ -81,8 +80,6 @@ func newLintCmd(out io.Writer) *cobra.Command {
return cmd
}
var errLintNoChart = errors.New("No chart found for linting (missing Chart.yaml)")
func (l *lintCmd) run() error {
var lowestTolerance int
if l.strict {
......@@ -100,15 +97,16 @@ func (l *lintCmd) run() error {
var total int
var failures int
for _, path := range l.paths {
if linter, err := lintChart(path, rvals, l.namespace, l.strict); err != nil {
linter, err := lintChart(path, rvals, l.namespace, l.strict)
if err != nil {
failures = failures + 1
fmt.Println("==> Skipping", path)
fmt.Println(err)
if err == errLintNoChart {
failures = failures + 1
fmt.Println("")
continue
}
} else {
fmt.Println("==> Linting", path)
fmt.Println("==> Linting", path)
if len(linter.Messages) == 0 {
fmt.Println("Lint OK")
}
......@@ -121,7 +119,6 @@ func (l *lintCmd) run() error {
if linter.HighestSeverity >= lowestTolerance {
failures = failures + 1
}
}
fmt.Println("")
}
......@@ -148,12 +145,12 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support
file, err := os.Open(path)
if err != nil {
return linter, err
return linter, fmt.Errorf("unable to open tar ball %s: %s", path, err.Error())
}
defer file.Close()
if err = chartutil.Expand(tempDir, file); err != nil {
return linter, err
return linter, fmt.Errorf("unable to extract tar ball: %s", err.Error())
}
files, err := ioutil.ReadDir(tempDir)
......@@ -171,7 +168,7 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support
// Guard: Error out if this is not a chart.
if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil {
return linter, errLintNoChart
return linter, fmt.Errorf("unable to check Chart.yaml file in chart: %s", err.Error())
}
return lint.All(chartPath, vals, namespace, strict), nil
......
......@@ -17,6 +17,8 @@ limitations under the License.
package main
import (
"bytes"
"fmt"
"testing"
)
......@@ -70,3 +72,38 @@ func TestLintChart(t *testing.T) {
})
}
}
func TestLinRunForNonExistentChart(t *testing.T) {
t.Run("should error out for non existent tgz chart", func(t *testing.T) {
testCharts := []string{"non-existent-chart.tgz"}
testLint := &lintCmd{
paths: testCharts,
out: bytes.NewBufferString(""),
}
expectedErr := fmt.Errorf("0 chart(s) linted, 1 chart(s) failed")
err := testLint.run()
if err == nil {
t.Errorf("expected error but got no error")
}
if err != nil && (err.Error() != expectedErr.Error()) {
t.Errorf("expected: \"%v\" , but got: \"%v\"", expectedErr, err)
}
})
t.Run("should error out for corrupted tgz chart", func(t *testing.T) {
var corruptedTgzChart = "testdata/testcharts/corrupted-compressed-chart.tgz"
testCharts := []string{corruptedTgzChart}
testLint := &lintCmd{
paths: testCharts,
out: bytes.NewBufferString(""),
}
expectedErr := fmt.Errorf("0 chart(s) linted, 1 chart(s) failed")
err := testLint.run()
if err == nil {
t.Errorf("expected error but got no error")
}
if err != nil && (err.Error() != expectedErr.Error()) {
t.Errorf("expected: \"%v\" , but got: \"%v\"", expectedErr, err)
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment