Skip to content

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

Merged
merged 2 commits into from
Jun 29, 2025

Conversation

nsega
Copy link
Contributor

@nsega nsega commented Jun 24, 2025

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:

  • Add comprehensive tests for Error.Error() method
  • Add tests for CanonicalCode() function with edge cases
  • Test all error code constants
  • Cover 100% test coverage for pkg/epp/util/error

Testing:

  • All new tests pass
  • Existing tests continue to pass
  • 100% test coverage achieved for the package

@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jun 24, 2025
Copy link

netlify bot commented Jun 24, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 35d2f23
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/685f5c7005edf30008968591
😎 Deploy Preview https://deploy-preview-1052--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 24, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @nsega!

It looks like this is your first PR to kubernetes-sigs/gateway-api-inference-extension 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/gateway-api-inference-extension has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 24, 2025
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 24, 2025
@kfswain
Copy link
Collaborator

kfswain commented Jun 24, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 24, 2025
@kfswain
Copy link
Collaborator

kfswain commented Jun 24, 2025

Looks great! Thanks! Will approve once CI finishes (assuming it all passes)

@nsega
Copy link
Contributor Author

nsega commented Jun 25, 2025

/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>
@nsega nsega force-pushed the add-error-util-tests branch from a90af55 to fce8bf8 Compare June 25, 2025 01:55
@nsega
Copy link
Contributor Author

nsega commented Jun 25, 2025

@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?

Comment on lines 204 to 220
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",
}
Copy link
Contributor

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"
)

Copy link
Contributor Author

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.

Copy link
Contributor

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?

const (
Unknown = "Unknown"
BadRequest = "BadRequest"
Internal = "Internal"
ModelServerError = "ModelServerError"
BadConfiguration = "BadConfiguration"
InferencePoolResourceExhausted = "InferencePoolResourceExhausted"
)

Copy link
Contributor Author

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?

Copy link
Contributor

@nirrozenbaum nirrozenbaum Jun 29, 2025

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).

Copy link
Contributor Author

@nsega nsega Jun 29, 2025

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.

Copy link
Contributor

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 :)

Copy link
Contributor Author

@nsega nsega left a 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?

Comment on lines 204 to 220
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",
}
Copy link
Contributor Author

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.

@nsega nsega requested a review from danehans June 28, 2025 03:08
@nirrozenbaum
Copy link
Contributor

/lgtm
/approve

Congrats @nsega on your first inference gateway PR!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 29, 2025
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 29, 2025
@k8s-ci-robot k8s-ci-robot merged commit 84f387e into kubernetes-sigs:main Jun 29, 2025
8 of 9 checks passed
@nsega
Copy link
Contributor Author

nsega commented Jun 29, 2025

@nirrozenbaum Thank you very much for your kind review! I was excited to contribute to inference gateway for the first time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants