1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-28 03:57:02 +02:00

fix(encoding/form): Timestamp use local time and fix test wrong mock time zone (#3257)

* fix(form/test): wrong mock time zone

* fix lint
This commit is contained in:
jessetang 2024-03-22 23:41:41 +08:00 committed by GitHub
parent bfafeca13d
commit aeecf3cdcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 11 deletions

View File

@ -87,10 +87,6 @@ func TestFormCodecUnmarshal(t *testing.T) {
}
func TestProtoEncodeDecode(t *testing.T) {
loc := time.Local
time.Local = time.UTC
t.Cleanup(func() { time.Local = loc })
in := &complex.Complex{
Id: 2233,
NoOne: "2233",
@ -106,7 +102,7 @@ func TestProtoEncodeDecode(t *testing.T) {
Byte: []byte("123"),
Map: map[string]string{"kratos": "https://go-kratos.dev/", "kratos_start": "https://go-kratos.dev/en/docs/getting-started/start/"},
Timestamp: &timestamppb.Timestamp{Seconds: 20, Nanos: 2},
Timestamp: timestamppb.New(time.Date(1970, 1, 1, 0, 0, 20, 2, time.Local)),
Duration: &durationpb.Duration{Seconds: 120, Nanos: 22},
Field: &fieldmaskpb.FieldMask{Paths: []string{"1", "2"}},
Double: &wrapperspb.DoubleValue{Value: 12.33},

View File

@ -244,7 +244,7 @@ func parseMessage(md protoreflect.MessageDescriptor, value string) (protoreflect
if value == nullStr {
break
}
t, err := time.Parse(time.RFC3339Nano, value)
t, err := time.ParseInLocation(time.RFC3339Nano, value, time.Local)
if err != nil {
return protoreflect.Value{}, err
}

View File

@ -13,10 +13,6 @@ import (
)
func TestEncodeValues(t *testing.T) {
loc := time.Local
time.Local = time.UTC
t.Cleanup(func() { time.Local = loc })
in := &complex.Complex{
Id: 2233,
NoOne: "2233",
@ -33,7 +29,7 @@ func TestEncodeValues(t *testing.T) {
Map: map[string]string{"kratos": "https://go-kratos.dev/", "kratos_start": "https://go-kratos.dev/en/docs/getting-started/start/"},
MapInt64Key: map[int64]string{1: "kratos", 2: "go-zero"},
Timestamp: &timestamppb.Timestamp{Seconds: 20, Nanos: 2},
Timestamp: timestamppb.New(time.Date(1970, 1, 1, 0, 0, 20, 2, time.Local)),
Duration: &durationpb.Duration{Seconds: 120, Nanos: 22},
Field: &fieldmaskpb.FieldMask{Paths: []string{"1", "2"}},
Double: &wrapperspb.DoubleValue{Value: 12.33},