Documentation
¶
Overview ¶
Package testcases defines shared test case types and helpers for multi-dialect testing.
Index ¶
- Constants
- func NewOrderPGSchema() pg.Schema
- func NewOrderSchema() schema.Schema
- func NewPersonPGSchema() pg.Schema
- func NewPersonSchema() schema.Schema
- func NewProductPGSchema() pg.Schema
- func NewProductSchema() schema.Schema
- type Category
- type ConvertTestCase
- func ArrayTests() []ConvertTestCase
- func BasicTests() []ConvertTestCase
- func CastTests() []ConvertTestCase
- func ComprehensionTests() []ConvertTestCase
- func JSONTests() []ConvertTestCase
- func OperatorTests() []ConvertTestCase
- func RegexTests() []ConvertTestCase
- func StringTests() []ConvertTestCase
- func TimestampTests() []ConvertTestCase
- type ParameterizedTestCase
Constants ¶
const EnvDefault = ""
EnvDefault is the default environment setup name (basic types, no schema).
const EnvWithJSON = "json_schema"
EnvWithJSON is an environment with JSON/JSONB schema fields.
const EnvWithSchema = "schema"
EnvWithSchema is an environment with a schema-based type provider.
const EnvWithTimestamp = "timestamp"
EnvWithTimestamp is an environment for timestamp operations.
Variables ¶
This section is empty.
Functions ¶
func NewOrderPGSchema ¶
NewOrderPGSchema returns a PostgreSQL-specific schema for the "orders" table.
func NewOrderSchema ¶
NewOrderSchema returns a dialect-agnostic schema for the "orders" table, with array and timestamp fields.
func NewPersonPGSchema ¶
NewPersonPGSchema returns a PostgreSQL-specific schema for the "person" table.
func NewPersonSchema ¶
NewPersonSchema returns a dialect-agnostic schema for the "person" table, suitable for basic, operator, and string tests.
func NewProductPGSchema ¶
NewProductPGSchema returns a PostgreSQL-specific schema for the "product" table.
func NewProductSchema ¶
NewProductSchema returns a dialect-agnostic schema for the "product" table, with JSON/JSONB fields for JSON-related tests.
Types ¶
type Category ¶
type Category string
Category classifies a test case for organization and selective running.
const ( CategoryBasic Category = "basic" CategoryOperator Category = "operator" CategoryString Category = "string" CategoryRegex Category = "regex" CategoryJSON Category = "json" CategoryArray Category = "array" CategoryComprehension Category = "comprehension" CategoryTimestamp Category = "timestamp" CategoryParameterized Category = "parameterized" CategoryCast Category = "cast" CategoryFieldAccess Category = "field_access" )
Test case categories.
type ConvertTestCase ¶
type ConvertTestCase struct {
// Name is the test case name (used for t.Run).
Name string
// CELExpr is the CEL expression source to compile and convert.
CELExpr string
// Category classifies the test case.
Category Category
// EnvSetup identifies which CEL environment setup to use.
// Empty string means "default" (basic types, no schema).
EnvSetup string
// WantSQL maps dialect name to expected SQL output.
// If a dialect is absent, the test is skipped for that dialect.
WantSQL map[dialect.Name]string
// WantErr maps dialect name to whether an error is expected.
// If a dialect is absent, no error is expected.
WantErr map[dialect.Name]bool
// SkipDialect maps dialect name to a skip reason.
// If a dialect is present, the test is skipped with the given message.
SkipDialect map[dialect.Name]string
}
ConvertTestCase defines a single CEL-to-SQL conversion test case with expected output per dialect.
func ArrayTests ¶
func ArrayTests() []ConvertTestCase
ArrayTests returns test cases for array operations.
func BasicTests ¶
func BasicTests() []ConvertTestCase
BasicTests returns test cases for basic comparisons and expressions.
func CastTests ¶
func CastTests() []ConvertTestCase
CastTests returns test cases for type casting operations.
func ComprehensionTests ¶
func ComprehensionTests() []ConvertTestCase
ComprehensionTests returns test cases for CEL comprehension operations.
func JSONTests ¶
func JSONTests() []ConvertTestCase
JSONTests returns test cases for JSON/JSONB field access and operations. These tests require the "json_schema" environment setup.
func OperatorTests ¶
func OperatorTests() []ConvertTestCase
OperatorTests returns test cases for logical and arithmetic operators.
func RegexTests ¶
func RegexTests() []ConvertTestCase
RegexTests returns test cases for regex pattern matching.
func StringTests ¶
func StringTests() []ConvertTestCase
StringTests returns test cases for string functions.
func TimestampTests ¶
func TimestampTests() []ConvertTestCase
TimestampTests returns test cases for timestamp and duration operations.
func (*ConvertTestCase) ForDialect ¶
func (tc *ConvertTestCase) ForDialect(d dialect.Name) (sql string, hasExpected bool)
ForDialect returns the expected SQL for a given dialect, and whether the test case has an expectation for that dialect.
func (*ConvertTestCase) ShouldError ¶
func (tc *ConvertTestCase) ShouldError(d dialect.Name) bool
ShouldError returns whether an error is expected for the given dialect.
func (*ConvertTestCase) ShouldSkip ¶
func (tc *ConvertTestCase) ShouldSkip(d dialect.Name) string
ShouldSkip returns the skip reason for a dialect, or empty string if not skipped.
type ParameterizedTestCase ¶
type ParameterizedTestCase struct {
// Name is the test case name.
Name string
// CELExpr is the CEL expression source.
CELExpr string
// Category classifies the test case.
Category Category
// EnvSetup identifies which CEL environment setup to use.
EnvSetup string
// WantSQL maps dialect name to expected parameterized SQL output.
WantSQL map[dialect.Name]string
// WantParams maps dialect name to expected parameter values.
WantParams map[dialect.Name][]any
// WantErr maps dialect name to whether an error is expected.
WantErr map[dialect.Name]bool
// SkipDialect maps dialect name to a skip reason.
SkipDialect map[dialect.Name]string
}
ParameterizedTestCase defines a test case for parameterized SQL conversion.
func ParameterizedTests ¶
func ParameterizedTests() []ParameterizedTestCase
ParameterizedTests returns test cases for parameterized SQL conversion.