Skip to content

Added response schema stability tests#98

Open
Noah-Philip wants to merge 2 commits into
opencost:mainfrom
Noah-Philip:main
Open

Added response schema stability tests#98
Noah-Philip wants to merge 2 commits into
opencost:mainfrom
Noah-Philip:main

Conversation

@Noah-Philip

Copy link
Copy Markdown

Description

Adds response schema stability integration tests for the following OpenCost API endpoints:

  • /allocation
  • /assets
  • /cloudCost

The tests validate required public JSON fields, nested response structures, and important field types.

Implementation

  • Validates common response fields and successful response codes
  • Validates allocation item fields and nested windows
  • Validates common asset fields and stricter Node-specific fields
  • Validates CloudCost items, properties, windows, and nested cost objects
  • Allows additional fields so backward-compatible API extensions continue to pass
  • Skips item-level validation when an endpoint returns no items

Testing

Using demo cluster:

  • go test -count=1 ./test/integration/api/schema -v
  • bats test/integration/api/schema/test.bats

Signed-off-by: noah-philip <noahphilip06@outlook.com>
@Noah-Philip Noah-Philip requested a review from a team as a code owner June 15, 2026 14:38
Copilot AI review requested due to automatic review settings June 15, 2026 14:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR adds integration tests for API schema stability, verifying that the /allocation, /assets, and /cloudCost endpoints continue to return responses with the expected JSON structure, field names, and types.

Changes:

  • Adds schema stability integration tests for three API endpoints (allocation, assets, cloudCost) that validate response structure using raw JSON inspection.
  • Adds shared test helper functions (fetchRawEndpoint, requireFields, requireMap, etc.) for response validation.
  • Adds a BATS test runner file to execute the Go schema tests.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/integration/api/schema/test.bats BATS test definitions to run the three Go schema stability tests
test/integration/api/schema/helpers_test.go Shared helper functions for fetching endpoints and asserting JSON structure
test/integration/api/schema/allocation_test.go Schema stability test for the /allocation endpoint
test/integration/api/schema/assets_test.go Schema stability test for the /assets endpoint
test/integration/api/schema/cloudcost_test.go Schema stability test for the /cloudCost endpoint

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +22
func fetchRawEndpoint(t *testing.T, apiClient *api.API, path string, req api.AutocompleteRequest) map[string]any {
t.Helper()

status, body, err := apiClient.GetAutocompleteStatus(path, req)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There is no general QueryRequest or raw-response helper currently available. API.GET is generic but does not expose the HTTP status or raw body, both of which this schema test validates. I considered an alias, but it would only conceal that the existing raw-status helper requires AutocompleteRequest, while still exposing autocomplete-specific fields underneath. I kept the existing helper to avoid expanding this test PR into an API-package refactor.

Comment thread test/integration/api/schema/cloudcost_test.go
Signed-off-by: noah-philip <noahphilip06@outlook.com>
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.

2 participants