Skip to content

[test] Add tests for config.validateAgainstCustomSchema#1334

Merged
lpcox merged 1 commit intomainfrom
test-coverage-validate-custom-schema-51e3214b948e2313
Feb 24, 2026
Merged

[test] Add tests for config.validateAgainstCustomSchema#1334
lpcox merged 1 commit intomainfrom
test-coverage-validate-custom-schema-51e3214b948e2313

Conversation

@github-actions
Copy link
Contributor

Test Coverage Improvement: validateAgainstCustomSchema and validateCustomServerConfig

Function Analyzed

  • Package: internal/config
  • Functions: validateAgainstCustomSchema, validateCustomServerConfig
  • File: internal/config/validation.go
  • Complexity: High — 9+ branches, schema fetching, JSON parsing, compiler setup, AdditionalProperties merging, type assertion fallbacks

Why This Function?

validateAgainstCustomSchema (lines 202–314 in validation.go) is a complex function with multiple independent error paths, several of which had zero test coverage before this PR:

  1. HTTP fetch failure — schema server returns non-200 status
  2. Connection failure — schema URL is unreachable
  3. Schema $id different from fetch URL — triggers the schemaID != schemaURL branch that registers the schema under both URLs before compilation
  4. AdditionalProperties merging — custom fields stored in server.AdditionalProperties must be merged into the validation map

validateCustomServerConfig (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 sets schemaURL = "" and skips validation

Tests Added

New file: internal/config/validate_against_custom_schema_test.go

Test Branch covered
TestValidateAgainstCustomSchema_FetchFailure fetchAndFixSchema error — HTTP 500
TestValidateAgainstCustomSchema_UnreachableURL fetchAndFixSchema error — connection refused
TestValidateAgainstCustomSchema_SchemaWithDifferentID schemaID != schemaURL happy path
TestValidateAgainstCustomSchema_SchemaWithDifferentID_MissingRequired schemaID != schemaURL + validation failure
TestValidateAgainstCustomSchema_AdditionalPropertiesMerged AdditionalProperties loop (lines 297–299)
TestValidateAgainstCustomSchema_AdditionalPropertiesMissingRequired AdditionalProperties missing required field
TestValidateCustomServerConfig_NonStringSchemaValue schemaValue.(string) type assertion fallback (4 sub-cases)
TestValidateCustomServerConfig_NilCustomSchemas customSchemas == nil path directly
TestValidateCustomServerConfig_UnregisteredType !exists path directly

Test Execution

Tests are structured as table-driven and sub-tests using httptest.NewServer mock servers (matching the pattern in custom_types_test.go) and use require/assert from testify.


Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

AI generated by Test Coverage Improver

…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>
@lpcox lpcox marked this pull request as ready for review February 24, 2026 04:20
Copilot AI review requested due to automatic review settings February 24, 2026 04:20
@lpcox lpcox merged commit 41a7a9b into main Feb 24, 2026
4 checks passed
@lpcox lpcox deleted the test-coverage-validate-custom-schema-51e3214b948e2313 branch February 24, 2026 04:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants