From f49f75b3718d10c21963ad96780a6849c76902c3 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Fri, 26 Aug 2022 10:47:25 +0800 Subject: [PATCH] test: add unit test for EncodeByte and DecodeByte --- convertor/convertor_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/convertor/convertor_test.go b/convertor/convertor_test.go index 4970f9c..6797dd1 100644 --- a/convertor/convertor_test.go +++ b/convertor/convertor_test.go @@ -238,3 +238,21 @@ func TestToPointer(t *testing.T) { assert.Equal(*result, 123) } + +func TestEncodeByte(t *testing.T) { + assert := internal.NewAssert(t, "TestEncodeByte") + + byteData, _ := EncodeByte("abc") + expected := []byte{6, 12, 0, 3, 97, 98, 99} + + assert.Equal(expected, byteData) +} + +func TestDecodeByte(t *testing.T) { + assert := internal.NewAssert(t, "TestDecodeByte") + + var obj string + byteData := []byte{6, 12, 0, 3, 97, 98, 99} + DecodeByte(byteData, &obj) + assert.Equal("abc", obj) +}