-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
String conversion functions for timestamp and duration.
The functions `string(timestamp)` and `string(duration)` will produce formatted strings which match those found in string-encoded protobuf values for `google.protobuf.Timestamp` and `google.protobuf.Duration` respectively. PiperOrigin-RevId: 359302330
- Loading branch information
1 parent
2977932
commit c190825
Showing
17 changed files
with
253 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include "eval/public/containers/field_access.h" | ||
|
||
#include "google/protobuf/message.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "absl/status/status.h" | ||
#include "absl/time/time.h" | ||
#include "internal/proto_util.h" | ||
#include "proto/test/v1/proto3/test_all_types.pb.h" | ||
|
||
namespace google { | ||
namespace api { | ||
namespace expr { | ||
namespace runtime { | ||
|
||
namespace { | ||
|
||
using google::api::expr::internal::MakeGoogleApiDurationMax; | ||
using google::api::expr::internal::MakeGoogleApiTimeMax; | ||
using google::protobuf::FieldDescriptor; | ||
using test::v1::proto3::TestAllTypes; | ||
|
||
TEST(FieldAccessTest, SetDuration) { | ||
TestAllTypes msg; | ||
const FieldDescriptor* field = | ||
TestAllTypes::descriptor()->FindFieldByName("single_duration"); | ||
auto status = SetValueToSingleField( | ||
CelValue::CreateDuration(MakeGoogleApiDurationMax()), field, &msg); | ||
EXPECT_TRUE(status.ok()); | ||
} | ||
|
||
TEST(FieldAccessTest, SetDurationBadDuration) { | ||
TestAllTypes msg; | ||
const FieldDescriptor* field = | ||
TestAllTypes::descriptor()->FindFieldByName("single_duration"); | ||
auto status = SetValueToSingleField( | ||
CelValue::CreateDuration(MakeGoogleApiDurationMax() + absl::Seconds(1)), | ||
field, &msg); | ||
EXPECT_FALSE(status.ok()); | ||
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument); | ||
} | ||
|
||
TEST(FieldAccessTest, SetDurationBadInputType) { | ||
TestAllTypes msg; | ||
const FieldDescriptor* field = | ||
TestAllTypes::descriptor()->FindFieldByName("single_duration"); | ||
auto status = SetValueToSingleField(CelValue::CreateInt64(1), field, &msg); | ||
EXPECT_FALSE(status.ok()); | ||
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument); | ||
} | ||
|
||
TEST(FieldAccessTest, SetTimestamp) { | ||
TestAllTypes msg; | ||
const FieldDescriptor* field = | ||
TestAllTypes::descriptor()->FindFieldByName("single_timestamp"); | ||
auto status = SetValueToSingleField( | ||
CelValue::CreateTimestamp(MakeGoogleApiTimeMax()), field, &msg); | ||
EXPECT_TRUE(status.ok()); | ||
} | ||
|
||
TEST(FieldAccessTest, SetTimestampBadTime) { | ||
TestAllTypes msg; | ||
const FieldDescriptor* field = | ||
TestAllTypes::descriptor()->FindFieldByName("single_timestamp"); | ||
auto status = SetValueToSingleField( | ||
CelValue::CreateTimestamp(MakeGoogleApiTimeMax() + absl::Seconds(1)), | ||
field, &msg); | ||
EXPECT_FALSE(status.ok()); | ||
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument); | ||
} | ||
|
||
TEST(FieldAccessTest, SetTimestampBadInputType) { | ||
TestAllTypes msg; | ||
const FieldDescriptor* field = | ||
TestAllTypes::descriptor()->FindFieldByName("single_timestamp"); | ||
auto status = SetValueToSingleField(CelValue::CreateInt64(1), field, &msg); | ||
EXPECT_FALSE(status.ok()); | ||
EXPECT_EQ(status.code(), absl::StatusCode::kInvalidArgument); | ||
} | ||
|
||
} // namespace | ||
|
||
} // namespace runtime | ||
} // namespace expr | ||
} // namespace api | ||
} // namespace google |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.