-
Notifications
You must be signed in to change notification settings - Fork 2
Add comprehensive test coverage for bulk insert functionality #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Add tests for snakeToPascalCase function in bulkinsert_test.go - Test edge cases: empty string, simple case, snake_case conversion - Test common initialisms (ID, URL, JSON) - Test underscore handling (double, leading, trailing) - Enhance main_test.go TestGenerate function - Add test case for queries with no INSERT statements - Add validation for invalid plugin options - Add validation for malformed JSON in plugin options - Include mock base code for type checking generated files - Update assertions to check file count instead of just existence - Enhance templates/template_test.go - Add test for pointer slice handling in ExtractFieldValues - Add error case tests for field not found and invalid struct types - Add error case tests for BuildBulkInsertQuery - Test zero numArgs, zero numParamsPerArg, and missing VALUES clause
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds comprehensive test coverage for the bulk insert code generation functionality, enhancing code quality and protecting against regressions. The changes introduce 236 lines of new test code covering core functions, edge cases, and error scenarios.
Key changes:
- Adds unit tests for
snakeToPascalCasefunction with edge cases (empty strings, initialisms, underscores) - Enhances main test suite with validation tests for plugin options and integrates Go type checking for generated code
- Adds comprehensive tests for template functions (
ExtractFieldValuesandBuildBulkInsertQuery) including error cases
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
bulkinsert_test.go |
New test file covering snakeToPascalCase function with 10 test cases for various edge cases |
main_test.go |
Enhanced with option validation tests, no-INSERT-query test case, and integrated Go type checker for generated code |
templates/template_test.go |
New test file for template functions with tests for pointer slices, field errors, and query building edge cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "error: VALUES clause not found": { | ||
| arrange: func(t *testing.T) (Args, Expected) { | ||
| return Args{ | ||
| originalQuery: "INSERT INTO users (id, name) SET id = ?, name = ?;", // VALUES がない |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment contains Japanese text 'VALUES がない' (meaning 'no VALUES'). Consider translating to English for consistency: '// No VALUES clause'.
| originalQuery: "INSERT INTO users (id, name) SET id = ?, name = ?;", // VALUES がない | |
| originalQuery: "INSERT INTO users (id, name) SET id = ?, name = ?;", // No VALUES clause |
| numParamsPerArg: 2, | ||
| }, Expected{ | ||
| query: "", | ||
| err: errors.New("VALUES clause not found"), |
Copilot
AI
Nov 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error message mismatch: The actual error message from buildBulkInsertQuery (line 64 in template.go) is 'invalid query format: VALUES clause not found in original query: %s', but the test expects just 'VALUES clause not found'. The test will fail because assert.ErrorContains checks if the error contains the expected string, and the actual error includes the full query in the message.
Overview
Adds comprehensive test coverage for the bulk insert code generation functionality, improving code quality and reliability through extensive unit testing.
Changes
New file:
bulkinsert_test.go(71 lines)snakeToPascalCasefunction covering edge cases: empty strings, simple cases, common initialisms (ID, URL, JSON), double underscores, and leading/trailing underscoresEnhanced:
main_test.go(+82 lines, -8 lines)New file:
templates/template_test.go(83 lines)ExtractFieldValuesfunction including pointer slices and error cases (field not found, invalid input types)BuildBulkInsertQueryfunction including error scenarios (zero arguments, zero parameters, missing VALUES clause)Impact