-
Notifications
You must be signed in to change notification settings - Fork 62
/
call_test.go
31 lines (25 loc) · 790 Bytes
/
call_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
package dat
import (
"testing"
"gopkg.in/stretchr/testify.v1/assert"
)
func TestCallSql(t *testing.T) {
sql, args := Call("foo", 1, "two").ToSQL()
assert.Equal(t, "SELECT * FROM foo($1,$2)", sql)
assert.Exactly(t, []interface{}{1, "two"}, args)
}
func TestCallNoArgsSql(t *testing.T) {
sql, args := Call("foo").ToSQL()
assert.Equal(t, "SELECT * FROM foo()", sql)
assert.Nil(t, args)
}
func TestCallInterpolate(t *testing.T) {
sql, args, err := Call("foo", 1).SetIsInterpolated(true).Interpolate()
assert.NoError(t, err)
assert.Equal(t, "SELECT * FROM foo(1)", sql)
assert.Exactly(t, []interface{}(nil), args)
sql, args, err = Call("foo", 1).Interpolate()
assert.NoError(t, err)
assert.Equal(t, "SELECT * FROM foo($1)", sql)
assert.Exactly(t, []interface{}{1}, args)
}