-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: deduplicate filter test code and add util func
- Loading branch information
Alexander Huck
committed
Nov 7, 2023
1 parent
84d8102
commit 458eb22
Showing
4 changed files
with
52 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package filter | ||
|
||
import ( | ||
"github.com/inovex/CalendarSync/internal/models" | ||
) | ||
|
||
// 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) { | ||
for _, event := range sourceEvents { | ||
if filter.Filter(event) { | ||
filteredEvents = append(filteredEvents, event) | ||
} | ||
} | ||
return filteredEvents | ||
} |