Skip to content

Commit f102fab

Browse files
authored
FIX: used float64 instead of int (#884)
* used float64 instead of int * fixed test cases * added comment
1 parent 99978c1 commit f102fab

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

util/ValidatorHelper.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ func AutoScale(dat map[string]interface{}) (bool, error) {
248248
if !okMin || !okMax{
249249
return false, errors.New("autoscaling.MinReplicas and autoscaling.MaxReplicas are mandatory fields")
250250
}
251-
if minReplicas.(int) > maxReplicas.(int){
251+
// see https://pkg.go.dev/encoding/json#Unmarshal for why conversion to float64 and not int
252+
// Bug fix PR https://github.com/devtron-labs/devtron/pull/884
253+
if minReplicas.(float64) > maxReplicas.(float64){
252254
return false, errors.New("autoscaling.MinReplicas can not be greater than autoscaling.MaxReplicas")
253255
}
254256
}

util/ValidatorHelper_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,25 @@ func TestAutoScale(t *testing.T) {
108108
},
109109
{
110110
name: "non-empty autoscaling enabled minReplicas maxReplicas object",
111-
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: 10, maxReplicas:11}}},
111+
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: float64(10), maxReplicas: float64(11)}}},
112112
want: true,
113113
wantErr: false,
114114
},
115115
{
116116
name: "non-empty autoscaling enabled minReplicas empty maxReplicas object",
117-
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: 11}}},
117+
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: false,minReplicas: float64(11)}}},
118118
want: true,
119119
wantErr: false,
120120
},
121121
{
122122
name: "non-empty autoscaling minReplicas maxReplicas object empty enabled",
123-
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{minReplicas: 10, maxReplicas:11}}},
123+
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{minReplicas: float64(10), maxReplicas: float64(11)}}},
124124
want: true,
125125
wantErr: false,
126126
},
127127
{
128128
name: "negative: non-empty and greater minReplicas than maxReplicas object",
129-
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: true, minReplicas: 10, maxReplicas:9}}},
129+
args: args{dat: map[string]interface{}{autoScaling: map[string]interface{}{enabled: true, minReplicas: float64(10), maxReplicas: float64(9)}}},
130130
want: false,
131131
wantErr: true,
132132
},

0 commit comments

Comments
 (0)