From 511f1917ced7effe95dc00dcabe626ad784ce69b Mon Sep 17 00:00:00 2001 From: jessetang <1430482733@qq.com> Date: Mon, 7 Nov 2022 14:20:56 +0800 Subject: [PATCH] fix(contrib/log): test case error (#2487) * fix(contrib/log): test case error * fix float32 * add nil case --- contrib/log/aliyun/aliyun_test.go | 19 ++++++++++--------- contrib/log/tencent/tencent_test.go | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/contrib/log/aliyun/aliyun_test.go b/contrib/log/aliyun/aliyun_test.go index c4bfde480..e3e224ad4 100644 --- a/contrib/log/aliyun/aliyun_test.go +++ b/contrib/log/aliyun/aliyun_test.go @@ -116,21 +116,22 @@ func TestToString(t *testing.T) { {"float64", 6.66, "6.66"}, {"max float64", math.MaxFloat64, "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}, //nolint:lll {"float32", float32(6.66), "6.66"}, - {"max float32", math.MaxFloat32, "340282346638528860000000000000000000000"}, - {"int", int(math.MaxInt64), "9223372036854775807"}, + {"max float32", float32(math.MaxFloat32), "340282350000000000000000000000000000000"}, + {"int", math.MaxInt64, "9223372036854775807"}, {"uint", uint(math.MaxUint64), "18446744073709551615"}, - {"int8", math.MaxInt8, "127"}, - {"uint8", math.MaxUint8, "255"}, - {"int16", math.MaxInt16, "32767"}, - {"uint16", math.MaxUint16, "65535"}, - {"int32", math.MaxInt32, "2147483647"}, - {"uint32", math.MaxUint32, "4294967295"}, - {"int64", math.MaxInt64, "9223372036854775807"}, + {"int8", int8(math.MaxInt8), "127"}, + {"uint8", uint8(math.MaxUint8), "255"}, + {"int16", int16(math.MaxInt16), "32767"}, + {"uint16", uint16(math.MaxUint16), "65535"}, + {"int32", int32(math.MaxInt32), "2147483647"}, + {"uint32", uint32(math.MaxUint32), "4294967295"}, + {"int64", int64(math.MaxInt64), "9223372036854775807"}, {"uint64", uint64(math.MaxUint64), "18446744073709551615"}, {"string", "abc", "abc"}, {"bool", false, "false"}, {"[]byte", []byte("abc"), "abc"}, {"struct", struct{ Name string }{}, `{"Name":""}`}, + {"nil", nil, ""}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { diff --git a/contrib/log/tencent/tencent_test.go b/contrib/log/tencent/tencent_test.go index 76bc13bdd..df1fe367c 100644 --- a/contrib/log/tencent/tencent_test.go +++ b/contrib/log/tencent/tencent_test.go @@ -120,21 +120,22 @@ func TestToString(t *testing.T) { {"float64", 6.66, "6.66"}, {"max float64", math.MaxFloat64, "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}, //nolint:lll {"float32", float32(6.66), "6.66"}, - {"max float32", math.MaxFloat32, "340282346638528860000000000000000000000"}, - {"int", int(math.MaxInt64), "9223372036854775807"}, + {"max float32", float32(math.MaxFloat32), "340282350000000000000000000000000000000"}, + {"int", math.MaxInt64, "9223372036854775807"}, {"uint", uint(math.MaxUint64), "18446744073709551615"}, - {"int8", math.MaxInt8, "127"}, - {"uint8", math.MaxUint8, "255"}, - {"int16", math.MaxInt16, "32767"}, - {"uint16", math.MaxUint16, "65535"}, - {"int32", math.MaxInt32, "2147483647"}, - {"uint32", math.MaxUint32, "4294967295"}, - {"int64", math.MaxInt64, "9223372036854775807"}, + {"int8", int8(math.MaxInt8), "127"}, + {"uint8", uint8(math.MaxUint8), "255"}, + {"int16", int16(math.MaxInt16), "32767"}, + {"uint16", uint16(math.MaxUint16), "65535"}, + {"int32", int32(math.MaxInt32), "2147483647"}, + {"uint32", uint32(math.MaxUint32), "4294967295"}, + {"int64", int64(math.MaxInt64), "9223372036854775807"}, {"uint64", uint64(math.MaxUint64), "18446744073709551615"}, {"string", "abc", "abc"}, {"bool", false, "false"}, {"[]byte", []byte("abc"), "abc"}, {"struct", struct{ Name string }{}, `{"Name":""}`}, + {"nil", nil, ""}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) {