processor_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package processor // import "miniflux.app/v2/internal/reader/processor"
  4. import (
  5. "testing"
  6. "time"
  7. "miniflux.app/v2/internal/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. }
  43. func TestParseISO8601(t *testing.T) {
  44. var scenarios = []struct {
  45. duration string
  46. expected time.Duration
  47. }{
  48. // Live streams and radio.
  49. {"PT0M0S", 0},
  50. // https://www.youtube.com/watch?v=HLrqNhgdiC0
  51. {"PT6M20S", (6 * time.Minute) + (20 * time.Second)},
  52. // https://www.youtube.com/watch?v=LZa5KKfqHtA
  53. {"PT5M41S", (5 * time.Minute) + (41 * time.Second)},
  54. // https://www.youtube.com/watch?v=yIxEEgEuhT4
  55. {"PT51M52S", (51 * time.Minute) + (52 * time.Second)},
  56. // https://www.youtube.com/watch?v=bpHf1XcoiFs
  57. {"PT80M42S", (1 * time.Hour) + (20 * time.Minute) + (42 * time.Second)},
  58. }
  59. for _, tc := range scenarios {
  60. result, err := parseISO8601(tc.duration)
  61. if err != nil {
  62. t.Errorf("Got an error when parsing %q: %v", tc.duration, err)
  63. }
  64. if tc.expected != result {
  65. t.Errorf(`Unexpected result, got %v for duration %q`, result, tc.duration)
  66. }
  67. }
  68. }