...

Source file src/github.com/go-openapi/runtime/flagext/byte_size_test.go

Documentation: github.com/go-openapi/runtime/flagext

     1  package flagext
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func TestMarshalBytesize(t *testing.T) {
    11  	v, err := ByteSize(1024).MarshalFlag()
    12  	require.NoError(t, err)
    13  	assert.Equal(t, "1.024kB", v)
    14  }
    15  
    16  func TestStringBytesize(t *testing.T) {
    17  	v := ByteSize(2048).String()
    18  	assert.Equal(t, "2.048kB", v)
    19  }
    20  
    21  func TestUnmarshalBytesize(t *testing.T) {
    22  	var b ByteSize
    23  	err := b.UnmarshalFlag("notASize")
    24  	require.Error(t, err)
    25  
    26  	err = b.UnmarshalFlag("1MB")
    27  	require.NoError(t, err)
    28  	assert.Equal(t, ByteSize(1000000), b)
    29  }
    30  
    31  func TestSetBytesize(t *testing.T) {
    32  	var b ByteSize
    33  	err := b.Set("notASize")
    34  	require.Error(t, err)
    35  
    36  	err = b.Set("2MB")
    37  	require.NoError(t, err)
    38  	assert.Equal(t, ByteSize(2000000), b)
    39  }
    40  
    41  func TestTypeBytesize(t *testing.T) {
    42  	var b ByteSize
    43  	assert.Equal(t, "byte-size", b.Type())
    44  }
    45  

View as plain text