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 pathlink_test.go
88 lines (71 loc) · 1.84 KB
/
link_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
package core
import (
"github.com/datatogether/sql_datastore"
"github.com/ipfs/go-datastore"
"testing"
)
func TestLinkStorage(t *testing.T) {
store := datastore.NewMapDatastore()
l := &Link{Src: &Url{Url: "http://www.epa.gov"}, Dst: &Url{Url: "http://www.epa.gov"}}
if err := l.Insert(store); err != nil {
t.Error(err.Error())
return
}
if err := l.Update(store); err != nil {
t.Error(err.Error())
return
}
l2 := &Link{
Src: &Url{Url: "http://www.epa.gov"},
Dst: &Url{Url: "http://www.epa.gov"},
}
if err := l2.Read(store); err != nil {
t.Error(err.Error())
return
}
if !l2.Created.Equal(l.Created) {
t.Errorf("created doesn't match: %s != %s", l2.Created.String(), l.Created.String())
}
if !l2.Updated.Equal(l.Updated) {
t.Errorf("updated doesn't match: %s != %s", l2.Updated.String(), l.Updated.String())
}
if err := l.Delete(store); err != nil {
t.Error(err.Error())
return
}
}
func TestLinkSQLStorage(t *testing.T) {
defer resetTestData(appDB, "links")
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&Link{}); err != nil {
t.Error(err.Error())
return
}
l := &Link{Src: &Url{Url: "http://www.epa.gov"}, Dst: &Url{Url: "http://www.epa.gov"}}
if err := l.Insert(store); err != nil {
t.Error(err.Error())
return
}
if err := l.Update(store); err != nil {
t.Error(err.Error())
return
}
l2 := &Link{
Src: &Url{Url: "http://www.epa.gov"},
Dst: &Url{Url: "http://www.epa.gov"},
}
if err := l2.Read(store); err != nil {
t.Error(err.Error())
return
}
if !l2.Created.Equal(l.Created) {
t.Errorf("created doesn't match: %s != %s", l2.Created.String(), l.Created.String())
}
if !l2.Updated.Equal(l.Updated) {
t.Errorf("updated doesn't match: %s != %s", l2.Updated.String(), l.Updated.String())
}
if err := l.Delete(store); err != nil {
t.Error(err.Error())
return
}
}