jet/utils_test.go

116 lines
2.9 KiB
Go
Raw Normal View History

2019-06-21 13:56:57 +02:00
package jet
2019-05-29 14:03:38 +02:00
import (
"gotest.tools/assert"
"testing"
)
2019-06-08 16:34:15 +02:00
var table1Col1 = IntegerColumn("col1")
2019-06-17 12:05:52 +02:00
var table1ColInt = IntegerColumn("col_int")
var table1ColFloat = FloatColumn("col_float")
2019-06-08 16:34:15 +02:00
var table1Col3 = IntegerColumn("col3")
2019-06-17 12:05:52 +02:00
var table1ColTime = TimeColumn("col_time")
2019-07-19 17:19:58 +02:00
var table1ColTimez = TimezColumn("col_timez")
var table1ColTimestamp = TimestampColumn("col_timestamp")
var table1ColTimestampz = TimestampzColumn("col_timestampz")
2019-06-17 12:05:52 +02:00
var table1ColBool = BoolColumn("col_bool")
2019-07-19 17:19:58 +02:00
var table1ColDate = DateColumn("col_date")
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,
2019-07-19 17:19:58 +02:00
table1ColTimez,
table1ColBool,
table1ColDate,
table1ColTimestamp,
table1ColTimestampz,
)
2019-06-08 16:34:15 +02:00
var table2Col3 = IntegerColumn("col3")
var table2Col4 = IntegerColumn("col4")
2019-06-17 12:05:52 +02:00
var table2ColInt = IntegerColumn("col_int")
var table2ColFloat = FloatColumn("col_float")
var table2ColStr = StringColumn("col_str")
var table2ColBool = BoolColumn("col_bool")
var table2ColTime = TimeColumn("col_time")
2019-07-19 17:19:58 +02:00
var table2ColTimez = TimezColumn("col_timez")
var table2ColTimestamp = TimestampColumn("col_timestamp")
var table2ColTimestampz = TimestampzColumn("col_timestampz")
var table2ColDate = DateColumn("col_date")
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,
2019-07-19 17:19:58 +02:00
table2ColTime,
table2ColTimez,
table2ColDate,
table2ColTimestamp,
table2ColTimestampz,
)
2019-06-08 16:34:15 +02:00
var table3Col1 = IntegerColumn("col1")
2019-06-17 12:05:52 +02:00
var table3ColInt = IntegerColumn("col_int")
2019-06-08 16:34:15 +02:00
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-07-08 10:48:03 +02:00
out := sqlBuilder{}
2019-07-18 17:43:11 +02:00
err := clause.serialize(selectStatement, &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) {
2019-07-08 10:48:03 +02:00
out := sqlBuilder{}
2019-07-18 17:43:11 +02:00
err := clause.serialize(selectStatement, &out)
2019-06-05 17:15:20 +02:00
//fmt.Println(out.buff.String())
2019-06-05 17:15:20 +02:00
assert.Assert(t, err != nil)
2019-06-21 13:56:57 +02:00
assert.Error(t, err, errString)
2019-06-05 17:15:20 +02:00
}
func assertProjectionSerialize(t *testing.T, projection projection, query string, args ...interface{}) {
2019-07-08 10:48:03 +02:00
out := sqlBuilder{}
2019-07-18 17:43:11 +02:00
err := projection.serializeForProjection(selectStatement, &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 assertStatement(t *testing.T, query Statement, expectedQuery string, expectedArgs ...interface{}) {
2019-06-11 12:47:35 +02:00
queryStr, args, err := query.Sql()
assert.NilError(t, err)
//fmt.Println(queryStr)
2019-06-11 12:47:35 +02:00
assert.Equal(t, queryStr, expectedQuery)
assert.DeepEqual(t, args, expectedArgs)
}
func assertStatementErr(t *testing.T, stmt Statement, errorStr string) {
_, _, err := stmt.Sql()
assert.Assert(t, err != nil)
2019-06-21 13:56:57 +02:00
assert.Error(t, err, errorStr)
}