File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -141,11 +141,12 @@ func supportSyntaxToBool(instanceTypeSupport *string) *bool {
141141}
142142
143143func calculateVCpusToMemoryRatio (vcpusVal * int64 , memoryVal * int64 ) * float64 {
144- if vcpusVal == nil || memoryVal == nil {
144+ if vcpusVal == nil || * vcpusVal == 0 || memoryVal == nil {
145145 return nil
146146 }
147147 // normalize vcpus to a mebivcpu value
148- return aws .Float64 (float64 (* memoryVal ) / float64 (* vcpusVal * 1024 ))
148+ result := math .Ceil (float64 (* memoryVal ) / float64 (* vcpusVal * 1024 ))
149+ return & result
149150}
150151
151152// Slice helper function
Original file line number Diff line number Diff line change @@ -217,17 +217,22 @@ func TestCalculateVCpusToMemoryRatio(t *testing.T) {
217217 vcpus := aws .Int64 (4 )
218218 memory := aws .Int64 (4096 )
219219 ratio := calculateVCpusToMemoryRatio (vcpus , memory )
220- h .Assert (t , * ratio == 1.00 , "nil should evaluate to nil " )
220+ h .Assert (t , * ratio == 1.00 , "ratio should equal 1:1 " )
221221
222222 vcpus = aws .Int64 (2 )
223223 memory = aws .Int64 (4096 )
224224 ratio = calculateVCpusToMemoryRatio (vcpus , memory )
225- h .Assert (t , * ratio == 2.00 , "nil should evaluate to nil " )
225+ h .Assert (t , * ratio == 2.00 , "ratio should equal 1:2 " )
226226
227227 vcpus = aws .Int64 (1 )
228228 memory = aws .Int64 (512 )
229229 ratio = calculateVCpusToMemoryRatio (vcpus , memory )
230- h .Assert (t , * ratio == 0.50 , "nil should evaluate to nil" )
230+ h .Assert (t , * ratio == 1.0 , "ratio should take the ceiling which equals 1:1" )
231+
232+ vcpus = aws .Int64 (0 )
233+ memory = aws .Int64 (512 )
234+ ratio = calculateVCpusToMemoryRatio (vcpus , memory )
235+ h .Assert (t , ratio == nil , "ratio should be nil when vcpus is 0" )
231236}
232237
233238func TestCalculateVCpusToMemoryRatio_Nil (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments