github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/util/memory/jvmheap_test.go (about) 1 // Copyright (C) 2021, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package memory 5 6 import ( 7 "github.com/stretchr/testify/assert" 8 "testing" 9 ) 10 11 // TestFormatJvmHeapSize tests the formatting of values using 1024 multiples 12 // GIVEN a integer ranging from 100 to over 1G 13 // WHEN FormatJvmHeapSize is called 14 // THEN ensure the result has whole numbers and correct suffix is returned: K, M, or G suffix. 15 func TestFormatJvmHeapSize(t *testing.T) { 16 asserts := assert.New(t) 17 asserts.Equal("1k", FormatJvmHeapSize(100), "expected 1k") 18 asserts.Equal("1k", FormatJvmHeapSize(UnitK), "expected 1k") 19 asserts.Equal("10k", FormatJvmHeapSize(10*UnitK), "expected 10k") 20 asserts.Equal("1000k", FormatJvmHeapSize(1000*UnitK), "expected 1000k") 21 asserts.Equal("10000k", FormatJvmHeapSize(10000*UnitK), "expected 10000k") 22 asserts.Equal("1m", FormatJvmHeapSize(UnitK*UnitK), "expected 1m") 23 24 asserts.Equal("1m", FormatJvmHeapSize(UnitM), "expected 1m") 25 asserts.Equal("10m", FormatJvmHeapSize(10*UnitM), "expected 10m") 26 asserts.Equal("1000m", FormatJvmHeapSize(1000*UnitM), "expected 1000m") 27 asserts.Equal("10000m", FormatJvmHeapSize(10000*UnitM), "expected 10000m") 28 asserts.Equal("1g", FormatJvmHeapSize(UnitK*UnitM), "expected 1g") 29 30 asserts.Equal("1g", FormatJvmHeapSize(UnitG), "expected 1g") 31 asserts.Equal("10g", FormatJvmHeapSize(10*UnitG), "expected 10g") 32 asserts.Equal("1000g", FormatJvmHeapSize(1000*UnitG), "expected 1000g") 33 asserts.Equal("10000g", FormatJvmHeapSize(10000*UnitG), "expected 10000g") 34 asserts.Equal("1024g", FormatJvmHeapSize(UnitK*UnitG), "expected 1024g") 35 } 36 37 // TestFormatJvmHeapMinMax tests the formatting of JVM heap string 38 // GIVEN a heap size 39 // WHEN FormatJvmHeapMinMax is called 40 // THEN ensure the result is a JVM formatted heap string with identical min/max heaps 41 func TestFormatJvmHeapMinMax(t *testing.T) { 42 asserts := assert.New(t) 43 asserts.Equal("-Xms500m -Xmx500m", FormatJvmHeapMinMax("500m"), "incorrect JVM heap string") 44 asserts.Equal("-Xms2g -Xmx2g", FormatJvmHeapMinMax("2g"), "incorrect JVM heap string") 45 }