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:
|
||||
- ~
|
||||
|
||||
...
|
||||
2
go.mod
2
go.mod
@@ -11,7 +11,7 @@ require (
|
||||
github.com/drone/drone-runtime v1.0.7-0.20190729202838-87c84080f4a1
|
||||
github.com/drone/drone-yaml v1.2.2
|
||||
github.com/drone/envsubst v1.0.2
|
||||
github.com/drone/runner-go v1.2.3-0.20191017212814-48a0db6f4ed7
|
||||
github.com/drone/runner-go v1.2.3-0.20191017224419-ef1504fb90be
|
||||
github.com/drone/signal v1.0.0
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/google/go-cmp v0.3.0
|
||||
|
||||
2
go.sum
2
go.sum
@@ -53,6 +53,8 @@ github.com/drone/runner-go v1.2.3-0.20191008184914-35b0486b7f23 h1:sj9myNBjsR7C6
|
||||
github.com/drone/runner-go v1.2.3-0.20191008184914-35b0486b7f23/go.mod h1:GvB5hX023g0n5UZUjMBmudk6givdDDuLcls7Nolm5v8=
|
||||
github.com/drone/runner-go v1.2.3-0.20191017212814-48a0db6f4ed7 h1:qGsY45PRwKdbaKZqa2jswjS5nbLEp1sDXFbVaIcbi4I=
|
||||
github.com/drone/runner-go v1.2.3-0.20191017212814-48a0db6f4ed7/go.mod h1:GvB5hX023g0n5UZUjMBmudk6givdDDuLcls7Nolm5v8=
|
||||
github.com/drone/runner-go v1.2.3-0.20191017224419-ef1504fb90be h1:tk4tW92ajKvIxlepMUX0iOAJ0CFdO5x3LsKP0H30OMs=
|
||||
github.com/drone/runner-go v1.2.3-0.20191017224419-ef1504fb90be/go.mod h1:GvB5hX023g0n5UZUjMBmudk6givdDDuLcls7Nolm5v8=
|
||||
github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI=
|
||||
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
|
||||
Reference in New Issue
Block a user