feed_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2018 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 model // import "miniflux.app/model"
  5. import (
  6. "testing"
  7. "miniflux.app/http/client"
  8. )
  9. func TestFeedWithResponse(t *testing.T) {
  10. response := &client.Response{ETag: "Some etag", LastModified: "Some date", EffectiveURL: "Some URL"}
  11. feed := &Feed{}
  12. feed.WithClientResponse(response)
  13. if feed.EtagHeader != "Some etag" {
  14. t.Fatal(`The ETag header should be set`)
  15. }
  16. if feed.LastModifiedHeader != "Some date" {
  17. t.Fatal(`The LastModified header should be set`)
  18. }
  19. if feed.FeedURL != "Some URL" {
  20. t.Fatal(`The Feed URL should be set`)
  21. }
  22. }
  23. func TestFeedCategorySetter(t *testing.T) {
  24. feed := &Feed{}
  25. feed.WithCategoryID(int64(123))
  26. if feed.Category == nil {
  27. t.Fatal(`The category field should not be null`)
  28. }
  29. if feed.Category.ID != int64(123) {
  30. t.Error(`The category ID must be set`)
  31. }
  32. }
  33. func TestFeedBrowsingParams(t *testing.T) {
  34. feed := &Feed{}
  35. feed.WithBrowsingParameters(true, "Custom User Agent", "Username", "Secret", "Some Rule", "Another Rule")
  36. if !feed.Crawler {
  37. t.Error(`The crawler must be activated`)
  38. }
  39. if feed.UserAgent != "Custom User Agent" {
  40. t.Error(`The user agent must be set`)
  41. }
  42. if feed.Username != "Username" {
  43. t.Error(`The username must be set`)
  44. }
  45. if feed.Password != "Secret" {
  46. t.Error(`The password must be set`)
  47. }
  48. if feed.ScraperRules != "Some Rule" {
  49. t.Errorf(`The scraper rules must be set`)
  50. }
  51. if feed.RewriteRules != "Another Rule" {
  52. t.Errorf(`The rewrite rules must be set`)
  53. }
  54. }
  55. func TestFeedErrorCounter(t *testing.T) {
  56. feed := &Feed{}
  57. feed.WithError("Some Error")
  58. if feed.ParsingErrorMsg != "Some Error" {
  59. t.Error(`The error message must be set`)
  60. }
  61. if feed.ParsingErrorCount != 1 {
  62. t.Error(`The error counter must be set to 1`)
  63. }
  64. feed.ResetErrorCounter()
  65. if feed.ParsingErrorMsg != "" {
  66. t.Error(`The error message must be removed`)
  67. }
  68. if feed.ParsingErrorCount != 0 {
  69. t.Error(`The error counter must be set to 0`)
  70. }
  71. }
  72. func TestFeedCheckedNow(t *testing.T) {
  73. feed := &Feed{}
  74. feed.FeedURL = "https://example.org/feed"
  75. feed.CheckedNow()
  76. if feed.SiteURL != feed.FeedURL {
  77. t.Error(`The site URL must not be empty`)
  78. }
  79. if feed.CheckedAt.IsZero() {
  80. t.Error(`The checked date must be set`)
  81. }
  82. }