[Refactor] Simplify UnmarshalJSON with Dedicated Handlers
This PR refactors the UnmarshalJSON method for ReplicatedDevices to improve code clarity and structure. Key changes include:
-
Modularization: Created separate handlers (
handleStringInput,handleNumericInput,handleListInput) for different input types, enhancing readability and simplifying future maintenance. -
Robust Error Handling: Enhanced the error handling in
handleListInputto allow processing of list elements independently. -
Code Refactoring: Eliminated redundancy by centralizing error checking logic.
-
Generics Readiness: Prepared
handleNumericInputfor future adaptation to Go's generics (once available).
@klueska PTAL
Upon reviewing, I identified a bug in the previous submission that resulted in the failure of two existing unit test functions. To address this, I've removed the switch statement, which was causing the issue.
Here are the current unit test results:
(base) ➜ v1 git:(main) ✗ go test ./...
ok github.com/NVIDIA/k8s-device-plugin/api/config/v1 0.634s
Ping @klueska
Ping @elezar
This PR is stale because it has been open 90 days with no activity. This PR will be closed in 30 days unless new comments are made or the stale label is removed.