Added invalid parameter tests#108
Open
HardingEthan15 wants to merge 4 commits into
Open
Conversation
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds integration tests that validate the OpenCost allocation and asset APIs return HTTP 400 errors (rather than 500 errors or successful responses) when invalid query parameters are provided. It also updates pkg/api/api.go to properly short-circuit HTTP error responses (4xx/5xx) before attempting JSON deserialization.
Changes:
- Added
decodeJSONResponselogic inapi.goto detect HTTP 4xx/5xx status codes and return a formatted error immediately, avoiding JSON unmarshal of error bodies. - Added new
invalid_query_parameter_test.gotest files for both asset and allocation APIs, covering cases like reversed windows, invalid formats, and invalid filters/aggregates. - Updated both
test.batsfiles to include the new test invocations.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
pkg/api/api.go |
Adds early-return error handling for HTTP 4xx/5xx responses in decodeJSONResponse |
test/integration/api/allocation/invalid_query_parameter_test.go |
New test validating allocation API returns 400 for invalid parameters |
test/integration/api/asset/invalid_query_parameter_test.go |
New test validating asset API returns 400 for invalid parameters |
test/integration/api/allocation/test.bats |
Registers the new allocation invalid parameter test |
test/integration/api/asset/test.bats |
Registers the new asset invalid parameter test |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
| filter string | ||
| aggregate string | ||
| accumulate string | ||
| includeidle string |
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
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.
DESCRIPTION
Adds invalid parameter tests for the asset and allocation api. This test validates that the apis handle invalid parameters correctly.
CHANGES
Adds a new invalid_query_parameter_test.go in the allocation and asset folder.
Adds to the test.bats file to run the tests.
MOTIVATION
Invalid Parameters should not return 500 errors or panics. Furthermore, they should not return successful responses, since the responses would then have to guess what is meant by the parameters.
TESTING
This test can be run from the new sanity test directory using the included Bats test file.
Signed-off-by: HardingEthan15 Ethan.Harding@ibm.com