-
Notifications
You must be signed in to change notification settings - Fork 108
test(epp): add unit tests for error package #1052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(epp): add unit tests for error package #1052
Conversation
✅ Deploy Preview for gateway-api-inference-extension ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Welcome @nsega! |
Hi @nsega. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
/ok-to-test |
Looks great! Thanks! Will approve once CI finishes (assuming it all passes) |
/retest |
- Add comprehensive tests for Error.Error() method - Add tests for CanonicalCode() function with edge cases - Test all error code constants - Achieve 100% test coverage for pkg/epp/util/error Signed-off-by: Naoki Sega <nsegaster@gmail.com>
a90af55
to
fce8bf8
Compare
@kfswain Thank you for your review! I just addressed the CI Test failure, which was the Boilerplate header of the target test code was wrong ref Just in case, I verified locally using hack/verify-boilerplate.sh as well after adding the correct boilerplate header with the exact format used by the project. Since all CI passes successfully, can you please approve this at your convenience? |
pkg/epp/util/error/error_test.go
Outdated
constants := map[string]string{ | ||
"Unknown": Unknown, | ||
"BadRequest": BadRequest, | ||
"Internal": Internal, | ||
"ModelServerError": ModelServerError, | ||
"BadConfiguration": BadConfiguration, | ||
"InferencePoolResourceExhausted": InferencePoolResourceExhausted, | ||
} | ||
|
||
expectedValues := map[string]string{ | ||
"Unknown": "Unknown", | ||
"BadRequest": "BadRequest", | ||
"Internal": "Internal", | ||
"ModelServerError": "ModelServerError", | ||
"BadConfiguration": "BadConfiguration", | ||
"InferencePoolResourceExhausted": "InferencePoolResourceExhausted", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the consts as map keys:
const (
Unknown = "Unknown"
BadRequest = "BadRequest"
Internal = "Internal"
ModelServerError = "ModelServerError"
BadConfiguration = "BadConfiguration"
InferencePoolResourceExhausted = "InferencePoolResourceExhausted"
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to me. Since the constants and expected values I defined seem redundant, I updated the test case by simplifying it to define only one map as a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these constants already defined in error.go. why not use reference them? why do we need to define them again?
gateway-api-inference-extension/pkg/epp/util/error/error.go
Lines 29 to 36 in 9c9abd5
const ( | |
Unknown = "Unknown" | |
BadRequest = "BadRequest" | |
Internal = "Internal" | |
ModelServerError = "ModelServerError" | |
BadConfiguration = "BadConfiguration" | |
InferencePoolResourceExhausted = "InferencePoolResourceExhausted" | |
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nirrozenbaum Based on danehans's feedback the other day, I updated the test to check the error message using the constant. 35d2f23 How does it sound to you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was commenting on the previous comment, sorry.
I think overall the code looks great, just not sure why unit-tests for constants are needed :)
Constants are compile-time values, there's no logic or behavior to test here — it's static data.
Unit tests are meant to test behavior and logic, not to assert that literals haven't changed (unless those values are dynamically generated or critical public APIs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nirrozenbaum No worries. I agree with your point. In general, we don't need to write unit tests for constants like you said. However, I do think that testing the literal values of exported constants is a valid and important test when those constants are part of the public API, potentially used by external systems, or part of error messages that might be parsed. This is the reason why I added the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's also fine to keep them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danehans Thank you for your feedback! I addressed it. Can you please take a look at it again?
pkg/epp/util/error/error_test.go
Outdated
constants := map[string]string{ | ||
"Unknown": Unknown, | ||
"BadRequest": BadRequest, | ||
"Internal": Internal, | ||
"ModelServerError": ModelServerError, | ||
"BadConfiguration": BadConfiguration, | ||
"InferencePoolResourceExhausted": InferencePoolResourceExhausted, | ||
} | ||
|
||
expectedValues := map[string]string{ | ||
"Unknown": "Unknown", | ||
"BadRequest": "BadRequest", | ||
"Internal": "Internal", | ||
"ModelServerError": "ModelServerError", | ||
"BadConfiguration": "BadConfiguration", | ||
"InferencePoolResourceExhausted": "InferencePoolResourceExhausted", | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to me. Since the constants and expected values I defined seem redundant, I updated the test case by simplifying it to define only one map as a test.
/lgtm Congrats @nsega on your first inference gateway PR! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nirrozenbaum, nsega The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@nirrozenbaum Thank you very much for your kind review! I was excited to contribute to inference gateway for the first time. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR adds comprehensive unit tests for the
pkg/epp/util/error
package, which previously had no test coverage.Changes:
Testing: