File: byte_size_test.go

package info (click to toggle)
golang-github-go-openapi-runtime 0.28.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,060 kB
  • sloc: sh: 9; makefile: 4
file content (44 lines) | stat: -rw-r--r-- 864 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package flagext

import (
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestMarshalBytesize(t *testing.T) {
	v, err := ByteSize(1024).MarshalFlag()
	require.NoError(t, err)
	assert.Equal(t, "1.024kB", v)
}

func TestStringBytesize(t *testing.T) {
	v := ByteSize(2048).String()
	assert.Equal(t, "2.048kB", v)
}

func TestUnmarshalBytesize(t *testing.T) {
	var b ByteSize
	err := b.UnmarshalFlag("notASize")
	require.Error(t, err)

	err = b.UnmarshalFlag("1MB")
	require.NoError(t, err)
	assert.Equal(t, ByteSize(1000000), b)
}

func TestSetBytesize(t *testing.T) {
	var b ByteSize
	err := b.Set("notASize")
	require.Error(t, err)

	err = b.Set("2MB")
	require.NoError(t, err)
	assert.Equal(t, ByteSize(2000000), b)
}

func TestTypeBytesize(t *testing.T) {
	var b ByteSize
	assert.Equal(t, "byte-size", b.Type())
}