Repository navigation
test: add comprehensive test suite + fix reserved keyword bugs in generated Jsonnet - #11
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Testing
go test -shortformatDebug()helper for debugging format failuresRefactoring
pkg/format/IsReservedKeyword()andSuperRef()from pkg/builder/Test Results