Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files: tests for issue #33 #132

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions pkg/labeler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func TestHandleEvent(t *testing.T) {
"new_file",
"dependabot.yml",
"\\/root\\/.+\\/test.md", // captures root/sub/test.md
"\\/.+\\/test.md", // captures /sub/test.md
},
// our test file has a diff in four files,
// including added/removed which have a
Expand Down Expand Up @@ -369,6 +370,7 @@ func TestHandleEvent(t *testing.T) {
"dependabot.yml",
"root/**/test", // dodgy regex should NOT break the evaluation
"\\/root\\/.+\\/test.md", // captures root/sub/test.md
"\\/.+\\/test.md", // captures /sub/test.md
},
// our test file has a diff in four files,
// including added/removed which have a
Expand Down Expand Up @@ -532,6 +534,63 @@ func TestHandleEvent(t *testing.T) {
initialLabels: []string{},
expectedLabels: []string{"Files"},
},
{
event: "pull_request",
payloads: []string{"diff_pr"},
name: "Test file condition corner case #1 (issue #33)",
config: LabelerConfigV1{
Version: 1,
Labels: []LabelMatcher{
{
Label: "Book",
Files: []string{
// matches root/sub/test.md only
"root\\/.+\\/.+.md",
},
},
},
},
initialLabels: []string{},
expectedLabels: []string{"Book"},
},
{
event: "pull_request",
payloads: []string{"diff_pr"},
name: "Test file condition corner case #2 (issue #33)",
config: LabelerConfigV1{
Version: 1,
Labels: []LabelMatcher{
{
Label: "BookStyle",
Files: []string{
// matches sub/test.md only
"^sub\\/.+.md",
},
},
},
},
initialLabels: []string{},
expectedLabels: []string{"BookStyle"},
},
{
event: "pull_request",
payloads: []string{"diff_pr"},
name: "Test file condition corner case #3 (issue #33)",
config: LabelerConfigV1{
Version: 1,
Labels: []LabelMatcher{
{
Label: "BookStyle",
Files: []string{
// matches README.md, not the two above
"^.+.md",
},
},
},
},
initialLabels: []string{},
expectedLabels: []string{"BookStyle"},
},
{
event: "pull_request",
payloads: []string{"small_pr"},
Expand Down
7 changes: 7 additions & 0 deletions test_data/diff_response
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ index 6c61a60..85aa975 100644
@@ -1 +1 @@
-# Test File
+# Test File !
diff --git a/sub/test.md b/sub/test.md
index 6c61a60..85aa975 100644
--- a/sub/test.md
+++ b/sub/test.md
@@ -1 +1 @@
-# Test File
+# Test File !
Loading