Skip to content

Commit

Permalink
tests fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
axenteoctavian committed Jan 22, 2024
1 parent 74037f1 commit 1e152b8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
18 changes: 6 additions & 12 deletions common/reflectcommon/structFieldsUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,9 @@ func isIntegerType(value reflect.Type) bool {
}

func fitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool {
min, err := getMinInt(targetType)
if err != nil {
return false
}
max, err := getMaxInt(targetType)
if err != nil {
min, errMin := getMinInt(targetType)
max, errMax := getMaxInt(targetType)
if errMin != nil || errMax != nil {
return false
}

Expand Down Expand Up @@ -300,12 +297,9 @@ func isFloatType(value reflect.Type) bool {
}

func fitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool {
min, err := getMinFloat(targetType)
if err != nil {
return false
}
max, err := getMaxFloat(targetType)
if err != nil {
min, errMin := getMinFloat(targetType)
max, errMax := getMaxFloat(targetType)
if errMin != nil || errMax != nil {
return false
}

Expand Down
19 changes: 17 additions & 2 deletions common/reflectcommon/structFieldsUpdate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,9 +647,24 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) {

path := "TestConfigI32.Int32.Value"

err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[8].Value)
err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value)
require.NoError(t, err)
require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Int32.Value))
})

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

testConfig, err := loadTestConfig("../../testscommon/toml/config.toml")
require.NoError(t, err)

expectedNewValue := uint16(10)

path := "TestConfigI32.Int32.Value"

err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue)
require.NoError(t, err)
require.Equal(t, overrideConfig.OverridableConfigTomlValues[8].Value, int64(testConfig.Int32.Value))
require.Equal(t, int32(expectedNewValue), testConfig.Int32.Value)
})

t.Run("should error int32 value", func(t *testing.T) {
Expand Down

0 comments on commit 1e152b8

Please sign in to comment.