[test] Add tests for config.validateAgainstCustomSchema#1334
Merged
Conversation
…rverConfig Cover previously untested branches: - fetchAndFixSchema error path (HTTP 500 from schema server) - fetchAndFixSchema connection error path (unreachable URL) - Schema with $id different from fetch URL (happy path and validation failure) - AdditionalProperties merged into validation map before schema validation - Non-string schema value in customSchemas (type assertion fallback to empty URL) - Nil customSchemas and unregistered type (direct validateCustomServerConfig tests) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive unit tests for two previously under-tested functions in the internal/config package: validateAgainstCustomSchema and validateCustomServerConfig. These functions handle custom server type validation against JSON schemas, with complex error paths and edge cases that were not fully exercised by the existing compliance tests (T-CFG-010 through T-CFG-014).
Changes:
- Added 9 new test cases covering HTTP fetch failures, unreachable URLs, schema $id handling, AdditionalProperties merging, and non-string schema value handling
- Tests use httptest mock servers and table-driven patterns consistent with existing test conventions
- All tests follow established patterns using testify/assert and testify/require
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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:
validateAgainstCustomSchemaandvalidateCustomServerConfigFunction Analyzed
internal/configvalidateAgainstCustomSchema,validateCustomServerConfiginternal/config/validation.goWhy This Function?
validateAgainstCustomSchema(lines 202–314 invalidation.go) is a complex function with multiple independent error paths, several of which had zero test coverage before this PR:$iddifferent from fetch URL — triggers theschemaID != schemaURLbranch that registers the schema under both URLs before compilationserver.AdditionalPropertiesmust be merged into the validation mapvalidateCustomServerConfig(lines 167–199) also had an untested branch:5. Non-string schema value — when
customSchemas[type]holds a non-string (e.g.,int,bool,map), the type assertion fallback silently setsschemaURL = ""and skips validationTests Added
New file:
internal/config/validate_against_custom_schema_test.goTestValidateAgainstCustomSchema_FetchFailurefetchAndFixSchemaerror — HTTP 500TestValidateAgainstCustomSchema_UnreachableURLfetchAndFixSchemaerror — connection refusedTestValidateAgainstCustomSchema_SchemaWithDifferentIDschemaID != schemaURLhappy pathTestValidateAgainstCustomSchema_SchemaWithDifferentID_MissingRequiredschemaID != schemaURL+ validation failureTestValidateAgainstCustomSchema_AdditionalPropertiesMergedTestValidateAgainstCustomSchema_AdditionalPropertiesMissingRequiredTestValidateCustomServerConfig_NonStringSchemaValueschemaValue.(string)type assertion fallback (4 sub-cases)TestValidateCustomServerConfig_NilCustomSchemascustomSchemas == nilpath directlyTestValidateCustomServerConfig_UnregisteredType!existspath directlyTest Execution
Tests are structured as table-driven and sub-tests using
httptest.NewServermock servers (matching the pattern incustom_types_test.go) and userequire/assertfromtestify.Generated by Test Coverage Improver
Next run will target the next most complex under-tested function