From 51eea1dcc14b7e684ca71f36fbbb05d44dc73fc6 Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Wed, 16 Aug 2023 16:50:24 +0800 Subject: [PATCH] test: add unit tests for byte (#2645) Signed-off-by: Guangwen Feng --- pkg/unit/byte_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/unit/byte_test.go b/pkg/unit/byte_test.go index 007e2fd0d..ea0d53ffa 100644 --- a/pkg/unit/byte_test.go +++ b/pkg/unit/byte_test.go @@ -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 {