-
Notifications
You must be signed in to change notification settings - Fork 0
/
economy_test.go
74 lines (55 loc) · 1.05 KB
/
economy_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
package economy
import (
"github.com/google/uuid"
"github.com/provsalt/economy/handler"
"github.com/provsalt/economy/provider"
"os"
"testing"
)
// TestEconomy tests the economy package
func TestEconomy(t *testing.T) {
id := uuid.New()
sql, err := provider.NewSQLite("test.sqlite")
if err != nil {
panic(err)
}
e := New(sql, handler.NopEconomyHandler{})
if e == nil {
t.Error("New: Economy is nil")
}
err = e.Set(id, 1000)
if err != nil {
t.Error(err)
}
bal, err := e.Balance(id)
if err != nil {
t.Error(err)
}
if bal != 1000 {
t.Errorf("Init: Balance is not 1000, But %d", bal)
}
err = e.Increase(id, 100)
if err != nil {
t.Error(err)
}
bal, err = e.Balance(id)
if bal != 1100 {
t.Errorf("Increase: Balance is not 1100, but %d", bal)
}
err = e.Decrease(id, 200)
if err != nil {
t.Error(err)
}
bal, err = e.Balance(id)
if err != nil {
t.Error(err)
}
if bal != 900 {
t.Errorf("Decrease: Balance is not 900, but %d", bal)
}
err = e.Close()
if err != nil {
t.Error(err)
}
_ = os.Remove("test.sqlite")
}