mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-03-03 10:31:06 +00:00
update tests
This commit is contained in:
parent
6396701222
commit
80ed91ff70
6 changed files with 55 additions and 11 deletions
|
@ -136,7 +136,7 @@ func Test_parse(t *testing.T) {
|
|||
g.Assert(pipeline.Commit).Equal(hook.PullRequest.Head.Sha)
|
||||
g.Assert(pipeline.Ref).Equal("refs/pull/1/head")
|
||||
g.Assert(pipeline.ForgeURL).Equal("http://forgejo.golang.org/gordon/hello-world/pull/1")
|
||||
g.Assert(pipeline.Branch).Equal("main")
|
||||
g.Assert(pipeline.Branch).Equal("feature/changes")
|
||||
g.Assert(pipeline.Refspec).Equal("feature/changes:main")
|
||||
g.Assert(pipeline.Message).Equal(hook.PullRequest.Title)
|
||||
g.Assert(pipeline.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")
|
||||
|
|
|
@ -207,7 +207,7 @@ func TestForgejoParser(t *testing.T) {
|
|||
Author: "gordon",
|
||||
Event: "pull_request",
|
||||
Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||
Branch: "main",
|
||||
Branch: "feature/changes",
|
||||
Ref: "refs/pull/1/head",
|
||||
Refspec: "feature/changes:main",
|
||||
Title: "Update the README with new information",
|
||||
|
@ -246,7 +246,7 @@ func TestForgejoParser(t *testing.T) {
|
|||
Author: "test",
|
||||
Event: "pull_request",
|
||||
Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25",
|
||||
Branch: "main",
|
||||
Branch: "test-patch-1",
|
||||
Ref: "refs/pull/2/head",
|
||||
Refspec: "test-patch-1:main",
|
||||
Title: "New Pull",
|
||||
|
@ -287,7 +287,7 @@ func TestForgejoParser(t *testing.T) {
|
|||
Author: "anbraten",
|
||||
Event: "pull_request_closed",
|
||||
Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4",
|
||||
Branch: "main",
|
||||
Branch: "anbraten-patch-1",
|
||||
Ref: "refs/pull/1/head",
|
||||
Refspec: "anbraten-patch-1:main",
|
||||
Title: "Adjust file",
|
||||
|
@ -325,7 +325,7 @@ func TestForgejoParser(t *testing.T) {
|
|||
Author: "anbraten",
|
||||
Event: "pull_request_closed",
|
||||
Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4",
|
||||
Branch: "main",
|
||||
Branch: "anbraten-patch-1",
|
||||
Ref: "refs/pull/1/head",
|
||||
Refspec: "anbraten-patch-1:main",
|
||||
Title: "Adjust file",
|
||||
|
|
|
@ -137,7 +137,7 @@ func Test_parse(t *testing.T) {
|
|||
g.Assert(pipeline.Commit).Equal(hook.PullRequest.Head.Sha)
|
||||
g.Assert(pipeline.Ref).Equal("refs/pull/1/head")
|
||||
g.Assert(pipeline.ForgeURL).Equal("http://gitea.golang.org/gordon/hello-world/pull/1")
|
||||
g.Assert(pipeline.Branch).Equal("main")
|
||||
g.Assert(pipeline.Branch).Equal("feature/changes")
|
||||
g.Assert(pipeline.Refspec).Equal("feature/changes:main")
|
||||
g.Assert(pipeline.Message).Equal(hook.PullRequest.Title)
|
||||
g.Assert(pipeline.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")
|
||||
|
|
|
@ -208,7 +208,7 @@ func TestGiteaParser(t *testing.T) {
|
|||
Author: "gordon",
|
||||
Event: "pull_request",
|
||||
Commit: "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
|
||||
Branch: "main",
|
||||
Branch: "feature/changes",
|
||||
Ref: "refs/pull/1/head",
|
||||
Refspec: "feature/changes:main",
|
||||
Title: "Update the README with new information",
|
||||
|
@ -247,7 +247,7 @@ func TestGiteaParser(t *testing.T) {
|
|||
Author: "test",
|
||||
Event: "pull_request",
|
||||
Commit: "788ed8d02d3b7fcfcf6386dbcbca696aa1d4dc25",
|
||||
Branch: "main",
|
||||
Branch: "test-patch-1",
|
||||
Ref: "refs/pull/2/head",
|
||||
Refspec: "test-patch-1:main",
|
||||
Title: "New Pull",
|
||||
|
@ -288,7 +288,7 @@ func TestGiteaParser(t *testing.T) {
|
|||
Author: "anbraten",
|
||||
Event: "pull_request_closed",
|
||||
Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4",
|
||||
Branch: "main",
|
||||
Branch: "anbraten-patch-1",
|
||||
Ref: "refs/pull/1/head",
|
||||
Refspec: "anbraten-patch-1:main",
|
||||
Title: "Adjust file",
|
||||
|
@ -326,7 +326,7 @@ func TestGiteaParser(t *testing.T) {
|
|||
Author: "anbraten",
|
||||
Event: "pull_request_closed",
|
||||
Commit: "d555a5dd07f4d0148a58d4686ec381502ae6a2d4",
|
||||
Branch: "main",
|
||||
Branch: "anbraten-patch-1",
|
||||
Ref: "refs/pull/1/head",
|
||||
Refspec: "anbraten-patch-1:main",
|
||||
Title: "Adjust file",
|
||||
|
|
|
@ -209,7 +209,7 @@ func Test_helper(t *testing.T) {
|
|||
g.Assert(err).IsNil()
|
||||
g.Assert(pull).IsNotNil()
|
||||
g.Assert(pipeline.Event).Equal(model.EventPull)
|
||||
g.Assert(pipeline.Branch).Equal(*from.PullRequest.Base.Ref)
|
||||
g.Assert(pipeline.Branch).Equal(*from.PullRequest.Head.Ref)
|
||||
g.Assert(pipeline.Ref).Equal("refs/pull/42/merge")
|
||||
g.Assert(pipeline.Refspec).Equal("changes:main")
|
||||
g.Assert(pipeline.Commit).Equal(*from.PullRequest.Head.SHA)
|
||||
|
|
|
@ -630,3 +630,47 @@ func getMockForge(t *testing.T) forge.Forge {
|
|||
forge.On("URL").Return("https://codeberg.org")
|
||||
return forge
|
||||
}
|
||||
|
||||
func TestPullRequestWhenStep(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := StepBuilder{
|
||||
Forge: getMockForge(t),
|
||||
Repo: &model.Repo{},
|
||||
Curr: &model.Pipeline{
|
||||
Event: model.EventPull,
|
||||
Branch: "feature-branch",
|
||||
},
|
||||
Prev: &model.Pipeline{},
|
||||
Netrc: &model.Netrc{},
|
||||
Secs: []*model.Secret{},
|
||||
Regs: []*model.Registry{},
|
||||
Host: "",
|
||||
Yamls: []*forge_types.FileMeta{
|
||||
{Name: "shouldrun", Data: []byte(`
|
||||
when:
|
||||
event: pull_request
|
||||
steps:
|
||||
xxx:
|
||||
when:
|
||||
event: pull_request
|
||||
image: scratch
|
||||
`)},
|
||||
{Name: "shouldbefiltered", Data: []byte(`
|
||||
steps:
|
||||
build:
|
||||
when:
|
||||
branch: main
|
||||
image: scratch
|
||||
`)},
|
||||
},
|
||||
}
|
||||
|
||||
pipelineItems, err := b.Build()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(pipelineItems) != 1 {
|
||||
t.Fatal("Steps with branch 'main' should not run on pull_request events targeting 'main'")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue