jet/sqlbuilder/test_utils.go

83 lines
2 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-05 17:15:20 +02:00
var table1Col1 = NewIntegerColumn("col1", true)
var table1ColInt = NewIntegerColumn("colInt", true)
var table1ColFloat = NewFloatColumn("colFloat", true)
var table1Col3 = NewIntegerColumn("col3", true)
var table1ColTime = NewTimeColumn("colTime", true)
var table1ColBool = NewBoolColumn("colBool", true)
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-05 17:15:20 +02:00
var table2Col3 = NewIntegerColumn("col3", true)
var table2Col4 = NewIntegerColumn("col4", true)
var table2ColInt = NewIntegerColumn("colInt", true)
var table2ColFloat = NewFloatColumn("colFloat", true)
var table2ColStr = NewStringColumn("colStr", true)
var table2ColBool = NewBoolColumn("colBool", true)
var table2ColTime = NewTimeColumn("colTime", true)
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-05 17:15:20 +02:00
var table3Col1 = NewIntegerColumn("col1", true)
var table3ColInt = NewIntegerColumn("colInt", true)
var table3StrCol = NewStringColumn("col2", true)
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)
}