-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_test.go
55 lines (45 loc) · 1.46 KB
/
update_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
package squbix
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestNewUpdateQuery(t *testing.T) {
Convey("If we dont specify table to read", t, func() {
builder := &updateQueryBuilder{}
query, err := builder.BuildQuery()
Convey("It should returns error", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "no table specified for query")
So(query, ShouldEqual, "")
})
})
Convey("If we dont specify field to select", t, func() {
query, err := NewUpdateQuery("table_a").
BuildQuery()
Convey("It should returns error", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "no field specified, add it using AddSetField method")
So(query, ShouldEqual, "")
})
})
Convey("Given field to set but no update condition", t, func() {
query, err := NewUpdateQuery("table_a").
AddSetField("field_a = 'A'").
BuildQuery()
Convey("It should returns error", func() {
So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "no update condition specified, this is DANGEROUS, add it using AddWhere method")
So(query, ShouldEqual, "")
})
})
Convey("Given field to set and update condition", t, func() {
query, err := NewUpdateQuery("table_a").
AddSetField("field_a = 'A'").
AddWhere("field_a IS NULL").
BuildQuery()
Convey("It should returns generated query", func() {
So(err, ShouldBeNil)
So(query, ShouldEqual, "UPDATE table_a SET field_a = 'A' WHERE field_a IS NULL")
})
})
}