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
Expand file tree
/
Copy pathdatarepo_test.go
More file actions
83 lines (67 loc) · 1.69 KB
/
datarepo_test.go
File metadata and controls
83 lines (67 loc) · 1.69 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
package core
import (
"github.com/datatogether/sql_datastore"
"github.com/ipfs/go-datastore"
"testing"
)
func TestDataRepoStorage(t *testing.T) {
store := datastore.NewMapDatastore()
c := &DataRepo{Title: "test dataRepo"}
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c.Description = "test description!"
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c2 := &DataRepo{Id: c.Id}
if err := c2.Read(store); err != nil {
t.Error(err.Error())
return
}
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 TestDataRepoSQLStorage(t *testing.T) {
defer resetTestData(appDB, "dataRepos")
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&DataRepo{}); err != nil {
t.Error(err.Error())
return
}
c := &DataRepo{Title: "test dataRepo"}
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c.Description = "test description!"
if err := c.Save(store); err != nil {
t.Error(err.Error())
return
}
c2 := &DataRepo{Id: c.Id}
if err := c2.Read(store); err != nil {
t.Error(err.Error())
return
}
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
}
}