subscription_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package validator // import "miniflux.app/v2/internal/validator"
  4. import (
  5. "testing"
  6. "miniflux.app/v2/internal/model"
  7. )
  8. func TestValidateSubscriptionDiscovery(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. req *model.SubscriptionDiscoveryRequest
  12. wantErr bool
  13. }{
  14. {
  15. name: "valid site url",
  16. req: &model.SubscriptionDiscoveryRequest{URL: "https://example.org"},
  17. wantErr: false,
  18. },
  19. {
  20. name: "invalid site url",
  21. req: &model.SubscriptionDiscoveryRequest{URL: "example.org"},
  22. wantErr: true,
  23. },
  24. {
  25. name: "invalid proxy url",
  26. req: &model.SubscriptionDiscoveryRequest{URL: "https://example.org", ProxyURL: "example.org"},
  27. wantErr: true,
  28. },
  29. }
  30. for _, tc := range tests {
  31. tc := tc
  32. t.Run(tc.name, func(t *testing.T) {
  33. if err := ValidateSubscriptionDiscovery(tc.req); (err != nil) != tc.wantErr {
  34. t.Fatalf("expected error %v, got %v", tc.wantErr, err)
  35. }
  36. })
  37. }
  38. }