Skip to content

Commit

Permalink
feat(misc): ConvertTypeToString
Browse files Browse the repository at this point in the history
Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Apr 25, 2024
1 parent 651ed84 commit 7b0bfde
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions utils/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit 7b0bfde

Please sign in to comment.