-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_test.go
110 lines (94 loc) · 2.16 KB
/
store_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package dominocount_test
import (
"dominocount"
"testing"
)
func TestSQLiteStore_MatchRoundtripCreateUpdateGet(t *testing.T) {
t.Parallel()
tempDB := t.TempDir() + "matchRoundtrip.store"
sqLiteStore, err := dominocount.OpenSQLiteStore(tempDB)
if err != nil {
t.Fatal(err)
}
m := dominocount.NewMatch()
err = sqLiteStore.CreateMatch(&m)
if err != nil {
t.Fatal(err)
}
want := "test"
m.Team1 = want
//m.Id = m.Id
err = sqLiteStore.UpdateMatch(&m)
if err != nil {
t.Fatal(err)
}
got, err := sqLiteStore.GetMatchByID(m.Id)
if err != nil {
t.Fatal(err)
}
if want != got.Team1 {
t.Errorf("want rountrip(create,update,get) test to return %s, got %s", want, got.Team1)
}
}
func TestSQLiteStore_MatchAddPoints(t *testing.T) {
t.Parallel()
tempDB := t.TempDir() + t.Name()
store, err := dominocount.OpenSQLiteStore(tempDB)
if err != nil {
t.Fatal(err)
}
m := dominocount.NewMatch()
err = store.CreateMatch(&m)
if err != nil {
t.Fatal(err)
}
want := 20
_, err = store.AddPointsByID(m.Id, 20, 0)
if err != nil {
t.Fatal(err)
}
got, err := store.GetMatchByID(m.Id)
if err != nil {
t.Fatal(err)
}
if want != got.Score1 {
t.Errorf("want match add %d points test to return %d, got %d", want, want, got.Score1)
}
}
func TestSQLiteStore_MatchAddPointsErrorsAfter200(t *testing.T) {
t.Parallel()
tempDB := t.TempDir() + t.Name()
store, err := dominocount.OpenSQLiteStore(tempDB)
if err != nil {
t.Fatal(err)
}
m := dominocount.NewMatch()
err = store.CreateMatch(&m)
if err != nil {
t.Fatal(err)
}
_, err = store.AddPointsByID(m.Id, 199, 0)
if err != nil {
t.Error("expect no error adding 199")
}
_, err = store.AddPointsByID(m.Id, 10, 0)
if err != nil {
t.Error("expect no error adding 10")
}
_, err = store.AddPointsByID(m.Id, 10, 0)
if err == nil {
t.Error("want error adding once the max score has been reached")
}
_, ok := err.(*dominocount.GameOverError)
if !ok {
t.Errorf("want error to GameOverError got %s", err.Error())
}
want := 209
got, err := store.GetMatchByID(m.Id)
if err != nil {
t.Fatal(err)
}
if want != got.Score1 {
t.Errorf("want match to be game over and %d, got %d", want, got.Score1)
}
}