jet/sqlbuilder/test_utils.go

90 lines
2.1 KiB
Go
Raw Normal View History

package sqlbuilder
2019-05-29 14:03:38 +02:00
import (
2019-06-05 17:15:20 +02:00
"fmt"
2019-05-29 14:03:38 +02:00
"gotest.tools/assert"
"testing"
)
2019-06-08 16:34:15 +02:00
var table1Col1 = IntegerColumn("col1")
var table1ColInt = IntegerColumn("colInt")
var table1ColFloat = FloatColumn("colFloat")
var table1Col3 = IntegerColumn("col3")
var table1ColTime = TimeColumn("colTime")
var table1ColBool = BoolColumn("colBool")
2019-05-29 14:03:38 +02:00
var table1 = NewTable(
2019-03-09 09:52:03 +01:00
"db",
"table1",
table1Col1,
table1ColInt,
table1ColFloat,
table1Col3,
2019-05-29 14:03:38 +02:00
table1ColTime,
table1ColBool)
2019-06-08 16:34:15 +02:00
var table2Col3 = IntegerColumn("col3")
var table2Col4 = IntegerColumn("col4")
var table2ColInt = IntegerColumn("colInt")
var table2ColFloat = FloatColumn("colFloat")
var table2ColStr = StringColumn("colStr")
var table2ColBool = BoolColumn("colBool")
var table2ColTime = TimeColumn("colTime")
2019-05-29 14:03:38 +02:00
var table2 = NewTable(
2019-03-09 09:52:03 +01:00
"db",
"table2",
table2Col3,
2019-05-29 14:03:38 +02:00
table2Col4,
table2ColInt,
table2ColFloat,
table2ColStr,
2019-05-29 14:03:38 +02:00
table2ColBool,
table2ColTime)
2019-06-08 16:34:15 +02:00
var table3Col1 = IntegerColumn("col1")
var table3ColInt = IntegerColumn("colInt")
var table3StrCol = StringColumn("col2")
var table3 = NewTable(
2019-03-09 09:52:03 +01:00
"db",
"table3",
table3Col1,
2019-06-05 17:15:20 +02:00
table3ColInt,
2019-05-29 14:03:38 +02:00
table3StrCol)
2019-06-05 17:15:20 +02:00
func assertClauseSerialize(t *testing.T, clause clause, query string, args ...interface{}) {
2019-05-29 14:03:38 +02:00
out := queryData{}
2019-06-05 17:15:20 +02:00
err := clause.serialize(select_statement, &out)
2019-05-29 14:03:38 +02:00
assert.NilError(t, err)
2019-06-01 18:04:56 +02:00
assert.DeepEqual(t, out.buff.String(), query)
assert.DeepEqual(t, out.args, args)
2019-05-29 14:03:38 +02:00
}
2019-06-05 17:15:20 +02:00
func assertClauseSerializeErr(t *testing.T, clause clause, errString string) {
out := queryData{}
err := clause.serialize(select_statement, &out)
fmt.Println(err)
assert.Assert(t, err != nil)
assert.Equal(t, err.Error(), errString)
}
func assertProjectionSerialize(t *testing.T, projection projection, query string, args ...interface{}) {
out := queryData{}
err := projection.serializeForProjection(select_statement, &out)
assert.NilError(t, err)
assert.DeepEqual(t, out.buff.String(), query)
assert.DeepEqual(t, out.args, args)
}
2019-06-11 12:47:35 +02:00
func assertQuery(t *testing.T, query Statement, expectedQuery string, expectedArgs ...interface{}) {
queryStr, args, err := query.Sql()
assert.NilError(t, err)
assert.Equal(t, queryStr, expectedQuery)
assert.DeepEqual(t, args, expectedArgs)
}