This repository was archived by the owner on Nov 7, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathsource_test.go
More file actions
152 lines (125 loc) · 3.18 KB
/
Copy pathsource_test.go
File metadata and controls
152 lines (125 loc) · 3.18 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package core
import (
"github.com/datatogether/sql_datastore"
"github.com/ipfs/go-datastore"
"testing"
)
func TestSourceStorage(t *testing.T) {
store := datastore.NewMapDatastore()
c := &Source{Url: "youtube.com", Primer: &Primer{Id: "5b1031f4-38a8-40b3-be91-c324bf686a87"}, Crawl: true}
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c.Crawl = false
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c2 := &Source{Id: c.Id}
if err := c2.Read(store); err != nil {
t.Error(err.Error())
return
}
if c2.Crawl != c.Crawl {
t.Errorf("crawl doesn't match: %t != %t", c2.Crawl, c.Crawl)
}
if !c2.Created.Equal(c.Created) {
t.Errorf("created doesn't match: %s != %s", c2.Created.String(), c.Created.String())
}
if !c2.Updated.Equal(c.Updated) {
t.Errorf("updated doesn't match: %s != %s", c2.Updated.String(), c.Updated.String())
}
if err := c.Delete(store); err != nil {
t.Error(err.Error())
return
}
}
func TestSourceSQLStorage(t *testing.T) {
defer resetTestData(appDB, "crawl_urls", "sources", "primers")
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&Source{}); err != nil {
t.Error(err)
return
}
c := &Source{Url: "youtube.com", Primer: &Primer{Id: "5b1031f4-38a8-40b3-be91-c324bf686a87"}, Crawl: true}
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c.Crawl = false
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c2 := &Source{Url: "youtube.com"}
if err := c2.Read(store); err != nil {
t.Error(err.Error())
return
}
if c2.Crawl != c.Crawl {
t.Errorf("crawl doesn't match: %t != %t", c2.Crawl, c.Crawl)
}
if !c2.Created.Equal(c.Created) {
t.Errorf("created doesn't match: %s != %s", c2.Created.String(), c.Created.String())
}
if !c2.Updated.Equal(c.Updated) {
t.Errorf("updated doesn't match: %s != %s", c2.Updated.String(), c.Updated.String())
}
if err := c.Delete(store); err != nil {
t.Error(err.Error())
return
}
}
func TestSourceUndescribedContent(t *testing.T) {
// TODO - some test isn't cleaning up after itself
if err := resetTestData(appDB, "sources"); err != nil {
t.Fatal(err.Error())
}
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&Source{}); err != nil {
t.Error(err)
return
}
c := &Source{Url: "www.census.gov"}
if err := c.Read(store); err != nil {
t.Error(err.Error())
return
}
urls, err := c.UndescribedContent(appDB, 100, 0)
if err != nil {
t.Error(err.Error())
return
}
if len(urls) != 1 {
t.Errorf("UnescribedContent Fail:")
for _, u := range urls {
t.Error(u)
}
}
}
func TestSourceDescribedContent(t *testing.T) {
// TODO - some test isn't cleaning up after itself
if err := resetTestData(appDB, "sources"); err != nil {
t.Fatal(err.Error())
}
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&Source{}); err != nil {
t.Error(err)
return
}
c := &Source{Url: "www.census.gov"}
if err := c.Read(store); err != nil {
t.Error(err.Error())
return
}
urls, err := c.DescribedContent(appDB, 100, 0)
if err != nil {
t.Error(err.Error())
return
}
if len(urls) != 1 {
t.Errorf("DescribedContent Fail:")
t.Error(urls)
}
}