-
Notifications
You must be signed in to change notification settings - Fork 0
/
q_simple_test.go
49 lines (44 loc) · 1.17 KB
/
q_simple_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
package dal
import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestSimpleQuery(t *testing.T) {
newRecord := func() Record {
return nil
}
var qb = From("test").
Where().
Limit(10).
Offset(20).
StartFrom(Cursor("cursor_1")).
OrderBy(orderExpression{expression: FieldRef{Name: "field_1"}})
assertQuery := func(t *testing.T, q Query) {
assert.NotNil(t, q)
assert.Equal(t, "test", q.From().Name)
assert.NotNil(t, q.Where())
assert.NotNil(t, q.OrderBy())
assert.NotNil(t, q.Limit())
assert.NotNil(t, q.Offset())
assert.NotNil(t, q.StartFrom())
}
t.Run("no_conditions", func(t *testing.T) {
qbNoConditions := From("test")
q := qbNoConditions.SelectKeysOnly(reflect.String)
assert.Equal(t, reflect.String, q.IDKind())
assert.Equal(t, "test", q.From().Name)
})
t.Run("with_single_condition", func(t *testing.T) {
qb2 := qb.WhereField("field_2", Equal, "value_2")
q := qb2.SelectInto(newRecord)
assertQuery(t, q)
})
t.Run("with_multiple_conditions", func(t *testing.T) {
qb2 := qb.
WhereField("field_2", Equal, "value_2").
WhereField("field_3", Equal, "value_3")
q := qb2.SelectInto(newRecord)
assertQuery(t, q)
})
}