test: add UT for byte String function (#2170)

Signed-off-by: Zhou Hao <zhouhao@fujitsu.com>
This commit is contained in:
Zhou Hao 2023-03-14 11:55:30 +08:00 committed by Gaius
parent 8b65c0c913
commit eff06c9fe3
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
1 changed files with 37 additions and 0 deletions

View File

@ -162,3 +162,40 @@ size: 1Mix
assert.Equal(tc.size, data.Size.ToNumber()) assert.Equal(tc.size, data.Size.ToNumber())
} }
} }
func Test_String(t *testing.T) {
assert := testifyassert.New(t)
testCases := []struct {
data string
b Bytes
}{
{
data: "1.0B",
b: 1,
},
{
data: "2.0KB",
b: 2 * 1024,
},
{
data: "3.0MB",
b: 3 * 1024 * 1024,
},
{
data: "4.0GB",
b: 4 * 1024 * 1024 * 1024,
},
{
data: "5.0TB",
b: 5 * 1024 * 1024 * 1024 * 1024,
},
{
data: "6.0PB",
b: 6 * 1024 * 1024 * 1024 * 1024 * 1024,
},
}
for _, tc := range testCases {
assert.Equal(tc.b.String(), tc.data)
}
}