handler_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package opml // import "miniflux.app/v2/internal/reader/opml"
  4. import "testing"
  5. func TestValidateSubscription(t *testing.T) {
  6. tests := []struct {
  7. name string
  8. subscription subcription
  9. wantErr bool
  10. }{
  11. {
  12. name: "valid feed",
  13. subscription: subcription{FeedURL: "https://example.org/feed.xml", KeeplistRules: "(?i)golang"},
  14. wantErr: false,
  15. },
  16. {
  17. name: "unsupported URL scheme",
  18. subscription: subcription{FeedURL: "feed://example.org/feed.xml"},
  19. wantErr: true,
  20. },
  21. {
  22. name: "relative URL",
  23. subscription: subcription{FeedURL: "/feed.xml"},
  24. wantErr: true,
  25. },
  26. {
  27. name: "invalid keeplist rule",
  28. subscription: subcription{FeedURL: "https://example.org/feed.xml", KeeplistRules: "["},
  29. wantErr: true,
  30. },
  31. {
  32. name: "invalid filter rule",
  33. subscription: subcription{FeedURL: "https://example.org/feed.xml", BlockFilterEntryRules: "Title=foo"},
  34. wantErr: true,
  35. },
  36. }
  37. for _, tc := range tests {
  38. t.Run(tc.name, func(t *testing.T) {
  39. if err := validateSubscription(tc.subscription); (err != nil) != tc.wantErr {
  40. t.Fatalf("expected error %v, got %v", tc.wantErr, err)
  41. }
  42. })
  43. }
  44. }