-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeeder_test.go
90 lines (81 loc) · 1.76 KB
/
feeder_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
87
88
89
90
package feeder_test
import (
"reflect"
"strconv"
"testing"
"time"
"github.com/kr/pretty"
"github.com/p1ass/feeder"
)
type mockFetcher struct {
Id string
}
func (f *mockFetcher) Crawl() ([]*feeder.Item, error) {
sleepTime, _ := strconv.Atoi(f.Id)
time.Sleep(time.Second * time.Duration(sleepTime))
publishedString := "2019-01-01T00:00:00+09:00"
published, _ := time.Parse(time.RFC3339, publishedString)
return []*feeder.Item{{
Title: "title",
Link: &feeder.Link{
Href: "http://ogp.me",
Rel: "",
},
Source: nil,
Author: &feeder.Author{
Name: "name",
},
Description: "summary_content",
ID: f.Id,
Updated: nil,
Created: &published,
Content: "",
}}, nil
}
func TestCrawl(t *testing.T) {
publishedString := "2019-01-01T00:00:00+09:00"
published, _ := time.Parse(time.RFC3339, publishedString)
expected := []*feeder.Item{{
Title: "title",
Link: &feeder.Link{
Href: "http://ogp.me",
Rel: "",
},
Source: nil,
Author: &feeder.Author{
Name: "name",
},
Description: "summary_content",
ID: "1",
Updated: nil,
Created: &published,
Content: "",
}, {
Title: "title",
Link: &feeder.Link{
Href: "http://ogp.me",
Rel: "",
},
Source: nil,
Author: &feeder.Author{
Name: "name",
},
Description: "summary_content",
ID: "2",
Updated: nil,
Created: &published,
Content: "",
}}
crawler1 := &mockFetcher{Id: "1"}
crawler2 := &mockFetcher{Id: "2"}
items, err := feeder.Crawl(crawler1, crawler2)
if err != nil {
t.Errorf("Crawl() shoud return nil error error = %v", err)
return
}
if !reflect.DeepEqual(&expected, &items) {
diffs := pretty.Diff(expected, items)
t.Log(pretty.Println(diffs))
t.Error("Crawl does not match.")
}
}