From 7b0bfde16f073f855f512c984a877dd91a9fefff Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Thu, 25 Apr 2024 12:44:33 +0800 Subject: [PATCH] feat(misc): ConvertTypeToString Signed-off-by: Chin-Ya Huang --- utils/misc_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/utils/misc_test.go b/utils/misc_test.go index f425ba1e..c90ed9f7 100644 --- a/utils/misc_test.go +++ b/utils/misc_test.go @@ -200,3 +200,43 @@ func (s TestSuite) TestGenerateRandomNumber(c *C) { } } } + +func (s *TestSuite) TestConvertTypeToString(c *C) { + type testCase struct { + inputValue interface{} + + expected string + } + testCases := map[string]testCase{ + "ConvertTypeToString(...): string": { + inputValue: "abc", + expected: "abc", + }, + "ConvertTypeToString(...): int": { + inputValue: 123, + expected: "123", + }, + "ConvertTypeToString(...): int64": { + inputValue: int64(123), + expected: "123", + }, + "ConvertTypeToString(...): float": { + inputValue: 123.456, + expected: "123.456", + }, + "ConvertTypeToString(...): bool": { + inputValue: true, + expected: "true", + }, + "ConvertTypeToString(...): unsupported": { + inputValue: nil, + expected: "Unsupported type: invalid", + }, + } + for testName, testCase := range testCases { + c.Logf("testing utils.%v", testName) + + result := ConvertTypeToString(testCase.inputValue) + c.Assert(result, Equals, testCase.expected, Commentf(test.ErrResultFmt, testName)) + } +}