This repository was archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustom_crawl_test.go
84 lines (67 loc) · 1.69 KB
/
custom_crawl_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
package core
import (
"github.com/datatogether/sql_datastore"
"github.com/ipfs/go-datastore"
"testing"
)
func TestCustomCrawlStorage(t *testing.T) {
store := datastore.NewMapDatastore()
p := &CustomCrawl{Id: "eg", OriginalUrl: "http://test.com"}
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p.Jwt = "eg_jwt"
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p2 := &CustomCrawl{Id: p.Id}
if err := p2.Read(store); err != nil {
t.Error(err.Error())
return
}
if !p2.Created.Equal(p.Created) {
t.Errorf("created doesn't match: %s != %s", p2.Created.String(), p.Created.String())
}
if !p2.Updated.Equal(p.Updated) {
t.Errorf("updated doesn't match: %s != %s", p2.Updated.String(), p.Updated.String())
}
if err := p.Delete(store); err != nil {
t.Error(err.Error())
return
}
}
func TestCustomCrawlSQLStorage(t *testing.T) {
defer resetTestData(appDB, "uncrawlables")
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&CustomCrawl{}); err != nil {
t.Error(err)
return
}
p := &CustomCrawl{SqliteChecksum: "eg"}
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p.SqliteChecksum = "eg_2"
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p2 := &CustomCrawl{Id: p.Id}
if err := p2.Read(store); err != nil {
t.Error(err.Error())
return
}
if !p2.Created.Equal(p.Created) {
t.Errorf("created doesn't match: %s != %s", p2.Created.String(), p.Created.String())
}
if !p2.Updated.Equal(p.Updated) {
t.Errorf("updated doesn't match: %s != %s", p2.Updated.String(), p.Updated.String())
}
if err := p.Delete(store); err != nil {
t.Error(err.Error())
return
}
}