Skip to content

Commit

Permalink
Files: tests for issue #33 (#132)
Browse files Browse the repository at this point in the history
Signed-off-by: Galo Navarro <anglorvaroa@gmail.com>
  • Loading branch information
srvaroa authored Dec 28, 2023
1 parent 9c29ad1 commit f64240a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
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 !

0 comments on commit f64240a

Please sign in to comment.