Skip to content

chore: refactor all tests by category - #2260

Merged
mromaszewicz merged 5 commits into
oapi-codegen:mainfrom
mromaszewicz:chore/refactor-tests
Jul 7, 2026
Merged

mromaszewicz merged 5 commits into
oapi-codegen:mainfrom
mromaszewicz:chore/refactor-tests

Conversation

@mromaszewicz

@mromaszewicz mromaszewicz commented Feb 27, 2026

Copy link
Copy Markdown
Member

Replace the organically grown layout — 56 issues/issue-NNNN directories
plus a few kitchen-sink specs — with 13 feature categories (schemas,
aggregates, parameters, bodies, servers, clients, events, references,
extensions, options, naming, openapi31, spec_validation).

Each scenario is now a focused spec/config/test unit under its category,
named for what it tests rather than an issue number, with issue context
kept as "From issue-NNNN" comments in the absorbing spec. Cross-framework
suites (parameters/roundtrip, servers/strict, events/webhooks,
servers/routers/smoke) share one spec and one table-driven harness per
concern; only the per-framework server/types generation remains
duplicated, since generated servers cannot share packages.

Coverage was audited directory-by-directory against the old tree: nothing
was dropped, and three previously lost areas were restored (hand-crafted
wire-format parameter binding, operationId name-normalization,
nil-vs-empty query array serialization). Greptile review rules now
enforce the category placement so issue directories don't return.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Co-Authored-By: Claude Fable 5 noreply@anthropic.com

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

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member Author

@greptileai

@greptile-apps

greptile-apps Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
mromaszewicz force-pushed the chore/refactor-tests branch from 6368d27 to bcf95c1 Compare March 2, 2026 15:12
@jamietanna

jamietanna commented Apr 29, 2026

Copy link
Copy Markdown
Member

A couple of things:

  • This looks good, and a lot neater!
  • Something I've considered for a while is it'd be nice to have a utility script to run that'll bootstrap one of these issuesXXXX directories with everything you need - maybe not as needed now, but may still be worthwhile?
  • I'd quite like to make sure we keep a reference to issue numbers where there are tests that have come in via one - it helps us track down "real-world" behaviour and whether there's any additional context that can be gleamed. Can be a comment in the package's documentation string or i.e. inline in the pieces of spec that are for a given issue
  • In the squashing down of files, are we confident in the coverage of everything we used to have? (I.e. we're no longer testing server generation)

Otherwise LGTM, let's get this quality-of-life improvement in!

@mromaszewicz

Copy link
Copy Markdown
Member Author

A lot of work has happened since this commit, I will rebase it and re-do it once 2.8.0 is out. It'll be a lot of work.

@mromaszewicz mromaszewicz added this to the v2.8.0 milestone Apr 30, 2026
@mromaszewicz

Copy link
Copy Markdown
Member Author

I'm revisiting this. The code has drifted hugely, so I'm basically re-doing it, and doing it a little more cleanly this time.

We won't be needing the per-issue test dirs. I really hope to avoid them, and the new top level categories should cover more bases. It's easier to add some edge case to an existing spec than to make a whole new test dir. Most of that code is wasted boilerplate.

@mromaszewicz
mromaszewicz force-pushed the chore/refactor-tests branch from bcf95c1 to 4ebe69e Compare June 23, 2026 01:41
@mromaszewicz

Copy link
Copy Markdown
Member Author

@greptileai - review.

@greptile-apps

greptile-apps Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review. (833 files found, 500 file limit)

@mromaszewicz
mromaszewicz force-pushed the chore/refactor-tests branch from 4ebe69e to 21ec07d Compare June 23, 2026 04:43
mromaszewicz and others added 5 commits July 6, 2026 19:55
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Reorganize internal/test into feature categories (schemas, aggregates,
parameters, bodies, servers, clients, events, references, extensions,
options, naming, openapi31). Previously the tests sprawled across 56
issues/issue-NNNN directories and a couple of kitchen-sink specs, plus
~24 nearly identical per-framework directories that regenerated large
amounts of near-duplicate boilerplate.

Each test is now a focused unit under its category, sharing a single
spec / client / table-driven harness per concern instead of duplicating
generated code for every framework. The old issues/, per-framework, and
kitchen-sink directories are removed; the category layout is the only
test structure.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Bring the test refactor up to date with HEAD, and fold in new
test issues into the unified test framework.
Update comments to reflect original source tests in each merged
spec, and consolidate some more, where possible.
Tell Greptile about the new test organization, so it helps people
place tests correctly in the future.
@mromaszewicz
mromaszewicz force-pushed the chore/refactor-tests branch from 21ec07d to 56fa375 Compare July 7, 2026 04:08
@mromaszewicz
mromaszewicz merged commit ae4f369 into oapi-codegen:main Jul 7, 2026
14 checks passed
@mromaszewicz mromaszewicz added the chore Any maintenance tasks that are regular, not as important to call out in the changelog label Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Any maintenance tasks that are regular, not as important to call out in the changelog internal size:xl/xxl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants