-
Notifications
You must be signed in to change notification settings - Fork 0
/
skimmer_test.go
138 lines (131 loc) · 2.79 KB
/
skimmer_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package skimmer
import (
"os"
"strings"
"testing"
"database/sql"
)
func TestParseURLList(t *testing.T) {
src := []byte(`
# This is an example url list.
https://transitinglosangeles.com/feed/ "~Transiting Los Angeles"
https://laist.com/index.atom "~The LAist"
#https://feeds.mcclatchy.com/sacbee/stories "~Sacramento Bee Stories"
https://apnews.com/world-news.rss "~Associated Press, World News"
https://apnews.com/us-news.rss "~Associated Press, US News"
https://www.theguardian.com/us/rss "~The Guardian US Edition"
`)
m, err := ParseURLList("test_sample.txt", src)
if err != nil {
t.Error(err)
t.FailNow()
}
expectedKey := "https://laist.com/index.atom"
expectedVal := `The LAist`
if val, ok := m[expectedKey]; !ok {
t.Errorf("expected value for %q, key not found in map", expectedKey)
t.FailNow()
} else if strings.Compare(val.Label, expectedVal) != 0 {
t.Errorf("expected %q, got %q", expectedVal, val.Label)
}
}
func TestSetup(t *testing.T) {
app, err := NewSkimmer("test_skimmer")
app.out = os.Stdout
app.eout = os.Stderr
if err != nil {
t.Error(err)
t.FailNow()
}
appDir := "./test_output"
if _, err := os.Stat(appDir); err == nil {
os.RemoveAll(appDir)
}
if err := app.Setup(appDir); err != nil {
t.Error(err)
t.FailNow()
}
}
func TestReadUrls(t *testing.T) {
app, err := NewSkimmer("test_skimmer")
if err != nil {
t.Error(err)
t.FailNow()
}
app.out = os.Stdout
app.eout = os.Stderr
appDir := "./test_output"
fName := "test.urls"
if err := app.Setup(appDir); err != nil {
t.Error(err)
t.FailNow()
}
if err := app.ReadUrls(fName); err != nil {
t.Error(err)
t.FailNow()
}
}
func TestDownload(t *testing.T) {
app, err := NewSkimmer("test_skimmer")
if err != nil {
t.Error(err)
t.FailNow()
}
app.out = os.Stdout
app.eout = os.Stderr
appDir := "./test_output"
fName := "test.urls"
dsn := app.DBName
db, err := sql.Open("sqlite", dsn)
if err != nil {
t.Error(err)
t.FailNow()
}
defer db.Close()
if err := app.Setup(appDir); err != nil {
t.Error(err)
t.FailNow()
}
if err := app.ReadUrls(fName); err != nil {
t.Error(err)
t.FailNow()
}
if err := app.Download(db); err != nil {
t.Error(err)
t.FailNow()
}
}
func TestDisplay(t *testing.T) {
app, err := NewSkimmer("test_skimmer")
if err != nil {
t.Error(err)
t.FailNow()
}
app.out = os.Stdout
app.eout = os.Stderr
appDir := "./test_output"
fName := "test.urls"
if err := app.Setup(appDir); err != nil {
t.Error(err)
t.FailNow()
}
if err := app.ReadUrls(fName); err != nil {
t.Error(err)
t.FailNow()
}
dsn := app.DBName
db, err := sql.Open("sqlite",dsn)
if err != nil {
t.Error(err)
t.FailNow()
}
defer db.Close()
if err := app.Download(db); err != nil {
t.Error(err)
t.FailNow()
}
if err := app.Write(db); err != nil {
t.Error(err)
t.FailNow()
}
}