ensure nil step does not cause problems

This commit is contained in:
Brad Rydzewski
2019-10-17 15:52:05 -07:00
parent b198003a0c
commit 983f1badde
6 changed files with 26 additions and 1 deletions

View File

@@ -77,6 +77,9 @@ func checkPipeline(pipeline *resource.Pipeline, trusted bool) error {
func checkSteps(pipeline *resource.Pipeline, trusted bool) error {
steps := append(pipeline.Services, pipeline.Steps...)
for _, step := range steps {
if step == nil {
return errors.New("linter: nil step")
}
if err := checkStep(step, trusted); err != nil {
return err
}

View File

@@ -39,6 +39,9 @@ func lint(pipeline *Pipeline) error {
// ensure pipeline steps are not unique.
names := map[string]struct{}{}
for _, step := range pipeline.Steps {
if step == nil {
return errors.New("Linter: detected nil step")
}
if step.Name == "" {
return errors.New("Linter: invalid or missing step name")
}

View File

@@ -105,6 +105,14 @@ func TestParseLintErr(t *testing.T) {
}
}
func TestParseLintNilStep(t *testing.T) {
_, err := manifest.ParseFile("testdata/nilstep.yml")
if err == nil {
t.Errorf("Expect linter returns error")
return
}
}
func TestParseNoMatch(t *testing.T) {
r := &manifest.RawResource{Kind: "pipeline", Type: "exec"}
_, match, _ := parse(r)

9
engine/resource/testdata/nilstep.yml vendored Normal file
View File

@@ -0,0 +1,9 @@
---
kind: pipeline
type: docker
name: test
steps:
- ~
...