processor_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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/config"
  8. "miniflux.app/v2/internal/model"
  9. )
  10. func TestIsRecentEntry(t *testing.T) {
  11. parser := config.NewParser()
  12. var err error
  13. config.Opts, err = parser.ParseEnvironmentVariables()
  14. if err != nil {
  15. t.Fatalf(`Parsing failure: %v`, err)
  16. }
  17. var scenarios = []struct {
  18. entry *model.Entry
  19. expected bool
  20. }{
  21. {&model.Entry{Title: "Example1", Date: time.Date(2005, 5, 1, 05, 05, 05, 05, time.UTC)}, true},
  22. {&model.Entry{Title: "Example2", Date: time.Date(2010, 5, 1, 05, 05, 05, 05, time.UTC)}, true},
  23. {&model.Entry{Title: "Example3", Date: time.Date(2020, 5, 1, 05, 05, 05, 05, time.UTC)}, true},
  24. {&model.Entry{Title: "Example4", Date: time.Date(2024, 3, 15, 05, 05, 05, 05, time.UTC)}, true},
  25. }
  26. for _, tc := range scenarios {
  27. result := isRecentEntry(tc.entry)
  28. if tc.expected != result {
  29. t.Errorf(`Unexpected result, got %v for entry %q`, result, tc.entry.Title)
  30. }
  31. }
  32. }
  33. func TestMinifyEntryContent(t *testing.T) {
  34. input := `<p> Some text with a <a href="http://example.org/"> link </a> </p>`
  35. expected := `<p>Some text with a <a href="http://example.org/">link</a></p>`
  36. result := minifyContent(input)
  37. if expected != result {
  38. t.Errorf(`Unexpected result, got %q`, result)
  39. }
  40. }