Commit 03e53e2
committed
test(mysql): add comprehensive pagination and error handling tests
Add 55 new test functions (1,011 lines) to improve MySQL driver test coverage.
## New Test Files
### Pagination Tests (22 functions, 531 lines)
- AllAndCount: 7 tests covering basic usage, WHERE conditions, pagination, field selection, empty results, cache support, DISTINCT queries
- ScanAndCount: 7 tests covering basic usage, WHERE conditions, pagination, single record, empty results, field selection, cache support
- Chunk: 5 tests covering basic iteration, early stop, WHERE conditions, error handling, empty results
- Page/Limit: 3 tests covering boundary values (0, negative, beyond data), combination usage
### Error Handling Tests (33 functions, 480 lines)
- Nil/empty data handling: Insert/Update with nil, empty map, empty slice
- Missing WHERE clause: Update/Delete without WHERE
- Scan errors: nil pointer, invalid pointer type, empty result
- Invalid SQL: invalid operators, non-existent fields/tables
- SQL injection prevention: WHERE clause, Insert, Update (parameterized queries)
- Aggregate functions: Max/Min/Avg/Sum with empty results
- Context: cancelled context handling
- Transaction: rollback after error
- Duplicate key errors
- Invalid connections
## Framework Bugs Discovered
During test development, discovered 3 framework edge case bugs:
- gogf#4697: Fields("") should handle empty string gracefully
- Regression test: Test_Model_Fields_Empty
- gogf#4697
- gogf#4698: AllAndCount(true) with multiple fields should work correctly
- Regression test: Test_Model_AllAndCount_WithFields
- gogf#4698
- gogf#4699: Negative Limit/Page values should be sanitized
- Regression tests: Test_Model_Page_Boundary, Test_Model_Limit_Boundary
- gogf#4699
These tests define correct expected behavior and will pass once bugs are fixed.
## Test Quality
- All tests use gtest.C() wrapper pattern
- Independent test execution (no dependencies)
- Comprehensive boundary/edge case coverage
- Proper error validation
- Code formatted with gofmt and gci
ref gogf#46891 parent a4b80e8 commit 03e53e2
2 files changed
Lines changed: 1021 additions & 0 deletions
File tree
- contrib/drivers/mysql
0 commit comments