feed_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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")
  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. }
  49. func TestFeedErrorCounter(t *testing.T) {
  50. feed := &Feed{}
  51. feed.WithError("Some Error")
  52. if feed.ParsingErrorMsg != "Some Error" {
  53. t.Error(`The error message must be set`)
  54. }
  55. if feed.ParsingErrorCount != 1 {
  56. t.Error(`The error counter must be set to 1`)
  57. }
  58. feed.ResetErrorCounter()
  59. if feed.ParsingErrorMsg != "" {
  60. t.Error(`The error message must be removed`)
  61. }
  62. if feed.ParsingErrorCount != 0 {
  63. t.Error(`The error counter must be set to 0`)
  64. }
  65. }
  66. func TestFeedCheckedNow(t *testing.T) {
  67. feed := &Feed{}
  68. feed.FeedURL = "https://example.org/feed"
  69. feed.CheckedNow()
  70. if feed.SiteURL != feed.FeedURL {
  71. t.Error(`The site URL must not be empty`)
  72. }
  73. if feed.CheckedAt.IsZero() {
  74. t.Error(`The checked date must be set`)
  75. }
  76. }