This repository was archived by the owner on Nov 7, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathprimer_test.go
More file actions
104 lines (85 loc) · 2.27 KB
/
Copy pathprimer_test.go
File metadata and controls
104 lines (85 loc) · 2.27 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
package core
import (
"github.com/datatogether/sql_datastore"
"github.com/ipfs/go-datastore"
"testing"
)
func TestPrimerStorage(t *testing.T) {
store := datastore.NewMapDatastore()
p := &Primer{Title: "Test Primer", Description: "test primer description!"}
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p.Description = "new description"
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p2 := &Primer{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 TestPrimerSQLStorage(t *testing.T) {
defer resetTestData(appDB, "primers", "sources")
store := sql_datastore.NewDatastore(appDB)
if err := store.Register(&Primer{}); err != nil {
t.Error(err.Error())
return
}
p := &Primer{Title: "Test Primer", Description: "test primer description!"}
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p.Description = "new description"
if err := p.Save(store); err != nil {
t.Error(err.Error())
return
}
p2 := &Primer{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 TestPrimerReadSubprimers(t *testing.T) {
p := &Primer{Id: "5b1031f4-38a8-40b3-be91-c324bf686a87"}
if err := p.ReadSubPrimers(appDB); err != nil {
t.Error(err.Error())
}
}
func TestPrimerReadSources(t *testing.T) {
p := &Primer{Id: "5b1031f4-38a8-40b3-be91-c324bf686a87"}
if err := p.ReadSources(appDB); err != nil {
t.Error(err.Error())
}
}
func TestPrimerCalcStats(t *testing.T) {
p := &Primer{Id: "5b1031f4-38a8-40b3-be91-c324bf686a87"}
if err := p.CalcStats(appDB); err != nil {
t.Error(err.Error())
}
}