Documentation
¶
Overview ¶
Package testutil provides common testing utilities to reduce code duplication across test files in the gorilla DataFrame library.
This package consolidates common patterns identified in test similarity analysis: - Memory allocator setup and cleanup - Standard test DataFrame creation - Resource lifecycle management - Common test assertions
Index ¶
- func AssertDataFrameEqual(t *testing.T, expected, actual *dataframe.DataFrame)
- func AssertDataFrameHasColumns(t *testing.T, df *dataframe.DataFrame, expectedColumns []string)
- func AssertDataFrameNotEmpty(t *testing.T, df *dataframe.DataFrame)
- func CreateSimpleTestDataFrame(allocator memory.Allocator) *dataframe.DataFrame
- func CreateTestDataFrame(allocator memory.Allocator, opts ...TestDataFrameOption) *dataframe.DataFrame
- func CreateTestTableWithData(allocator memory.Allocator, data map[string]interface{}) *dataframe.DataFrame
- type SQLTestContext
- type TestDataFrameOption
- type TestMemoryContext
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertDataFrameEqual ¶
AssertDataFrameEqual performs deep equality comparison of DataFrames. This consolidates common DataFrame assertion patterns.
func AssertDataFrameHasColumns ¶
AssertDataFrameHasColumns verifies that a DataFrame has the expected columns.
func AssertDataFrameNotEmpty ¶
AssertDataFrameNotEmpty verifies that a DataFrame is not empty.
func CreateSimpleTestDataFrame ¶
CreateSimpleTestDataFrame creates a simple 2-column DataFrame for basic testing. This is useful for tests that don't need the full employee dataset.
func CreateTestDataFrame ¶
func CreateTestDataFrame(allocator memory.Allocator, opts ...TestDataFrameOption) *dataframe.DataFrame
CreateTestDataFrame creates a standard test DataFrame with employee data. This consolidates the common createTestDataFrame pattern found across multiple test files.
Default DataFrame includes: - name (string): ["Alice", "Bob", "Charlie", "David"] - age (int64): [25, 30, 35, 28] - department (string): ["Engineering", "Sales", "Engineering", "Marketing"] - salary (int64): [100000, 80000, 120000, 75000]
Example usage:
mem := testutil.SetupMemoryTest(t) defer mem.Release() df := testutil.CreateTestDataFrame(mem.Allocator) defer df.Release()
Types ¶
type SQLTestContext ¶
type SQLTestContext struct {
Translator *sql.SQLTranslator
TestTable *dataframe.DataFrame
Allocator memory.Allocator
// contains filtered or unexported fields
}
SQLTestContext provides a configured SQL translator with test data for SQL tests.
func SetupSQLTest ¶
func SetupSQLTest(t *testing.T) *SQLTestContext
SetupSQLTest creates a configured SQL translator with a test table for SQL tests. This consolidates the common SQL test setup pattern found across SQL test files.
The test table "employees" contains: - name, age, department, salary columns with sample employee data - Suitable for testing SELECT, WHERE, GROUP BY, HAVING operations
Example usage:
sqlCtx := testutil.SetupSQLTest(t)
defer sqlCtx.Release()
stmt, err := sql.ParseSQL("SELECT name FROM employees WHERE age > 30")
lazy, err := sqlCtx.Translator.TranslateStatement(stmt)
func SetupSimpleSQLTest ¶
func SetupSimpleSQLTest(t *testing.T) *SQLTestContext
SetupSimpleSQLTest creates a minimal SQL test context with simple test data. Useful for basic SQL parsing and translation tests.
func (*SQLTestContext) AssertSQLQueryResult ¶
func (ctx *SQLTestContext) AssertSQLQueryResult(t *testing.T, query string, expectedRowCount int, expectedColumns []string) *dataframe.DataFrame
AssertSQLQueryResult executes a SQL query and validates the result structure. This consolidates common SQL test assertion patterns.
func (*SQLTestContext) ExecuteSQLQuery ¶
ExecuteSQLQuery executes a SQL query and returns the result DataFrame. This consolidates the common pattern of parsing -> translating -> collecting SQL queries.
func (*SQLTestContext) Release ¶
func (ctx *SQLTestContext) Release()
Release cleans up the SQL test context.
type TestDataFrameOption ¶
type TestDataFrameOption func(*testDataFrameConfig)
TestDataFrameOption configures test DataFrame creation.
func WithActiveColumn ¶
func WithActiveColumn() TestDataFrameOption
WithActiveColumn includes an 'active' boolean column.
func WithRowCount ¶
func WithRowCount(count int) TestDataFrameOption
WithRowCount sets the number of rows in test data.
type TestMemoryContext ¶
type TestMemoryContext struct {
Allocator memory.Allocator
// contains filtered or unexported fields
}
TestMemoryContext provides memory allocator with automatic cleanup.
func SetupMemoryTest ¶
func SetupMemoryTest(tb testing.TB) *TestMemoryContext
SetupMemoryTest creates a memory allocator with automatic cleanup for tests. Returns a TestMemoryContext that should be released with defer.
Example usage:
mem := testutil.SetupMemoryTest(t) defer mem.Release()
func (*TestMemoryContext) Release ¶
func (tmc *TestMemoryContext) Release()
Release performs cleanup of the memory context.