-
Notifications
You must be signed in to change notification settings - Fork 0
/
edb_test.go
75 lines (62 loc) · 2.1 KB
/
edb_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
package edb
import (
"github.com/eager7/edb/tables"
"github.com/shopspring/decimal"
"testing"
)
const (
dbAddr, dbUser, dbPass, dbName = "127.0.0.1:3306", "root", "plainchant", "wallet_funds_database"
)
func TestInsert(t *testing.T) {
db, err := Initialize(dbAddr, dbUser, dbPass, dbName, 1)
if err != nil {
t.Fatal(err)
}
r1 := tables.TableTestInfo{Uuid: "r1", Version: 0, Balance: decimal.New(1, 2)}
if err := Insert(db.LogMode(true), &r1, true); err != nil {
t.Fatal(err)
}
r2 := tables.TableTestInfo{Uuid: "r2", Version: 0, Balance: decimal.New(1, 3)}
if err := BatchInsert(db.LogMode(true), []DbMessage{&r1, &r2}, (&tables.TableTestInfo{}).TableName(), true); err != nil {
t.Fatal(err)
}
}
func TestUpdate(t *testing.T) {
db, err := Initialize(dbAddr, dbUser, dbPass, dbName, 1)
if err != nil {
t.Fatal(err)
}
r1 := tables.TableTestInfo{Uuid: "r1", Version: 0, Balance: decimal.New(2, 2)}
if err := Update(db.LogMode(true), &r1, "balance"); err != nil {
t.Fatal(err)
}
r2 := tables.TableTestInfo{Uuid: "r2", Version: 0, Balance: decimal.New(2, 3)}
if err := BatchUpdate(db.LogMode(true), []DbMessage{&r1, &r2}, (&tables.TableTestInfo{}).TableName(), "balance"); err != nil {
t.Fatal(err)
}
}
func TestReplace(t *testing.T) {
db, err := Initialize(dbAddr, dbUser, dbPass, dbName, 1)
if err != nil {
t.Fatal(err)
}
r1 := tables.TableTestInfo{Uuid: "r1", Version: 0, Balance: decimal.New(3, 2)}
if err := Replace(db.LogMode(true), &r1); err != nil {
t.Fatal(err)
}
r2 := tables.TableTestInfo{Uuid: "r2", Version: 0, Balance: decimal.New(3, 3)}
if err := BatchReplace(db.LogMode(true), []DbMessage{&r1, &r2}, (&tables.TableTestInfo{}).TableName()); err != nil {
t.Fatal(err)
}
}
func TestBatchInsertTable(t *testing.T) {
db, err := Initialize(dbAddr, dbUser, dbPass, dbName, 1)
if err != nil {
t.Fatal(err)
}
r1 := tables.TableTestInfo{Uuid: "r3", Version: 0, Balance: decimal.New(4, 2)}
r2 := tables.TableTestInfo{Uuid: "r4", Version: 0, Balance: decimal.New(4, 3)}
if err := BatchInsertTable(db.LogMode(true), []interface{}{&r1, &r2}, true); err != nil {
t.Fatal(err)
}
}