Skip to content

Commit

Permalink
Update test files related to PR event
Browse files Browse the repository at this point in the history
  • Loading branch information
wsan3 committed Mar 12, 2024
1 parent 802d90f commit 361dac1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions library/actions/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func testPull() *Pull {
pr.SetSynchronize(true)
pr.SetEdited(false)
pr.SetReopened(true)
pr.SetLabeled(false)

return pr
}
4 changes: 4 additions & 0 deletions library/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func (e *Events) List() []string {
eventSlice = append(eventSlice, constants.EventPull+":"+constants.ActionReopened)
}

if e.GetPullRequest().GetLabeled() {
eventSlice = append(eventSlice, constants.EventPull+":"+constants.ActionLabeled)
}

if e.GetPush().GetTag() {
eventSlice = append(eventSlice, constants.EventTag)
}
Expand Down
5 changes: 5 additions & 0 deletions library/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func TestLibrary_Events_List(t *testing.T) {

wantTwo := []string{
"pull_request:edited",
"pull_request:labeled",
"deployment",
"comment:edited",
"delete:tag",
Expand Down Expand Up @@ -166,6 +167,7 @@ func TestLibrary_Events_NewEventsFromMask_ToDatabase(t *testing.T) {
constants.AllowPushDeleteTag |
constants.AllowPullEdit |
constants.AllowCommentEdit |
constants.AllowPullLabel |
constants.AllowDeployCreate,
)

Expand Down Expand Up @@ -210,6 +212,7 @@ func TestLibrary_Events_Allowed(t *testing.T) {
{event: "pull_request", action: "synchronize", want: true},
{event: "pull_request", action: "edited", want: false},
{event: "pull_request", action: "reopened", want: true},
{event: "pull_request", action: "labeled", want: false},
{event: "deployment", want: false},
{event: "comment", action: "created", want: true},
{event: "comment", action: "edited", want: false},
Expand Down Expand Up @@ -249,6 +252,7 @@ func testEvents() (*Events, *Events) {
Synchronize: &tBool,
Edited: &fBool,
Reopened: &tBool,
Labeled: &fBool,
},
Deployment: &actions.Deploy{
Created: &fBool,
Expand All @@ -274,6 +278,7 @@ func testEvents() (*Events, *Events) {
Synchronize: &fBool,
Edited: &tBool,
Reopened: &fBool,
Labeled: &tBool,
},
Deployment: &actions.Deploy{
Created: &tBool,
Expand Down
4 changes: 2 additions & 2 deletions pipeline/ruleset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ type (
Status Ruletype `json:"status,omitempty" yaml:"status,omitempty"`
Tag Ruletype `json:"tag,omitempty" yaml:"tag,omitempty"`
Target Ruletype `json:"target,omitempty" yaml:"target,omitempty"`
Parallel bool `json:"-" yaml:"-"`
Label Ruletype `json:"label,omitempty" yaml:"label,omitempty"`
Parallel bool `json:"-" yaml:"-"`
}

// Ruletype is the pipeline representation of an element
Expand All @@ -58,8 +58,8 @@ type (
Status string `json:"status,omitempty" yaml:"status,omitempty"`
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
Target string `json:"target,omitempty" yaml:"target,omitempty"`
Parallel bool `json:"-" yaml:"-"`
Label string `json:"label,omitempty" yaml:"label,omitempty"`
Parallel bool `json:"-" yaml:"-"`
}
)

Expand Down
20 changes: 16 additions & 4 deletions pipeline/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,20 @@ func TestPipeline_Rules_Match(t *testing.T) {
},
{
rules: &Rules{Event: []string{"push", "pull_request"}, Tag: []string{"release/*"}},
data: &RuleData{Branch: "main", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""},
data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""},
operator: "or",
want: false,
},
{
rules: &Rules{Event: []string{"pull_request:labeled"}, Label: []string{"enhancement", "documentation"}},
data: &RuleData{Branch: "main", Event: "pull_request:labeled", Repo: "octocat/hello-world", Status: "pending", Label: "documentation"},
operator: "and",
want: true,
},
{
rules: &Rules{Event: []string{"push", "pull_request"}, Tag: []string{"release/*"}},
data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""},
operator: "or",
rules: &Rules{Event: []string{"pull_request:labeled"}, Label: []string{"enhancement", "documentation"}},
data: &RuleData{Branch: "main", Event: "pull_request:labeled", Repo: "octocat/hello-world", Status: "pending", Label: "support"},
operator: "and",
want: false,
},
}
Expand Down Expand Up @@ -572,6 +578,9 @@ func TestPipeline_Ruletype_MatchOr(t *testing.T) {
// Target with filepath matcher
{matcher: "filepath", rule: []string{"production"}, pattern: "production", want: true},
{matcher: "filepath", rule: []string{"stage"}, pattern: "production", want: false},
// Label with filepath matcher
{matcher: "filepath", rule: []string{"enhancement", "documentation"}, pattern: "documentation", want: true},
{matcher: "filepath", rule: []string{"enhancement", "documentation"}, pattern: "question", want: false},
// Empty with regexp matcher
{matcher: "regexp", rule: []string{}, pattern: "main", want: false},
{matcher: "regexp", rule: []string{}, pattern: "push", want: false},
Expand Down Expand Up @@ -599,6 +608,9 @@ func TestPipeline_Ruletype_MatchOr(t *testing.T) {
// Target with regexp matcher
{matcher: "regexp", rule: []string{"production"}, pattern: "production", want: true},
{matcher: "regexp", rule: []string{"stage"}, pattern: "production", want: false},
// Label with regexp matcher
{matcher: "regexp", rule: []string{"enhancement", "documentation"}, pattern: "documentation", want: true},
{matcher: "regexp", rule: []string{"enhancement", "documentation"}, pattern: "question", want: false},
}

// run test
Expand Down
4 changes: 4 additions & 0 deletions yaml/ruleset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestYaml_Ruleset_ToPipeline(t *testing.T) {
Status: []string{"success"},
Tag: []string{"v0.1.0"},
Target: []string{"production"},
Label: []string{"enhancement"},
},
Unless: Rules{
Branch: []string{"main"},
Expand All @@ -53,6 +54,7 @@ func TestYaml_Ruleset_ToPipeline(t *testing.T) {
Status: []string{"success"},
Tag: []string{"v0.1.0"},
Target: []string{"production"},
Label: []string{"enhancement"},
},
Unless: pipeline.Rules{
Branch: []string{"main"},
Expand Down Expand Up @@ -173,6 +175,7 @@ func TestYaml_Rules_ToPipeline(t *testing.T) {
Status: []string{"success"},
Tag: []string{"v0.1.0"},
Target: []string{"production"},
Label: []string{"enhancement"},
},
want: &pipeline.Rules{
Branch: []string{"main"},
Expand All @@ -183,6 +186,7 @@ func TestYaml_Rules_ToPipeline(t *testing.T) {
Status: []string{"success"},
Tag: []string{"v0.1.0"},
Target: []string{"production"},
Label: []string{"enhancement"},
},
},
}
Expand Down

0 comments on commit 361dac1

Please sign in to comment.