From f64240a8d525cd2651b2755497d1936365158333 Mon Sep 17 00:00:00 2001 From: Galo Navarro Date: Thu, 28 Dec 2023 21:10:17 +0100 Subject: [PATCH] Files: tests for issue #33 (#132) Signed-off-by: Galo Navarro --- pkg/labeler_test.go | 59 +++++++++++++++++++++++++++++++++++++++++ test_data/diff_response | 7 +++++ 2 files changed, 66 insertions(+) diff --git a/pkg/labeler_test.go b/pkg/labeler_test.go index a9d3b5c..402a930 100644 --- a/pkg/labeler_test.go +++ b/pkg/labeler_test.go @@ -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 @@ -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 @@ -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"}, diff --git a/test_data/diff_response b/test_data/diff_response index 4a2cdc9..d6110a7 100644 --- a/test_data/diff_response +++ b/test_data/diff_response @@ -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 !