-
Notifications
You must be signed in to change notification settings - Fork 26
/
update_test.go
63 lines (51 loc) · 1.5 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
56
57
58
59
60
61
62
63
package qb
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/assert"
)
type UpdateTestSuite struct {
suite.Suite
dialect Dialect
ctx *CompilerContext
users TableElem
}
func (suite *UpdateTestSuite) SetupTest() {
suite.dialect = NewDefaultDialect()
suite.ctx = NewCompilerContext(suite.dialect)
suite.users = Table(
"users",
Column("id", BigInt()).NotNull(),
Column("email", Varchar()).NotNull().Unique(),
PrimaryKey("email"),
)
}
func (suite *UpdateTestSuite) TestUpdateSimple() {
sql := Update(suite.users).
Values(map[string]interface{}{
"email": "[email protected]",
}).Accept(suite.ctx)
binds := suite.ctx.Binds
assert.Contains(suite.T(), sql, "UPDATE users")
assert.Contains(suite.T(), sql, "SET email = ?")
assert.Equal(suite.T(), []interface{}{"[email protected]"}, binds)
}
func (suite *UpdateTestSuite) TestUpdateWhereReturning() {
sql := Update(suite.users).
Values(map[string]interface{}{"email": "[email protected]"}).
Where(Eq(suite.users.C("email"), "al@pacino")).
Returning(suite.users.C("id"), suite.users.C("email")).
Accept(suite.ctx)
binds := suite.ctx.Binds
assert.Contains(suite.T(), sql, "UPDATE users")
assert.Contains(suite.T(), sql, "SET email = ?")
assert.Contains(suite.T(), sql, "WHERE email = ?")
assert.Contains(suite.T(), sql, "RETURNING id, email")
assert.Equal(suite.T(), []interface{}{
"al@pacino",
}, binds)
}
func TestUpdateTestSuite(t *testing.T) {
suite.Run(t, new(UpdateTestSuite))
}