4
0

processor_test.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. "time"
  8. "miniflux.app/model"
  9. )
  10. func TestBlockingEntries(t *testing.T) {
  11. var scenarios = []struct {
  12. feed *model.Feed
  13. entry *model.Entry
  14. expected bool
  15. }{
  16. {&model.Feed{ID: 1, BlocklistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
  17. {&model.Feed{ID: 1, BlocklistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
  18. {&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, false},
  19. }
  20. for _, tc := range scenarios {
  21. result := isBlockedEntry(tc.feed, tc.entry)
  22. if tc.expected != result {
  23. t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
  24. }
  25. }
  26. }
  27. func TestAllowEntries(t *testing.T) {
  28. var scenarios = []struct {
  29. feed *model.Feed
  30. entry *model.Entry
  31. expected bool
  32. }{
  33. {&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Some Example"}, true},
  34. {&model.Feed{ID: 1, KeeplistRules: "(?i)example"}, &model.Entry{Title: "Something different"}, false},
  35. {&model.Feed{ID: 1}, &model.Entry{Title: "No rule defined"}, true},
  36. }
  37. for _, tc := range scenarios {
  38. result := isAllowedEntry(tc.feed, tc.entry)
  39. if tc.expected != result {
  40. t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
  41. }
  42. }
  43. }
  44. func TestParseISO8601(t *testing.T) {
  45. var scenarios = []struct {
  46. duration string
  47. expected time.Duration
  48. }{
  49. // Live streams and radio.
  50. {"PT0M0S", 0},
  51. // https://www.youtube.com/watch?v=HLrqNhgdiC0
  52. {"PT6M20S", (6 * time.Minute) + (20 * time.Second)},
  53. // https://www.youtube.com/watch?v=LZa5KKfqHtA
  54. {"PT5M41S", (5 * time.Minute) + (41 * time.Second)},
  55. // https://www.youtube.com/watch?v=yIxEEgEuhT4
  56. {"PT51M52S", (51 * time.Minute) + (52 * time.Second)},
  57. // https://www.youtube.com/watch?v=bpHf1XcoiFs
  58. {"PT80M42S", (1 * time.Hour) + (20 * time.Minute) + (42 * time.Second)},
  59. }
  60. for _, tc := range scenarios {
  61. result, err := parseISO8601(tc.duration)
  62. if err != nil {
  63. t.Errorf("Got an error when parsing %q: %v", tc.duration, err)
  64. }
  65. if tc.expected != result {
  66. t.Errorf(`Unexpected result, got %v for duration %q`, result, tc.duration)
  67. }
  68. }
  69. }