-
Notifications
You must be signed in to change notification settings - Fork 26
/
conditional_test.go
114 lines (85 loc) · 2.93 KB
/
conditional_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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package qb
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/assert"
)
type ConditionalTestSuite struct {
suite.Suite
dialect Dialect
ctx *CompilerContext
country ColumnElem
score ColumnElem
}
func (suite *ConditionalTestSuite) SetupTest() {
suite.dialect = NewDefaultDialect()
suite.ctx = NewCompilerContext(suite.dialect)
suite.country = Column("country", Varchar()).NotNull()
suite.score = Column("score", BigInt()).NotNull()
}
func (suite *ConditionalTestSuite) TestConditionalLike() {
like := Like(suite.country, "%land%")
sql := like.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "country LIKE ?", sql)
assert.Equal(suite.T(), []interface{}{"%land%"}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalNotIn() {
notIn := NotIn(suite.country, "USA", "England", "Sweden")
sql := notIn.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "country NOT IN (?, ?, ?)", sql)
assert.Equal(suite.T(), []interface{}{"USA", "England", "Sweden"}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalIn() {
in := In(suite.country, "USA", "England", "Sweden")
sql := in.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "country IN (?, ?, ?)", sql)
assert.Equal(suite.T(), []interface{}{"USA", "England", "Sweden"}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalNotEq() {
notEq := NotEq(suite.country, "USA")
sql := notEq.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "country != ?", sql)
assert.Equal(suite.T(), []interface{}{"USA"}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalEq() {
eq := Eq(suite.country, "Turkey")
sql := eq.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "country = ?", sql)
assert.Equal(suite.T(), []interface{}{"Turkey"}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalGt() {
gt := Gt(suite.score, 1500)
sql := gt.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "score > ?", sql)
assert.Equal(suite.T(), []interface{}{1500}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalLt() {
lt := Lt(suite.score, 1500)
sql := lt.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "score < ?", sql)
assert.Equal(suite.T(), []interface{}{1500}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalGte() {
gte := Gte(suite.score, 1500)
sql := gte.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "score >= ?", sql)
assert.Equal(suite.T(), []interface{}{1500}, bindings)
}
func (suite *ConditionalTestSuite) TestConditionalLte() {
lte := Lte(suite.score, 1500)
sql := lte.Accept(suite.ctx)
bindings := suite.ctx.Binds
assert.Equal(suite.T(), "score <= ?", sql)
assert.Equal(suite.T(), []interface{}{1500}, bindings)
}
func TestConditionalTestSuite(t *testing.T) {
suite.Run(t, new(ConditionalTestSuite))
}