Added response schema stability tests#98
Conversation
Signed-off-by: noah-philip <noahphilip06@outlook.com>
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
Signed-off-by: noah-philip <noahphilip06@outlook.com>
Description
Adds response schema stability integration tests for the following OpenCost API endpoints:
/allocation/assets/cloudCostThe tests validate required public JSON fields, nested response structures, and important field types.
Implementation
Testing
Using demo cluster:
go test -count=1 ./test/integration/api/schema -vbats test/integration/api/schema/test.bats