Skip to content

Commit

Permalink
Merge pull request #5710 from multiversx/overridable-configs-fix
Browse files Browse the repository at this point in the history
overridable configs fix
  • Loading branch information
gabi-vuls authored Nov 17, 2023
2 parents cd89ae9 + b6b59e2 commit 28dfbe4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/reflectcommon/structFieldsUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ func trySetTheNewValue(value *reflect.Value, newValue string) error {
}

value.Set(reflect.ValueOf(int(intVal)))
case reflect.Int32:
int32Val, err := strconv.ParseInt(newValue, 10, 32)
if err != nil {
return fmt.Errorf("%w: %s", errFunc(), err.Error())
}

value.Set(reflect.ValueOf(int32(int32Val)))
case reflect.Int64:
int64Val, err := strconv.ParseInt(newValue, 10, 64)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions common/reflectcommon/structFieldsUpdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) {
require.Equal(t, expectedNewValue, cfg.StoragePruning.FullArchiveNumActivePersisters)
})

t.Run("should work and override int32 value", func(t *testing.T) {
t.Parallel()

path := "Antiflood.NumConcurrentResolverJobs"
cfg := &config.Config{}
cfg.Antiflood.NumConcurrentResolverJobs = int32(50)
expectedNewValue := int32(37)

err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue))
require.NoError(t, err)

require.Equal(t, expectedNewValue, cfg.Antiflood.NumConcurrentResolverJobs)
})

t.Run("should work and override string value on multiple levels depth", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 28dfbe4

Please sign in to comment.