From 6186ab61dfb162e35b4eb72c9b06b62053990f5a Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Wed, 21 Aug 2024 19:26:28 +0900 Subject: [PATCH] fix asTime api --- grpc/federation/cel/time.go | 2 +- grpc/federation/cel/time_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/grpc/federation/cel/time.go b/grpc/federation/cel/time.go index 1b60c6da..958134b0 100644 --- a/grpc/federation/cel/time.go +++ b/grpc/federation/cel/time.go @@ -432,7 +432,7 @@ func (lib *TimeLibrary) CompileOptions() []cel.EnvOption { "asTime", MemberOverloadFunc(createTimeID("asTime_timestamp_int_time"), cel.TimestampType, []*cel.Type{}, TimeType, func(_ context.Context, self ref.Val, args ...ref.Val) ref.Val { - return lib.toTimeValue(self.(*types.Timestamp).Time) + return lib.toTimeValue(self.(types.Timestamp).Time) }, ), ), diff --git a/grpc/federation/cel/time_test.go b/grpc/federation/cel/time_test.go index 7cf8690d..07e40077 100644 --- a/grpc/federation/cel/time_test.go +++ b/grpc/federation/cel/time_test.go @@ -1365,6 +1365,22 @@ func TestTime(t *testing.T) { return nil }, }, + { + name: "asTime", + expr: "google.protobuf.Timestamp{seconds: 1560000000}.asTime()", + cmp: func(got ref.Val) error { + gotV, ok := got.Value().(*cellib.Time) + if !ok { + return fmt.Errorf("invalid result type: %T", got) + } + gotSecond := gotV.GetTimestamp().GetSeconds() + expected := 1560000000 + if diff := cmp.Diff(int(gotSecond), expected); diff != "" { + return fmt.Errorf("(-got, +want)\n%s", diff) + } + return nil + }, + }, } reg, err := types.NewRegistry(new(cellib.Time), new(cellib.Location)) if err != nil {