Skip to content

chore: refactor all tests by category#2260

Open
mromaszewicz wants to merge 3 commits intooapi-codegen:mainfrom
mromaszewicz:chore/refactor-tests
Open

chore: refactor all tests by category#2260
mromaszewicz wants to merge 3 commits intooapi-codegen:mainfrom
mromaszewicz:chore/refactor-tests

Conversation

@mromaszewicz
Copy link
Member

Replace the organically-grown test directory structure (issue-numbered directories, flat parameter/component tests) with a feature-based taxonomy that makes coverage visible at a glance.

New structure:
components/{primitives,objects,nullable,recursive}
aggregates/{allof,anyof,oneof}
parameters/{path/{simple,label,matrix},query/{form,deep_object},
header/simple,cookie/form,content,precedence,encoding}
externalref/ (multi-package external $ref qualification)

Each directory contains a minimal OpenAPI spec exercising one feature, a config.yaml, a doc.go with go:generate, committed generated code, and round-trip tests that instantiate types and verify JSON marshaling.

Key changes:

  • Absorb issue-specific directories into feature categories
  • Delete old flat test directories (server/, strict-server/, client/, schemas/, cookies/, compatibility/, filter/, outputoptions/, etc.)
  • Add comprehensive parameter permutation coverage across all location x style x explode x value-type combinations
  • Fold issue-2113 (external ref in responses) into externalref/
  • Add tools.go to keep oapi-codegen/v2 in go.mod for go:generate (previously kept alive implicitly by old test imports)

@mromaszewicz mromaszewicz requested a review from a team as a code owner February 27, 2026 17:50
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@mromaszewicz
Copy link
Member Author

@greptileai

@greptile-apps
Copy link

greptile-apps bot commented Feb 27, 2026

Greptile Summary

This PR successfully reorganizes the internal test directory from an organic, issue-numbered structure into a clean feature-based taxonomy. The refactoring deletes 52k lines while adding only 10k, demonstrating significant simplification.

Key improvements:

  • Introduced tools.go with proper build constraints to maintain oapi-codegen/v2 dependency for go:generate directives
  • Organized tests into logical categories: components/, aggregates/, parameters/, externalref/
  • Added comprehensive parameter testing across all OpenAPI parameter styles (simple, label, matrix, form, deepObject) and locations (path, query, header, cookie)
  • Consolidated issue-2113 (external ref in responses) into the externalref/ package with proper import-mapping
  • Cleaned up go.mod by removing unused framework dependencies (gin, iris, gorilla, testutil)
  • Each test directory follows consistent structure: minimal spec.yaml, config.yaml, doc.go with go:generate, and round-trip tests

Test coverage:
The new structure makes test coverage immediately visible through directory names, covering primitives, objects, nullable types, recursive schemas, allOf/anyOf/oneOf aggregates, and all parameter style permutations.

Confidence Score: 5/5

  • This PR is safe to merge with high confidence
  • This is a pure test refactoring that improves organization without changing functionality. The tools.go pattern is standard Go practice, all configs follow consistent structure, tests are comprehensive and well-written, and the massive code deletion (52k vs 10k added) indicates successful consolidation rather than loss of coverage.
  • No files require special attention

Important Files Changed

Filename Overview
internal/test/tools.go Added tools.go with go:build constraint to keep oapi-codegen dependency in go.mod for go:generate directives
internal/test/go.mod Cleaned up dependencies, removing unused framework imports (gin, iris, gorilla, etc.)
internal/test/components/primitives/primitives_test.go Comprehensive tests for primitive types, enums, formats, and JSON round-trip serialization
internal/test/parameters/path/simple/path_simple_test.go Thorough testing of simple-style path parameters with explode/noExplode for primitives, arrays, and objects
internal/test/externalref/externalref_test.go Tests external ref qualification in responses (issue-2113), verifying proper package import
internal/test/externalref/config.api.yaml API config with import-mapping for external common package references

Last reviewed commit: 5d69e3b

@mromaszewicz
Copy link
Member Author

This code review is quite immense. It might be easier to look at my source branch to see what the layout looks like.

I think it will be a lot easier to add test cases for specific things once this is merged.

@jamietanna
Copy link
Member

@mromaszewicz would you like this change in before any other PRs? What's your priority order for these to avoid conflcits/rebasing fun?

@mromaszewicz
Copy link
Member Author

I will use AI to rebase this, it shines there. I'd like to get this in just as a quality of life improvement. It exposed some issues we have with matrix and label parameters as-is (so tests are disabled for now).

mromaszewicz and others added 3 commits March 2, 2026 07:07
Replace the organically-grown test directory structure (issue-numbered
directories, flat parameter/component tests) with a feature-based taxonomy
that makes coverage visible at a glance.

New structure:
  components/{primitives,objects,nullable,recursive}
  aggregates/{allof,anyof,oneof}
  parameters/{path/{simple,label,matrix},query/{form,deep_object},
              header/simple,cookie/form,content,precedence,encoding}
  externalref/ (multi-package external $ref qualification)

Each directory contains a minimal OpenAPI spec exercising one feature,
a config.yaml, a doc.go with go:generate, committed generated code,
and round-trip tests that instantiate types and verify JSON marshaling.

Key changes:
- Absorb issue-specific directories into feature categories
- Delete old flat test directories (server/, strict-server/, client/,
  schemas/, cookies/, compatibility/, filter/, outputoptions/, etc.)
- Add comprehensive parameter permutation coverage across all
  location x style x explode x value-type combinations
- Fold issue-2113 (external ref in responses) into externalref/
- Add tools.go to keep oapi-codegen/v2 in go.mod for go:generate
  (previously kept alive implicitly by old test imports)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move header and cookie nil-check tests from issues/issue-2238/ into
the new category-based test structure:
- parameters/header/nilcheck/ (prefer-skip-optional-pointer header array)
- parameters/cookie/nilcheck/ (prefer-skip-optional-pointer cookie array)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mromaszewicz mromaszewicz force-pushed the chore/refactor-tests branch from 6368d27 to bcf95c1 Compare March 2, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants