mirror of https://github.com/helm/helm
parent
62cb6ce45d
commit
7edce9b82b
@ -0,0 +1,13 @@
|
|||||||
|
name: frobnitz
|
||||||
|
description: This is a frobniz.
|
||||||
|
version: "garbage"
|
||||||
|
keywords:
|
||||||
|
- bad bad chart file
|
||||||
|
maintainers:
|
||||||
|
- name: The Helm Team
|
||||||
|
email: helm@example.com
|
||||||
|
- name: Someone Else
|
||||||
|
email: nobody@example.com
|
||||||
|
source:
|
||||||
|
- https://example.com/foo/bar
|
||||||
|
home: http://example.com
|
@ -0,0 +1,57 @@
|
|||||||
|
package lint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const badChartDir = "testdata/badchartversion"
|
||||||
|
const badYamlFileDir = "testdata/albatross"
|
||||||
|
const goodChartDir = "testdata/goodone"
|
||||||
|
|
||||||
|
func TestBadChart(t *testing.T) {
|
||||||
|
m := All(badChartDir)
|
||||||
|
if len(m) != 3 {
|
||||||
|
t.Errorf("All didn't fail with expected errors, got %#v", m)
|
||||||
|
}
|
||||||
|
// There should be INFO, WARNING and ERROR messages, check for them
|
||||||
|
var i, w, e = false, false, false
|
||||||
|
for _, msg := range m {
|
||||||
|
if msg.Severity == InfoSev {
|
||||||
|
if strings.Contains(msg.Text, "values.toml") {
|
||||||
|
i = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msg.Severity == WarningSev {
|
||||||
|
if strings.Contains(msg.Text, "No templates") {
|
||||||
|
w = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if msg.Severity == ErrorSev {
|
||||||
|
if strings.Contains(msg.Text, "Chart.yaml does not exist") {
|
||||||
|
e = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !i || !w || !e {
|
||||||
|
t.Errorf("Didn't find all the expected errors, got %#v", m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInvalidYaml(t *testing.T) {
|
||||||
|
m := All(badYamlFileDir)
|
||||||
|
if len(m) != 1 {
|
||||||
|
t.Errorf("All didn't fail with expected errors")
|
||||||
|
}
|
||||||
|
if !strings.Contains(m[0].Text, "deliberateSyntaxError") {
|
||||||
|
t.Errorf("All didn't have the error for deliberateSyntaxError")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoodChart(t *testing.T) {
|
||||||
|
m := All(goodChartDir)
|
||||||
|
if len(m) != 0 {
|
||||||
|
t.Errorf("All failed but shouldn't have: %#v", m)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
name: goodone
|
||||||
|
description: good testing chart
|
||||||
|
version: 199.44.12345-Alpha.1+cafe009
|
@ -0,0 +1,2 @@
|
|||||||
|
metadata:
|
||||||
|
name: {{.name | default "foo" | title}}
|
@ -0,0 +1 @@
|
|||||||
|
name = "goodone here"
|
@ -0,0 +1,23 @@
|
|||||||
|
package lint
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/kubernetes/helm/pkg/chart"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Values lints a chart's values.toml file.
|
||||||
|
func Values(basepath string) (messages []Message) {
|
||||||
|
vf := filepath.Join(basepath, "values.toml")
|
||||||
|
messages = []Message{}
|
||||||
|
if _, err := os.Stat(vf); err != nil {
|
||||||
|
messages = append(messages, Message{Severity: InfoSev, Text: "No values.toml file"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, err := chart.ReadValuesFile(vf)
|
||||||
|
if err != nil {
|
||||||
|
messages = append(messages, Message{Severity: ErrorSev, Text: err.Error()})
|
||||||
|
}
|
||||||
|
return messages
|
||||||
|
}
|
Loading…
Reference in new issue