Skip to content

Commit

Permalink
adding implicit parsePipelines tests (#40)
Browse files Browse the repository at this point in the history
tests for when implicit include paths are set at step and trigger positions
  • Loading branch information
Jim Sheldon authored Nov 30, 2020
1 parent 4138532 commit a7f5c2f
Showing 1 changed file with 117 additions and 0 deletions.
117 changes: 117 additions & 0 deletions plugin/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,123 @@ name: default
}
}

func TestParsePipelinesStepPathImplicitAndOptionalIncludePipeline(t *testing.T) {
req := &converter.Request{
Build: drone.Build{},
Repo: drone.Repo{
Slug: "somewhere/over-the-rainbow",
Config: ".drone.yml",
},
}

before := `
kind: pipeline
type: docker
name: default
steps:
- name: message
image: busybox
commands:
- echo "README.md was changed"
when:
paths:
- README.md
`

// parsed pipelines don't have a leading newline...
after := `kind: pipeline
type: docker
steps:
- when:
paths:
include:
- README.md
commands:
- echo "README.md was changed"
image: busybox
name: message
name: default
`

changedFiles := []string{"README.md"}
resources, err := parsePipelines(before, req.Build, req.Repo, changedFiles)
if err != nil {
t.Error(err)
return
}

c, err := marshal(resources)
if err != nil {
t.Error(err)
return
}
config := string(c)

if want, got := after, config; want != got {
t.Errorf("Want %v got %v", want, got)
}
}

func TestParsePipelinesTriggerPathImplicitAndOptionalIncludePipeline(t *testing.T) {
req := &converter.Request{
Build: drone.Build{},
Repo: drone.Repo{
Slug: "somewhere/over-the-rainbow",
Config: ".drone.yml",
},
}

before := `
kind: pipeline
type: docker
name: default
trigger:
paths:
- README.md
steps:
- name: message
image: busybox
commands:
- echo "README.md was changed"
`

// parsed pipelines don't have a leading newline...
after := `kind: pipeline
type: docker
steps:
- commands:
- echo "README.md was changed"
image: busybox
name: message
trigger:
paths:
include:
- README.md
name: default
`

changedFiles := []string{"README.md"}
resources, err := parsePipelines(before, req.Build, req.Repo, changedFiles)
if err != nil {
t.Error(err)
return
}

c, err := marshal(resources)
if err != nil {
t.Error(err)
return
}
config := string(c)

if want, got := after, config; want != got {
t.Errorf("Want %v got %v", want, got)
}
}

func TestParsePipelinesStepPathExcludeAnchorPipeline(t *testing.T) {
req := &converter.Request{
Build: drone.Build{},
Expand Down

0 comments on commit a7f5c2f

Please sign in to comment.