test: add Unit Test Coverage for Reflect Util - #1026
Conversation
db2e4a2 to
47f39c1
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds unit tests for the reflection-based configuration utilities in pkg/utils/reflect.go, improving confidence in config extraction/conversion and category filtering logic used by the CLI.
Changes:
- Add unit tests for
ExtractConfigValuesacrossConfigurationsandConfigurationsResponse, including nil/empty-string handling. - Add unit tests for
ConvertToConfigurations,ExtractConfigurationsByCategory, andIsCategory.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
1a54c3e to
73bee7e
Compare
|
Hey @qcserestipy , I have made changes and resolved the review remarks. Could you PTAL. |
qcserestipy
left a comment
There was a problem hiding this comment.
Solid coverage of the main extraction and conversion paths, and good to see both inclusion and exclusion asserted in the category filter test. A few gaps are worth closing before this lands, since they cover the riskiest logic:
-
Secret-field encryption path is untested. The
secretbranch inconvertAndSetField(driven byisSecretConfigurationField→encrypt) is the most complex code inreflect.goand currently has zero coverage. Please add aConvertToConfigurations/ExtractConfigurationsByCategorycase that passes one ofOIDCClientSecret,UaaClientSecret, orLdapSearchPasswordso the encryption branch (and its error handling) is exercised. -
ExtractConfigValuesgeneric fallback untested. The tests cover*StringConfigItem/*BoolConfigItem/*IntegerConfigItem, but thedefault:reflection branch (generic non-nil pointer) and the*stringcase never run. Add a case that hits the fallback. -
Nil handling is inconsistent — decide, don't just pin it.
TestConvertToConfigurations_NilPanicslocks in a panic onnil, whileExtractConfigurationsByCategory(nil, ...)guards nil and returns&models.Configurations{}. Prefer makingConvertToConfigurationsnil-safe as well (early return onresp == nil), then assert the graceful return instead of a panic, so the two functions behave consistently.
Minor: since both this PR (reflect) and #1027 (query) say "Fixes #1025", only one should carry the "Fixes" keyword so the issue isn't auto-closed before both land.
Description
Add unit test coverage for pkg/utils/reflect.go (ExtractConfigValues, ConvertToConfigurations, ExtractConfigurationsByCategory, IsCategory).
Type of Change
Please select the relevant type.
Changes