Skip to content

test: add Unit Test Coverage for Reflect Util - #1026

Open
kartikangiras wants to merge 2 commits into
goharbor:mainfrom
kartikangiras:test/reflectutil
Open

test: add Unit Test Coverage for Reflect Util#1026
kartikangiras wants to merge 2 commits into
goharbor:mainfrom
kartikangiras:test/reflectutil

Conversation

@kartikangiras

Copy link
Copy Markdown

Description

Add unit test coverage for pkg/utils/reflect.go (ExtractConfigValues, ConvertToConfigurations, ExtractConfigurationsByCategory, IsCategory).

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • pkg/utils/reflect_test.go: 8 tests for config extraction, conversion, category filtering, and nil safety

@qcserestipy qcserestipy added the status/in-progress Work on this issue has started or a linked pull request is actively being developed. label Jun 30, 2026

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 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 ExtractConfigValues across Configurations and ConfigurationsResponse, including nil/empty-string handling.
  • Add unit tests for ConvertToConfigurations, ExtractConfigurationsByCategory, and IsCategory.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/utils/reflect_test.go
Comment thread pkg/utils/reflect_test.go
Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
Signed-off-by: Kartik Angiras <angiraskartik@gmail.com>
@kartikangiras

Copy link
Copy Markdown
Author

Hey @qcserestipy , I have made changes and resolved the review remarks. Could you PTAL.

@qcserestipy qcserestipy added Changes Requesed feedback that must be addressed before merging. and removed Changes Requesed feedback that must be addressed before merging. labels Jul 20, 2026

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Secret-field encryption path is untested. The secret branch in convertAndSetField (driven by isSecretConfigurationFieldencrypt) is the most complex code in reflect.go and currently has zero coverage. Please add a ConvertToConfigurations / ExtractConfigurationsByCategory case that passes one of OIDCClientSecret, UaaClientSecret, or LdapSearchPassword so the encryption branch (and its error handling) is exercised.

  2. ExtractConfigValues generic fallback untested. The tests cover *StringConfigItem / *BoolConfigItem / *IntegerConfigItem, but the default: reflection branch (generic non-nil pointer) and the *string case never run. Add a case that hits the fallback.

  3. Nil handling is inconsistent — decide, don't just pin it. TestConvertToConfigurations_NilPanics locks in a panic on nil, while ExtractConfigurationsByCategory(nil, ...) guards nil and returns &models.Configurations{}. Prefer making ConvertToConfigurations nil-safe as well (early return on resp == 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/in-progress Work on this issue has started or a linked pull request is actively being developed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature]: Add Unit Test coverage for Utils

3 participants