entry_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2017 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 "testing"
  6. func TestValidateEntryStatus(t *testing.T) {
  7. for _, status := range []string{EntryStatusRead, EntryStatusUnread, EntryStatusRemoved} {
  8. if err := ValidateEntryStatus(status); err != nil {
  9. t.Error(`A valid status should not generate any error`)
  10. }
  11. }
  12. if err := ValidateEntryStatus("invalid"); err == nil {
  13. t.Error(`An invalid status should generate a error`)
  14. }
  15. }
  16. func TestValidateEntryOrder(t *testing.T) {
  17. for _, status := range []string{"id", "status", "changed_at", "published_at", "created_at", "category_title", "category_id"} {
  18. if err := ValidateEntryOrder(status); err != nil {
  19. t.Error(`A valid order should not generate any error`)
  20. }
  21. }
  22. if err := ValidateEntryOrder("invalid"); err == nil {
  23. t.Error(`An invalid order should generate a error`)
  24. }
  25. }
  26. func TestValidateEntryDirection(t *testing.T) {
  27. for _, status := range []string{"asc", "desc"} {
  28. if err := ValidateDirection(status); err != nil {
  29. t.Error(`A valid direction should not generate any error`)
  30. }
  31. }
  32. if err := ValidateDirection("invalid"); err == nil {
  33. t.Error(`An invalid direction should generate a error`)
  34. }
  35. }
  36. func TestValidateRange(t *testing.T) {
  37. if err := ValidateRange(-1, 0); err == nil {
  38. t.Error(`An invalid offset should generate a error`)
  39. }
  40. if err := ValidateRange(0, -1); err == nil {
  41. t.Error(`An invalid limit should generate a error`)
  42. }
  43. if err := ValidateRange(42, 42); err != nil {
  44. t.Error(`A valid offset and limit should not generate any error`)
  45. }
  46. }