Skip to content

test: add comprehensive test suite + fix reserved keyword bugs in generated Jsonnet - #11

Merged
thisisibrahimd merged 8 commits into
mainfrom
test-swagger
Sep 1, 2026
Merged

thisisibrahimd merged 8 commits into
mainfrom
test-swagger

Conversation

@thisisibrahimd

Copy link
Copy Markdown
Owner

Summary

Fixes reserved keyword bugs in generated Jsonnet files and adds a comprehensive test suite covering the entire k8s generator pipeline with golden file validation.

Changes

Bug Fixes

  • super.function → super['function'] for 17 reserved keywords (function, self, import, etc.)
  • d.T.function → d.T['function'] in docsonnet type references
  • Nil pointer panic when $ref target is missing from swagger spec

Testing

  • 34 unit tests for pkg/swagger/ with fixture files
  • Integration test validating 685 generated .libsonnet files
  • Golden fixtures for k8s 1.35 swagger spec
  • Test suite skippable with go test -short
  • formatDebug() helper for debugging format failures

Refactoring

  • Centralized Jsonnet formatting in pkg/format/
  • Exported IsReservedKeyword() and SuperRef() from pkg/builder/
  • Full documentation for pkg/swagger/ exports
  • TESTING.md moved to repo root

Test Results

ok  pkg/builder          0.351s
ok  pkg/builder/docsonnet 0.505s
ok  pkg/integration      2.000s
ok  pkg/swagger          1.021s
(all 13 packages pass)

…emacompiler

Fix typo in pkg/complier/ directory name, subdirectory, package declarations,
import paths, Makefile, and AGENTS.md. All tests pass.
CRDs with fields named after Jsonnet keywords (function, self, local,
etc.) caused syntax errors like 'Expected token IDENTIFIER but got
"function"' because super.fieldName was emitted without quoting.

- Add builder.SuperRef(fieldName) — centralized super reference builder
  that uses bracket notation for reserved keywords and special characters
- Export builder.IsReservedKeyword for use across packages
- Remove duplicate superRef/superRefString from compiler and render
- Add 24 test cases covering all reserved keywords, special chars, and
  normal identifiers
d.T.function produced invalid Jsonnet when field type was "function".
Now uses d.T['function'] for reserved keywords.

Discovered by integration test validating all 685 generated .libsonnet
files against go-jsonnet parser.
SwaggerLoader.resolveRefs() crashed when a $ref pointed to a
non-existent definition. Added nil guard before accessing
resolved.Items.
Replaced scattered go-jsonnet/formatter imports across 5 files with
a single pkg/format/ package. Added formatDebug() test helper that
dumps raw output on format failure for debugging (test-only, not
exposed to users).
All 14 exported types, interfaces, and functions now have Go doc
comments: Loader, Load, CRDLoader, SwaggerLoader, Definitions,
Filter, Sub, Type, Schema, XGvk, Ref, GroupVersionKind.
34 tests across 4 files:
- swagger_test.go: SwaggerLoader (refs, skip list, caching, missing refs)
- crd_test.go: CRDLoader (single/multi CRD, nested props, arrays, metadata)
- definitions_test.go: Filter/Sub (regex, subset, empty)
- schema_test.go: Ref/GVK (all code paths, table-driven fuzz coverage)

Plus 4 test fixtures.
TestK8sSwagger_FullPipeline validates the entire generation pipeline:
cached swagger → model → render → golden compare 685 .libsonnet files.

- Table-driven for adding more k8s versions
- Skippable with go test -short
- Cached swagger spec (~4MB) in testdata
- 685 golden .libsonnet files

Also moves TESTING.md to repo root covering all packages (was
previously in pkg/builder/ only).
@thisisibrahimd thisisibrahimd self-assigned this Sep 1, 2026
@thisisibrahimd
thisisibrahimd merged commit aa346e1 into main Sep 1, 2026
2 checks passed
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.

1 participant