Skip to content

test: add unit tests for validate() and NewFromMap() functions#3086

Open
raphaeltorquat0 wants to merge 1 commit intozalando:masterfrom
raphaeltorquat0:fix/issue-416-config-util-tests
Open

test: add unit tests for validate() and NewFromMap() functions#3086
raphaeltorquat0 wants to merge 1 commit intozalando:masterfrom
raphaeltorquat0:fix/issue-416-config-util-tests

Conversation

@raphaeltorquat0
Copy link
Copy Markdown

Summary

Changes

  • TestValidate: Tests validation logic including:

    • Valid configuration passes validation
    • MinInstances > MaxInstances returns error
    • Workers = 0 returns error
    • ConnectionPooler.NumberOfInstances < minimum returns error
    • ConnectionPooler.User = SuperUsername returns error
    • MinInstances/MaxInstances both negative (disabled) passes validation
  • TestNewFromMap: Tests config creation from map including:

    • Empty map uses default values
    • Custom values override defaults
    • Duration parsing (e.g., "10s", "1m")
    • Boolean parsing
    • Map parsing (e.g., "key1:value1,key2:value2")
    • Slice parsing (e.g., "item1,item2,item3")
    • Invalid workers triggers validation panic
    • Invalid integer causes panic
  • TestMain: Sets OPERATOR_NAMESPACE environment variable to avoid log.Fatal when running tests outside a Kubernetes pod

Test plan

  • All unit tests pass locally (go test ./pkg/util/config/...)
  • Full test suite passes (go test ./...)

Disclosure: I used AI assistance (Claude) to help implement this change under my review and testing.

Closes #416

This addresses issue zalando#416 by adding comprehensive unit tests for the
config utility functions:

- TestValidate: Tests validation logic for MinInstances/MaxInstances,
  Workers count, ConnectionPooler instances, and user conflicts
- TestNewFromMap: Tests config creation from map with defaults,
  custom values, duration/boolean/map/slice parsing, and panic behavior
- TestMain: Sets OPERATOR_NAMESPACE env var for testing outside K8s

The tests cover both valid configurations and error cases.
@raphaeltorquat0
Copy link
Copy Markdown
Author

Hi @FxKu, could you please add the minor label so the CI checks can proceed? Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests to config util functions

1 participant