Skip to content

Commit

Permalink
refactor: Move filter tests into filter_test packages
Browse files Browse the repository at this point in the history
This allows removing MockFilter interface without causing an import
loop.
  • Loading branch information
MichaelEischer committed Nov 6, 2023
1 parent 3c6c62e commit 5bac9e0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
7 changes: 4 additions & 3 deletions internal/filter/allDayEvents_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package filter
package filter_test

import (
"testing"

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -34,9 +35,9 @@ func TestAllDayEventsFilter(t *testing.T) {

expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]}

filter := AllDayEvents{}
eventFilter := filter.AllDayEvents{}

filteredEvents := FilterEvents(sourceEvents, filter)
filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
}
7 changes: 4 additions & 3 deletions internal/filter/declinedEvents_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package filter
package filter_test

import (
"testing"

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -35,8 +36,8 @@ func TestDeclinedEventsFilter(t *testing.T) {

expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]}

filter := DeclinedEvents{}
filteredEvents := FilterEvents(sourceEvents, filter)
eventFilter := filter.DeclinedEvents{}
filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
}
11 changes: 6 additions & 5 deletions internal/filter/regexTitle_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package filter
package filter_test

import (
"testing"

"github.com/inovex/CalendarSync/internal/filter"
"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -33,11 +34,11 @@ func TestRegexTitleFilter(t *testing.T) {

expectedSinkEvents := []models.Event{sourceEvents[1], sourceEvents[2]}

filter := RegexTitle{
eventFilter := filter.RegexTitle{
ExludeRegexp: ".*test",
}

filteredEvents := FilterEvents(sourceEvents, filter)
filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
}
Expand All @@ -46,11 +47,11 @@ func TestRegexTitleFilter(t *testing.T) {
func TestRegexTitleFilterEmptyRegex(t *testing.T) {
expectedSinkEvents := sourceEvents

filter := RegexTitle{
eventFilter := filter.RegexTitle{
ExludeRegexp: "",
}

filteredEvents := FilterEvents(sourceEvents, filter)
filteredEvents := FilterEvents(sourceEvents, eventFilter)

assert.Equal(t, expectedSinkEvents, filteredEvents)
}
10 changes: 3 additions & 7 deletions internal/filter/util.go → internal/filter/util_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package filter
package filter_test

import (
"github.com/inovex/CalendarSync/internal/models"
"github.com/inovex/CalendarSync/internal/sync"
)

// Need to declare another interface similar to the sync.Filter interface here, otherwise we would land in an import loop
type MockFilter interface {
Filter(models.Event) bool
}

// FilterEvents takes an array of events and a filter and executes the .Filter Method on each of the sourceEvents
// Not exluded events get returned in the filteredEvents
func FilterEvents(sourceEvents []models.Event, filter MockFilter) (filteredEvents []models.Event) {
func FilterEvents(sourceEvents []models.Event, filter sync.Filter) (filteredEvents []models.Event) {
for _, event := range sourceEvents {
if filter.Filter(event) {
filteredEvents = append(filteredEvents, event)
Expand Down

0 comments on commit 5bac9e0

Please sign in to comment.