-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrss_crawler_test.go
86 lines (79 loc) · 1.71 KB
/
rss_crawler_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package feeder_test
import (
"io/ioutil"
"os"
"reflect"
"testing"
"time"
"github.com/kr/pretty"
"github.com/p1ass/feeder"
)
func TestRSSFetch(t *testing.T) {
// Set up mock server
xmlFile, err := os.Open("rss_test.xml")
if err != nil {
t.Fatal("Failed to open test rss feed file.")
}
bytes, _ := ioutil.ReadAll(xmlFile)
response := &feeder.Response{
Path: "/rss",
ContentType: "application/xml",
Body: string(bytes),
}
server := feeder.NewMockServer(response)
defer server.Close()
publishedString := "2019-01-01T00:00:00+09:00"
published, _ := time.Parse(time.RFC3339, publishedString)
expected := []*feeder.Item{{
Title: "title RFC1123Z",
Link: &feeder.Link{
Href: "http://example.com",
Rel: "",
},
Source: nil,
Author: &feeder.Author{
Name: "name",
},
Description: "summary_content",
ID: "id",
Updated: nil,
Created: &published,
Enclosure: &feeder.Enclosure{
URL: "http://example.com/image.png",
Type: "image/png",
Length: "0",
},
Content: "",
},
{
Title: "title RFC1123",
Link: &feeder.Link{
Href: "http://example.com",
Rel: "",
},
Source: nil,
Author: &feeder.Author{
Name: "name",
},
Description: "summary_content",
ID: "id",
Updated: nil,
Created: &published,
Enclosure: &feeder.Enclosure{
URL: "http://example.com/image.png",
Type: "image/png",
Length: "0",
},
Content: "",
}}
crawler := feeder.NewRSSCrawler(server.URL + "/rss")
got, err := crawler.Crawl()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(expected, got) {
diffs := pretty.Diff(expected, got)
t.Log(pretty.Println(diffs))
t.Error("Failed to convert AtomEntry to Item.")
}
}