Skip to content

Commit

Permalink
test: upgrade ut of package config to make it more self-contained and…
Browse files Browse the repository at this point in the history
… exact (#896)
  • Loading branch information
healthjyk committed Mar 8, 2024
1 parent 9f6d73d commit cf24848
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 209 deletions.
8 changes: 3 additions & 5 deletions pkg/config/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
ErrEmptyConfigItem = errors.New("empty config item")
ErrConflictConfigItemType = errors.New("type of the config item conflicts between saved and registered")
ErrEmptyConfigItemKey = errors.New("empty config item key")
ErrEmptyConfigItemValue = errors.New("empty config item value")
ErrUnsupportedConfigItem = errors.New("unsupported config item")
ErrEmptyBackendName = errors.New("backend name should not be empty")
ErrInvalidBackendName = errors.New("backend name should not be current")
Expand Down Expand Up @@ -246,9 +247,6 @@ func getConfigItemWithLaxType(config *v1.Config, key string) (any, error) {
// the updated config.
// ATTENTION! Cause the input config could be nil, change it or its value may both could result in assignment failure.
func setItemInConfig(config *v1.Config, info *itemInfo, key string, value any) (*v1.Config, error) {
if err := validateConfig(config); err != nil {
return nil, err
}
if err := validateConfigItem(config, info, key, value); err != nil {
return nil, err
}
Expand Down Expand Up @@ -299,7 +297,7 @@ func tidyConfig(configAddr **v1.Config) {
// validateConfigItem checks the config item value is valid or not.
func validateConfigItem(config *v1.Config, info *itemInfo, key string, value any) error {
if reflect.ValueOf(value).IsZero() {
return ErrEmptyConfigItem
return ErrEmptyConfigItemValue
}
if info.validateFunc != nil {
return info.validateFunc(config, key, value)
Expand All @@ -311,7 +309,7 @@ func validateConfigItem(config *v1.Config, info *itemInfo, key string, value any
// its validation.
func parseStructuredConfigItem(info *itemInfo, strValue string) (any, error) {
if len(strValue) == 0 {
return nil, ErrEmptyConfigItem
return nil, ErrEmptyConfigItemValue
}

value := info.zeroValue
Expand Down
Loading

0 comments on commit cf24848

Please sign in to comment.