Skip to content

Added invalid parameter tests#108

Open
HardingEthan15 wants to merge 4 commits into
opencost:mainfrom
HardingEthan15:Invalid_Parameter_Tests
Open

Added invalid parameter tests#108
HardingEthan15 wants to merge 4 commits into
opencost:mainfrom
HardingEthan15:Invalid_Parameter_Tests

Conversation

@HardingEthan15

@HardingEthan15 HardingEthan15 commented Jun 17, 2026

Copy link
Copy Markdown

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

Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
Copilot AI review requested due to automatic review settings June 17, 2026 21:01
@HardingEthan15 HardingEthan15 requested a review from a team as a code owner June 17, 2026 21:01

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

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 decodeJSONResponse logic in api.go to detect HTTP 4xx/5xx status codes and return a formatted error immediately, avoiding JSON unmarshal of error bodies.
  • Added new invalid_query_parameter_test.go test files for both asset and allocation APIs, covering cases like reversed windows, invalid formats, and invalid filters/aggregates.
  • Updated both test.bats files 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.

Comment thread test/integration/api/asset/invalid_query_parameter_test.go Outdated
Comment thread test/integration/api/asset/invalid_query_parameter_test.go Outdated
Comment thread test/integration/api/allocation/invalid_query_parameter_test.go Outdated
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>
Copilot AI review requested due to automatic review settings June 17, 2026 21:16

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

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

Comment thread pkg/api/api.go Outdated
Comment thread test/integration/api/allocation/invalid_query_parameter_test.go Outdated
filter string
aggregate string
accumulate string
includeidle string
Comment thread test/integration/api/asset/invalid_query_parameter_test.go Outdated
Comment thread pkg/api/api.go Outdated
Signed-off-by: HardingEthan15 <Ethan.Harding@ibm.com>

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

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

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