From e8700ffaad72c78db27200004334f861c9f15d68 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 6 Nov 2023 20:57:42 +0100 Subject: [PATCH] refactor: filter: deduplicate filter asserts --- internal/filter/allDayEvents_test.go | 6 +----- internal/filter/declinedEvents_test.go | 5 +---- internal/filter/regexTitle_test.go | 11 ++--------- internal/filter/util_test.go | 6 ++++++ 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/internal/filter/allDayEvents_test.go b/internal/filter/allDayEvents_test.go index d7554b4..341959c 100644 --- a/internal/filter/allDayEvents_test.go +++ b/internal/filter/allDayEvents_test.go @@ -5,7 +5,6 @@ import ( "github.com/inovex/CalendarSync/internal/filter" "github.com/inovex/CalendarSync/internal/models" - "github.com/stretchr/testify/assert" ) // All Day Events should be filtered @@ -36,8 +35,5 @@ func TestAllDayEventsFilter(t *testing.T) { expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]} eventFilter := filter.AllDayEvents{} - - filteredEvents := FilterEvents(sourceEvents, eventFilter) - - assert.Equal(t, expectedSinkEvents, filteredEvents) + checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents) } diff --git a/internal/filter/declinedEvents_test.go b/internal/filter/declinedEvents_test.go index 23c6125..54c81fe 100644 --- a/internal/filter/declinedEvents_test.go +++ b/internal/filter/declinedEvents_test.go @@ -5,7 +5,6 @@ import ( "github.com/inovex/CalendarSync/internal/filter" "github.com/inovex/CalendarSync/internal/models" - "github.com/stretchr/testify/assert" ) // Declined Events should be filtered @@ -37,7 +36,5 @@ func TestDeclinedEventsFilter(t *testing.T) { expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]} eventFilter := filter.DeclinedEvents{} - filteredEvents := FilterEvents(sourceEvents, eventFilter) - - assert.Equal(t, expectedSinkEvents, filteredEvents) + checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents) } diff --git a/internal/filter/regexTitle_test.go b/internal/filter/regexTitle_test.go index 1504135..de7a6ca 100644 --- a/internal/filter/regexTitle_test.go +++ b/internal/filter/regexTitle_test.go @@ -5,7 +5,6 @@ import ( "github.com/inovex/CalendarSync/internal/filter" "github.com/inovex/CalendarSync/internal/models" - "github.com/stretchr/testify/assert" ) var sourceEvents = []models.Event{ @@ -37,10 +36,7 @@ func TestRegexTitleFilter(t *testing.T) { eventFilter := filter.RegexTitle{ ExludeRegexp: ".*test", } - - filteredEvents := FilterEvents(sourceEvents, eventFilter) - - assert.Equal(t, expectedSinkEvents, filteredEvents) + checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents) } // All Events should be there @@ -50,8 +46,5 @@ func TestRegexTitleFilterEmptyRegex(t *testing.T) { eventFilter := filter.RegexTitle{ ExludeRegexp: "", } - - filteredEvents := FilterEvents(sourceEvents, eventFilter) - - assert.Equal(t, expectedSinkEvents, filteredEvents) + checkEventFilter(t, eventFilter, sourceEvents, expectedSinkEvents) } diff --git a/internal/filter/util_test.go b/internal/filter/util_test.go index 59a5be1..2c452ab 100644 --- a/internal/filter/util_test.go +++ b/internal/filter/util_test.go @@ -3,6 +3,7 @@ package filter_test import ( "github.com/inovex/CalendarSync/internal/models" "github.com/inovex/CalendarSync/internal/sync" + "github.com/stretchr/testify/assert" ) // FilterEvents takes an array of events and a filter and executes the .Filter Method on each of the sourceEvents @@ -15,3 +16,8 @@ func FilterEvents(sourceEvents []models.Event, filter sync.Filter) (filteredEven } return filteredEvents } + +func checkEventFilter(t assert.TestingT, filter sync.Filter, sourceEvents []models.Event, expectedEvents []models.Event) { + filteredEvents := FilterEvents(sourceEvents, filter) + assert.Equal(t, expectedEvents, filteredEvents) +}