2020-08-06 20:58:47 +03:00
|
|
|
// Package fixt contains common test fixture values.
|
|
|
|
// It exists as its own package separate from testh mostly
|
|
|
|
// for semantic convenience. Broadly speaking, for any one
|
|
|
|
// database column, we want to test three values: the zero value,
|
|
|
|
// a non-zero value, and NULL (note that for some columns, e.g.
|
|
|
|
// primary key columns, NULL does not make sense). Thus for each
|
|
|
|
// value there is a ValueZ (zero) and Value (non-zero) item.
|
|
|
|
package fixt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2023-11-22 00:49:52 +03:00
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
|
2020-08-23 13:42:15 +03:00
|
|
|
"github.com/neilotoole/sq/libsq/core/kind"
|
2020-08-06 20:58:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// These consts are test fixtures for various data types.
|
|
|
|
const (
|
2023-11-22 00:49:52 +03:00
|
|
|
Text string = "seven"
|
|
|
|
TextZ string = ""
|
|
|
|
Int int64 = 7
|
|
|
|
IntZ int64 = 0
|
|
|
|
Float float64 = 7.7
|
|
|
|
FloatZ float64 = 0
|
|
|
|
|
|
|
|
Bool bool = true
|
|
|
|
BoolZ bool = false
|
|
|
|
BitString string = "1001"
|
|
|
|
BitStringZ string = "0"
|
|
|
|
TimeOfDay string = "07:07:07"
|
|
|
|
TimeOfDayZ string = "00:00:00"
|
|
|
|
JSON string = `{"val": 7}`
|
|
|
|
JSONZ string = "{}"
|
|
|
|
EnumAlfa string = "alfa"
|
|
|
|
EnumBravo string = "bravo"
|
|
|
|
UUID string = "77777777-7777-7777-7777-777777777777"
|
|
|
|
UUIDZ string = "00000000-0000-0000-0000-000000000000"
|
2020-08-06 20:58:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// These vars are text fixtures for various data types.
|
|
|
|
var (
|
2023-11-22 00:49:52 +03:00
|
|
|
Decimal = decimal.New(7777, -2)
|
|
|
|
DecimalZ = decimal.New(0, 0)
|
|
|
|
Money = decimal.New(7777, -2)
|
|
|
|
MoneyZ = decimal.New(0, 0)
|
2020-08-06 20:58:47 +03:00
|
|
|
Bytes = []byte("seven")
|
|
|
|
BytesZ = []byte("")
|
|
|
|
Datetime = mustParseTime(time.RFC3339, "2017-07-07T07:07:07-00:00").UTC()
|
|
|
|
DatetimeZ = mustParseTime(time.RFC3339, "1989-11-09T00:00:00-00:00").UTC()
|
2023-05-07 05:36:34 +03:00
|
|
|
Date = mustParseTime(time.DateOnly, "2017-07-07").UTC()
|
|
|
|
DateZ = mustParseTime(time.DateOnly, "1989-11-09").UTC()
|
2020-08-06 20:58:47 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func mustParseTime(layout, value string) time.Time {
|
|
|
|
t, err := time.ParseInLocation(layout, value, time.UTC)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
// ColNamePerKind returns a slice of column names, one column name for
|
2020-08-23 13:42:15 +03:00
|
|
|
// each kind (excepting kind.Unknown and kind.Null, unless withNull
|
2020-08-06 20:58:47 +03:00
|
|
|
// or withUnknown are set). If isIntBool is
|
2020-08-23 13:42:15 +03:00
|
|
|
// true, kind.Int is returned for "col_bool", otherwise kind.Bool.
|
2022-12-18 11:35:59 +03:00
|
|
|
func ColNamePerKind(isIntBool, withNull, withUnknown bool) (colNames []string, kinds []kind.Kind) {
|
|
|
|
colNames = []string{
|
|
|
|
"col_int", "col_float", "col_decimal", "col_bool", "col_text", "col_datetime", "col_date",
|
|
|
|
"col_time", "col_bytes",
|
|
|
|
}
|
|
|
|
kinds = []kind.Kind{
|
|
|
|
kind.Int, kind.Float, kind.Decimal, kind.Bool, kind.Text, kind.Datetime, kind.Date, kind.Time,
|
|
|
|
kind.Bytes,
|
|
|
|
}
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
if isIntBool {
|
2020-08-23 13:42:15 +03:00
|
|
|
kinds[3] = kind.Int
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if withNull {
|
|
|
|
colNames = append(colNames, "col_null")
|
2020-08-23 13:42:15 +03:00
|
|
|
kinds = append(kinds, kind.Null)
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
if withUnknown {
|
|
|
|
colNames = append(colNames, "col_unknown")
|
2020-08-23 13:42:15 +03:00
|
|
|
kinds = append(kinds, kind.Unknown)
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return colNames, kinds
|
|
|
|
}
|
|
|
|
|
|
|
|
// The gopher.gif image used for testing bytes.
|
|
|
|
const (
|
|
|
|
GopherFilename = "gopher.gif"
|
|
|
|
GopherPath = "testh/fixt/testdata/gopher.gif"
|
|
|
|
GopherSize = 1788 // filesize in bytes
|
2023-07-27 07:19:11 +03:00
|
|
|
|
|
|
|
// BlobDBPath is the path to blob.db, which contains the gopher image
|
|
|
|
// in the "blobs" table.
|
|
|
|
BlobDBPath = "drivers/sqlite3/testdata/blob.db"
|
2020-08-06 20:58:47 +03:00
|
|
|
)
|