-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdal_test.go
58 lines (53 loc) · 1.92 KB
/
dal_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
package gta
import (
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func Test_taskDALImp_GetInitialized(t *testing.T) {
convey.Convey("Test_taskDALImp_GetInitialized", t, func() {
db := testDB("Test_taskDALImp_GetInitialized")
convey.Convey("normal", func() {
tdal := taskDALImp{options: &options{db: db, table: "tasks"}}
convey.Convey("only has sensitive keys", func() {
convey.Convey("normal time", func() {
_ = tdal.Create(db, &Task{TaskKey: "t1", TaskStatus: TaskStatusInitialized, CreatedAt: time.Now(), UpdatedAt: time.Now()})
task, err := tdal.GetInitialized(db, []TaskKey{"t1"}, time.Second, nil)
convey.So(err, convey.ShouldBeNil)
convey.So(task, convey.ShouldNotBeNil)
})
convey.Convey("invalid time", func() {
_ = tdal.Create(db, &Task{TaskKey: "t1", TaskStatus: TaskStatusInitialized, CreatedAt: time.Now(), UpdatedAt: time.Now()})
task, err := tdal.GetInitialized(db, []TaskKey{"t1"}, -time.Second, nil)
convey.So(err, convey.ShouldBeNil)
convey.So(task, convey.ShouldBeNil)
})
})
})
convey.Convey("error", func() {
tdal := taskDALImp{options: &options{db: db, table: "not exist"}}
_, err := tdal.GetInitialized(db, nil, time.Second, nil)
convey.So(err, convey.ShouldNotBeNil)
})
})
}
func Test_taskDALImp_Get(t *testing.T) {
convey.Convey("Test_taskDALImp_Get", t, func() {
convey.Convey("error", func() {
db := testDB("Test_taskDALImp_Get")
tdal := taskDALImp{options: &options{db: db, table: "not exist"}}
_, err := tdal.Get(db, 1)
convey.So(err, convey.ShouldNotBeNil)
})
})
}
func Test_taskDALImp_GetForUpdate(t *testing.T) {
convey.Convey("Test_taskDALImp_GetForUpdate", t, func() {
convey.Convey("error", func() {
db := testDB("Test_taskDALImp_GetForUpdate")
tdal := taskDALImp{options: &options{db: db, table: "not exist"}}
_, err := tdal.GetForUpdate(db, 1)
convey.So(err, convey.ShouldNotBeNil)
})
})
}