youtube_test.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
  2. // SPDX-License-Identifier: Apache-2.0
  3. package processor // import "miniflux.app/v2/internal/reader/processor"
  4. import (
  5. "testing"
  6. )
  7. func TestGetYouTubeVideoIDFromURL(t *testing.T) {
  8. scenarios := []struct {
  9. url string
  10. expected string
  11. }{
  12. {"https://www.youtube.com/watch?v=HLrqNhgdiC0", "HLrqNhgdiC0"},
  13. {"https://www.youtube.com/watch?v=HLrqNhgdiC0&feature=youtu.be", "HLrqNhgdiC0"},
  14. {"https://example.org/test", ""},
  15. }
  16. for _, tc := range scenarios {
  17. result := getVideoIDFromYouTubeURL(tc.url)
  18. if tc.expected != result {
  19. t.Errorf(`Unexpected result, got %q for url %q`, result, tc.url)
  20. }
  21. }
  22. }
  23. func TestIsYouTubeVideoURL(t *testing.T) {
  24. scenarios := []struct {
  25. url string
  26. expected bool
  27. }{
  28. {"https://www.youtube.com/watch?v=HLrqNhgdiC0", true},
  29. {"https://www.youtube.com/watch?v=HLrqNhgdiC0&feature=youtu.be", true},
  30. {"https://example.org/test", false},
  31. }
  32. for _, tc := range scenarios {
  33. result := isYouTubeVideoURL(tc.url)
  34. if tc.expected != result {
  35. t.Errorf(`Unexpected result, got %v for url %q`, result, tc.url)
  36. }
  37. }
  38. }