Skip to content

Commit

Permalink
Improved handling of incomplete configs array
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed May 3, 2024
1 parent 8b8895c commit ce829e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/go-configmap/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func tryConversion(current any, desiredType reflect.Type) (any, error) {
}
case reflect.Array, reflect.Slice:
currentArray, ok := current.([]any)
if !ok {
if !ok && current != nil {
break
}
for i, elem := range currentArray {
Expand Down
8 changes: 8 additions & 0 deletions internal/integrationtest/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,4 +893,12 @@ build.unk: 123
out, _, err = cli.Run("config", "get", "locale", "--config-file", invalidConfig.String())
require.NoError(t, err)
require.Equal(t, "en", strings.TrimSpace(string(out)))

// Run "config get" with a configuration contatinng a null array
nullArrayConfig := paths.New(filepath.Join(tmp, "null_array.yaml"))
nullArrayConfig.WriteFile([]byte(`board_manager.additional_urls:`))
t.Cleanup(func() { nullArrayConfig.Remove() })
out, _, err = cli.Run("config", "get", "locale", "--config-file", invalidConfig.String())
require.NoError(t, err)
require.Equal(t, "en", strings.TrimSpace(string(out)))
}

0 comments on commit ce829e4

Please sign in to comment.