processor_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2020 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package processor // import "miniflux.app/reader/processor"
  5. import (
  6. "testing"
  7. "miniflux.app/model"
  8. )
  9. func TestBlockingEntries(t *testing.T) {
  10. var scenarios = []struct {
  11. feed *model.Feed
  12. entry *model.Entry
  13. expected bool
  14. }{
  15. {&model.Feed{ID: 1, BlocklistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
  16. {&model.Feed{ID: 1, BlocklistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
  17. {&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, false},
  18. }
  19. for _, tc := range scenarios {
  20. result := isBlockedEntry(tc.feed, tc.entry)
  21. if tc.expected != result {
  22. t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
  23. }
  24. }
  25. }
  26. func TestAllowEntries(t *testing.T) {
  27. var scenarios = []struct {
  28. feed *model.Feed
  29. entry *model.Entry
  30. expected bool
  31. }{
  32. {&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
  33. {&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
  34. {&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, true},
  35. }
  36. for _, tc := range scenarios {
  37. result := isAllowedEntry(tc.feed, tc.entry)
  38. if tc.expected != result {
  39. t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
  40. }
  41. }
  42. }