comb_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // Copyright (C) 2017-2019 Marcus Rohrmoser, http://purl.mro.name/ShaarliGo
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. //
  17. package main
  18. import (
  19. "os"
  20. "time"
  21. "github.com/stretchr/testify/assert"
  22. "testing"
  23. )
  24. func TestParseCombHeiseHttp(t *testing.T) {
  25. t.SkipNow()
  26. ent, err := entryFromURL(mustParseURL("https://www.heise.de/security/meldung/Notfall-Patch-fuer-Windows-Co-Kritische-Sicherheitsluecke-im-Virenscanner-von-Microsoft-3913800.html"), 10*time.Second)
  27. assert.Nil(t, err, "ouch")
  28. assert.Equal(t, "de", ent.XmlLang, "ouch")
  29. }
  30. func TestParseCombHeise(t *testing.T) {
  31. t.Parallel()
  32. f, err := os.Open("testdata/comb-heise-3913800.html")
  33. assert.NotNil(t, f, "ouch")
  34. assert.Nil(t, err, "ouch")
  35. ent, err := entryFromReader(f, mustParseURL("https://www.heise.de/security/meldung/Notfall-Patch-fuer-Windows-Co-Kritische-Sicherheitsluecke-im-Virenscanner-von-Microsoft-3913800.html"))
  36. assert.Nil(t, err, "ouch")
  37. assert.Equal(t, Lang("de"), ent.XmlLang, "ouch")
  38. assert.Equal(t, "Notfall-Patch für Windows & Co.: Kritische Sicherheitslücke im Virenscanner von Microsoft", ent.Title.Body, "ouch")
  39. //assert.Equal(t, "", ent.Content.Body, "ouch")
  40. assert.Equal(t, 5, len(ent.Categories), "ouch")
  41. assert.Equal(t, "Malware_Protection_Engine", ent.Categories[0].Term, "ouch")
  42. assert.Equal(t, "Windows_Defender", ent.Categories[4].Term, "ouch")
  43. assert.Equal(t, "Die Malware Protection Engine von Microsoft weist eine Schwachstelle auf, über die Angreifer Schadcode auf Computer schieben könnten. Die Engine kommt unter anderem bei Windows Defender zum Einsatz.", ent.Summary.Body, "ouch")
  44. assert.Equal(t, 1, len(ent.Authors), "ouch")
  45. assert.Equal(t, "Dennis Schirrmacher", ent.Authors[0].Name, "ouch")
  46. assert.Equal(t, "2017-12-08T09:57:00+01:00", ent.Published.Format(time.RFC3339), "ouch")
  47. assert.Equal(t, Iri("https://www.heise.de/imgs/18/2/3/3/3/6/5/2/ms-27f2d5b32536ec59.png"), ent.MediaThumbnail.Url, "ouch")
  48. }
  49. func TestParseCombSpon(t *testing.T) {
  50. t.Parallel()
  51. f, err := os.Open("testdata/comb-spon-1182013.html")
  52. assert.NotNil(t, f, "ouch")
  53. assert.Nil(t, err, "ouch")
  54. ent, err := entryFromReader(f, mustParseURL("http://www.spiegel.de/netzwelt/web/bitcoin-blockchain-hashgraph-die-blase-die-bleibt-kolumne-a-1182013.html"))
  55. assert.Nil(t, err, "ouch")
  56. assert.Equal(t, Lang("de"), ent.XmlLang, "ouch")
  57. assert.Equal(t, "Bitcoin, Blockchain, Hashgraph: Die Blase, die bleibt - SPIEGEL ONLINE - Netzwelt", ent.Title.Body, "ouch")
  58. //assert.Equal(t, "", ent.Content.Body, "ouch")
  59. assert.Equal(t, 0, len(ent.Categories), "ouch")
  60. assert.Equal(t, "Bitcoin ist nur deshalb so viel wert, weil so viele Menschen daran glauben, dass Bitcoin so viel wert ist. Die Krypto-Währung ist nichts anderes als das jüngste, digitale Gesicht des Kapitalismus.", ent.Summary.Body, "ouch")
  61. assert.Equal(t, 1, len(ent.Authors), "ouch")
  62. assert.Equal(t, "SPIEGEL ONLINE, Hamburg, Germany", ent.Authors[0].Name, "ouch")
  63. assert.Equal(t, "2017-12-06T16:13:00+01:00", ent.Published.Format(time.RFC3339), "ouch")
  64. assert.Equal(t, Iri("http://cdn3.spiegel.de/images/image-1222932-galleryV9-yqyy-1222932.jpg"), ent.MediaThumbnail.Url, "ouch")
  65. }