[test] Add tests for config.validateServerAgainstSchema#7798
Merged
lpcox merged 1 commit intoJun 19, 2026
Merged
Conversation
Add comprehensive table-driven tests for the validateServerAgainstSchema function in internal/config/validation.go, which had 0% test coverage. The function validates a StdinServerConfig against a compiled JSON schema and merges AdditionalProperties into the validation map. New tests cover: - Happy path: conforming server passes validation - Schema validation failure: missing required field returns SchemaValidationError - AdditionalProperties merged and satisfy schema requirements - AdditionalProperties causing schema validation failure (additionalProperties:false) - Nil AdditionalProperties handled safely (merge loop skipped) - Empty AdditionalProperties handled safely - Multiple AdditionalProperties all merged and satisfy schema - Type mismatch in AdditionalProperties triggers validation error Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves unit test coverage for the internal/config package by directly exercising the private helper validateServerAgainstSchema, which is only invoked in production when custom schema URLs are configured. The new tests validate correct behavior around schema validation and the merge semantics for StdinServerConfig.AdditionalProperties.
Changes:
- Add a
compileSchemaForTesthelper to compile inline Draft-7 JSON schemas using the package’snewDraft7Compiler()without network access. - Add happy-path and failure-path tests for
validateServerAgainstSchema(including required-field failures and type mismatches). - Add coverage for
AdditionalPropertiesmerge behavior (nil/empty/multiple keys and schema rejection viaadditionalProperties: false).
Show a summary per file
| File | Description |
|---|---|
| internal/config/validate_server_against_schema_test.go | Adds focused unit tests covering validateServerAgainstSchema behavior, especially AdditionalProperties merge semantics and schema pass/fail scenarios. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
This was referenced Jun 20, 2026
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.
Test Coverage Improvement:
validateServerAgainstSchemaFunction Analyzed
internal/configvalidateServerAgainstSchemainternal/config/validation.goAdditionalProperties, schema pass/fail)Why This Function?
validateServerAgainstSchemais a private helper called only when acustomSchemasURL is configured. All existing unit tests either passnilschemas or fail earlier in the compile step insidevalidateAgainstCustomSchema, so this function's logic was never exercised. Its branching aroundAdditionalPropertiesmerging and JSON schema validation makes it a meaningful coverage gap.Tests Added
SchemaValidationErrorwith correct JSON pathAdditionalPropertiesmerged and satisfy schema — custom fields inAdditionalPropertiesare merged into the validation map and fulfill schema requirementsAdditionalPropertiescause validation failure — extra fields violate anadditionalProperties: falseschemaAdditionalProperties— merge loop is skipped safely, no panicAdditionalPropertiesmap — same safe no-op behaviourAdditionalProperties— all keys merged; schema requiring several custom fields is satisfiedAdditionalProperties— wrong type triggers a schema validation errorImplementation Notes
Tests use a
compileSchemaForTesthelper (same file,package config) that calls the package-internalnewDraft7Compiler()to compile inline JSON schemas without any network access. This matches the same compiler used in production, ensuring the tests reflect real behaviour.Test Execution
Tests cannot run locally due to
golang.org/x/termbeing blocked by the network firewall in this environment. The file is syntactically valid (confirmed viagofmt -e) and follows the same import/package patterns as all other*_test.gofiles ininternal/config. CI will compile and run the tests normally.Generated by Test Coverage Improver
Warning
Firewall blocked 7 domains
The following domains were blocked by the firewall during workflow execution:
go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.ingoproxy.ioproxy.golang.orgSee Network Configuration for more information.