test(mysql): add pagination and error handling tests#4703
Open
lingcoder wants to merge 2 commits intogogf:masterfrom
Open
test(mysql): add pagination and error handling tests#4703lingcoder wants to merge 2 commits intogogf:masterfrom
lingcoder wants to merge 2 commits intogogf:masterfrom
Conversation
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#4689
Replace t.Assert(len(result) <= 1) with t.AssertLE(len(result), 1). t.Assert requires two arguments (actual, expected) but was given a boolean expression.
This was referenced Feb 13, 2026
lingcoder
added a commit
to lingcoder/gf
that referenced
this pull request
Feb 13, 2026
## Summary Fix bug where AllAndCount(true) with multiple fields generates invalid SQL COUNT(field1, field2, ...) causing syntax error. ## Root Cause When useFieldForCount=true, the COUNT query inherits the fields configuration from the model, generating COUNT(multiple fields) which is invalid SQL syntax. ## Fix Always use COUNT(1) regardless of useFieldForCount parameter since COUNT() accepts only one argument. Applied to both AllAndCount() and ScanAndCount() methods in database/gdb/gdb_model_select.go. ## Tests Added Test_Issue4698 in contrib/drivers/mysql/mysql_z_unit_issue_test.go with 5 test cases covering all scenarios. Updated SQLiteCGo tests to expect correct behavior after framework fix. Fixes gogf#4698 Ref gogf#4703
lingcoder
added a commit
to lingcoder/gf
that referenced
this pull request
Feb 13, 2026
## Summary Fix bug where AllAndCount(true) with multiple fields generates invalid SQL COUNT(field1, field2, ...) causing syntax error. ## Root Cause When useFieldForCount=true, the COUNT query inherits the fields configuration from the model, generating COUNT(multiple fields) which is invalid SQL syntax. ## Fix Always use COUNT(1) regardless of useFieldForCount parameter since COUNT() accepts only one argument. Applied to both AllAndCount() and ScanAndCount() methods in database/gdb/gdb_model_select.go. ## Tests Added Test_Issue4698 in contrib/drivers/mysql/mysql_z_unit_issue_test.go with 5 test cases covering all scenarios. Updated SQLiteCGo tests to expect correct behavior after framework fix. Fixes gogf#4698 Ref gogf#4703
7f29c65 to
2433f49
Compare
This was referenced Feb 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test coverage added:
Ref #4689
Test plan