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 pathuncrawlable_test.go
84 lines (67 loc) · 1.71 KB
/
uncrawlable_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 TestUncrawlableStorage(t *testing.T) {
store := datastore.NewMapDatastore()
p := &Uncrawlable{Url: "http://www.epa.gov"}
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p.Comments = "new comment"
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p2 := &Uncrawlable{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 TestUncrawlableSQLStorage(t *testing.T) {
defer resetTestData(appDB, "uncrawlables")
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&Uncrawlable{}); err != nil {
t.Error(err)
return
}
p := &Uncrawlable{Url: "http://www.epa.gov"}
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p.Comments = "new comment"
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p2 := &Uncrawlable{Url: "http://www.epa.gov"}
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
}
}