-
Notifications
You must be signed in to change notification settings - Fork 2
/
atom_crawler_test.go
68 lines (61 loc) · 1.46 KB
/
atom_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
package feeder_test
import (
"io/ioutil"
"os"
"reflect"
"testing"
"time"
"github.com/kr/pretty"
"github.com/p1ass/feeder"
)
func TestAtomFetch(t *testing.T) {
// Set up mock server
xmlFile, err := os.Open("atom_test.xml")
if err != nil {
t.Fatal("Failed to open test atom feed file.")
}
bytes, _ := ioutil.ReadAll(xmlFile)
response := &feeder.Response{
Path: "/feed",
ContentType: "application/xml",
Body: string(bytes),
}
server := feeder.NewMockServer(response)
defer server.Close()
updatedString := "2019-01-02T00:00:00+09:00"
updated, _ := time.Parse(time.RFC3339, updatedString)
publishedString := "2019-01-01T00:00:00+09:00"
published, _ := time.Parse(time.RFC3339, publishedString)
expected := []*feeder.Item{{
Title: "title",
Link: &feeder.Link{
Href: "http://example.com",
Rel: "alternate",
},
Source: nil,
Author: &feeder.Author{
Name: "name",
Email: "[email protected]",
},
Description: "summary_content",
ID: "id",
Updated: &updated,
Created: &published,
Enclosure: &feeder.Enclosure{
URL: "http://example.com/image.png",
Type: "image/png",
Length: "0",
},
Content: "content",
}}
crawler := feeder.NewAtomCrawler(server.URL + "/feed")
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.")
}
}