github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/utils/ram_test.go (about)

     1  package utils
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/go-units"
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestParseRAMInHuman(t *testing.T) {
    11  	size, err := ParseRAMInHuman("")
    12  	assert.Nil(t, err)
    13  	assert.EqualValues(t, 0, size)
    14  
    15  	size, err = ParseRAMInHuman("1")
    16  	assert.Nil(t, err)
    17  	assert.EqualValues(t, 1, size)
    18  
    19  	size, err = ParseRAMInHuman("-1")
    20  	assert.Nil(t, err)
    21  	assert.EqualValues(t, -1, size)
    22  
    23  	size, err = ParseRAMInHuman("hhhh")
    24  	assert.NotNil(t, err)
    25  
    26  	size, err = ParseRAMInHuman("1G")
    27  	assert.Nil(t, err)
    28  	assert.EqualValues(t, units.GiB, size)
    29  
    30  	size, err = ParseRAMInHuman("-1T")
    31  	assert.Nil(t, err)
    32  	assert.EqualValues(t, -units.TiB, size)
    33  }