ensure nil step does not cause problems
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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
9
engine/resource/testdata/nilstep.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: test
|
||||
|
||||
steps:
|
||||
- ~
|
||||
|
||||
...
|
||||
Reference in New Issue
Block a user