test: add unit tests for byte (#2645)

Signed-off-by: Guangwen Feng <fenggw-fnst@fujitsu.com>
This commit is contained in:
Guangwen Feng 2023-08-16 16:50:24 +08:00 committed by GitHub
parent 7d5ebae1f1
commit 51eea1dcc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 0 deletions

View File

@ -83,6 +83,12 @@ func Test_Set(t *testing.T) {
}
}
func Test_Type(t *testing.T) {
assert := testifyassert.New(t)
var f Bytes
assert.Equal("bytes", f.Type())
}
func Test_parseByte(t *testing.T) {
assert := testifyassert.New(t)
testCases := []struct {
@ -180,6 +186,28 @@ func Test_parseByte(t *testing.T) {
}
}
func TestByteMarshalYAML(t *testing.T) {
tests := []struct {
name string
f Bytes
expect any
}{
{
name: "3MB",
f: 3 * 1024 * 1024,
expect: "3.0MB",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert := testifyassert.New(t)
result, _ := tc.f.MarshalYAML()
assert.Equal(tc.expect, result)
})
}
}
func TestByteUnmarshal(t *testing.T) {
assert := testifyassert.New(t)
testCases := []struct {