-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflexmy_test.go
More file actions
82 lines (69 loc) · 1.89 KB
/
flexmy_test.go
File metadata and controls
82 lines (69 loc) · 1.89 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
package flexpg_test
import (
"errors"
"testing"
"time"
"git.eaciitapp.com/sebar/dbflex"
"github.com/eaciit/toolkit"
cv "github.com/smartystreets/goconvey/convey"
)
var (
connString = "postgres://localhost/ariefdarmawan?sslmode=disable&binary_parameters=yes"
tableName = "testmodel"
)
func connect() (dbflex.IConnection, error) {
dbflex.Logger().SetLevelStdOut(toolkit.ErrorLevel, true)
dbflex.Logger().SetLevelStdOut(toolkit.InfoLevel, true)
dbflex.Logger().SetLevelStdOut(toolkit.WarningLevel, true)
dbflex.Logger().SetLevelStdOut(toolkit.DebugLevel, true)
conn, err := dbflex.NewConnectionFromURI(connString, nil)
if err != nil {
return nil, errors.New("unable to connect. " + err.Error())
}
err = conn.Connect()
if err != nil {
return nil, errors.New("unable to connect. " + err.Error())
}
return conn, nil
}
func TestQueryM(t *testing.T) {
cv.Convey("connecting", t, func() {
conn, err := connect()
cv.So(err, cv.ShouldBeNil)
defer conn.Close()
cv.Convey("querying", func() {
cmd := dbflex.From(tableName).Select()
cur := conn.Cursor(cmd, nil)
cv.So(cur.Error(), cv.ShouldBeNil)
cv.Convey("get results", func() {
ms := []toolkit.M{}
err := cur.Fetchs(&ms, 0)
cv.So(err, cv.ShouldBeNil)
toolkit.Logger().Infof("\nResults:\n%s\n", toolkit.JsonString(ms))
})
})
})
}
func TestQueryObj(t *testing.T) {
cv.Convey("connecting", t, func() {
conn, err := connect()
cv.So(err, cv.ShouldBeNil)
defer conn.Close()
cv.Convey("querying", func() {
cmd := dbflex.From(tableName).Select()
cur := conn.Cursor(cmd, nil)
cv.So(cur.Error(), cv.ShouldBeNil)
cv.Convey("get results", func() {
ms := []struct {
ID string
Title string
DataDec float64
Created time.Time
}{}
err := cur.Fetchs(&ms, 0)
cv.So(err, cv.ShouldBeNil)
toolkit.Logger().Infof("\nResults:\n%s\n", toolkit.JsonString(ms))
})
})
})
}