Skip to content

Conversation

@tomtwinkle
Copy link
Owner

@tomtwinkle tomtwinkle commented Nov 12, 2025

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)

    • Added tests for snakeToPascalCase function covering edge cases: empty strings, simple cases, common initialisms (ID, URL, JSON), double underscores, and leading/trailing underscores
  • Enhanced: main_test.go (+82 lines, -8 lines)

    • Added validation tests for plugin options (missing required fields, malformed JSON)
    • Added test for queries without INSERT statements
    • Integrated actual Go type checking for generated code using a mock base code structure
    • Improved test assertions with file count verification instead of just checking for existence
  • New file: templates/template_test.go (83 lines)

    • Added tests for ExtractFieldValues function including pointer slices and error cases (field not found, invalid input types)
    • Added tests for BuildBulkInsertQuery function including error scenarios (zero arguments, zero parameters, missing VALUES clause)

Impact

  • Quality: Significantly improved code reliability with 236 new lines of test code covering core functions and edge cases
  • Maintainability: Better protection against regressions when modifying bulk insert logic or case conversion utilities
  • Validation: Generated code is now validated through Go's type checker, ensuring syntactic correctness of the output
  • Coverage: Tests now cover both happy paths and error conditions, making the plugin more robust

- 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
Copilot AI review requested due to automatic review settings November 12, 2025 04:09
@tomtwinkle tomtwinkle self-assigned this Nov 12, 2025
Copilot finished reviewing on behalf of tomtwinkle November 12, 2025 04:10
Copy link

Copilot AI left a 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 snakeToPascalCase function 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 (ExtractFieldValues and BuildBulkInsertQuery) 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 がない
Copy link

Copilot AI Nov 12, 2025

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'.

Suggested change
originalQuery: "INSERT INTO users (id, name) SET id = ?, name = ?;", // VALUES がない
originalQuery: "INSERT INTO users (id, name) SET id = ?, name = ?;", // No VALUES clause

Copilot uses AI. Check for mistakes.
numParamsPerArg: 2,
}, Expected{
query: "",
err: errors.New("VALUES clause not found"),
Copy link

Copilot AI Nov 12, 2025

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.

Copilot uses AI. Check for mistakes.
@tomtwinkle tomtwinkle merged commit f4b1f4b into main Nov 12, 2025
7 checks passed
@tomtwinkle tomtwinkle deleted the enhancement-add-generated-code-test branch November 12, 2025 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants