scraper_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 scraper // import "miniflux.app/reader/scraper"
  5. import "testing"
  6. func TestGetPredefinedRules(t *testing.T) {
  7. if getPredefinedScraperRules("http://www.phoronix.com/") == "" {
  8. t.Error("Unable to find rule for phoronix.com")
  9. }
  10. if getPredefinedScraperRules("https://www.linux.com/") == "" {
  11. t.Error("Unable to find rule for linux.com")
  12. }
  13. if getPredefinedScraperRules("https://example.org/") != "" {
  14. t.Error("A rule not defined should not return anything")
  15. }
  16. }
  17. func TestWhitelistedContentTypes(t *testing.T) {
  18. scenarios := map[string]bool{
  19. "text/html": true,
  20. "TeXt/hTmL": true,
  21. "application/xhtml+xml": true,
  22. "text/html; charset=utf-8": true,
  23. "application/xhtml+xml; charset=utf-8": true,
  24. "text/css": false,
  25. "application/javascript": false,
  26. "image/png": false,
  27. "application/pdf": false,
  28. }
  29. for inputValue, expectedResult := range scenarios {
  30. actualResult := isWhitelistedContentType(inputValue)
  31. if actualResult != expectedResult {
  32. t.Errorf(`Unexpected result for content type whitelist, got "%v" instead of "%v"`, actualResult, expectedResult)
  33. }
  34. }
  35. }