| #include "proto_reader.h" |
| |
| #include <string> |
| |
| #include "safepower_agent.pb.h" |
| #include "gmock/gmock.h" |
| #include "gtest/gtest.h" |
| #include "absl/strings/str_cat.h" |
| #include "absl/strings/string_view.h" |
| |
| namespace { |
| |
| using ::safepower_agent_proto::StartActionRequest; |
| using ::testing::EqualsProto; |
| using ::testing::status::IsOkAndHolds; |
| |
| constexpr absl::string_view kTestDataPath = |
| "" |
| "testdata"; |
| |
| TEST(ProtoReaderTest, ReadBinaryOk) { |
| std::string file_name = absl::StrCat(testing::SrcDir(), "/", kTestDataPath, |
| "/good_data.binarypb"); |
| EXPECT_THAT(proto_reader::ReadProto<StartActionRequest>(file_name), |
| IsOkAndHolds(EqualsProto(R"pb(caller_cookie: "test")pb"))); |
| } |
| |
| TEST(ProtoReaderTest, WriteReadBinaryOk) { |
| std::string file_name = absl::StrCat(testing::TempDir(), "/test.binarypb"); |
| StartActionRequest request; |
| request.set_caller_cookie("test"); |
| EXPECT_OK(proto_reader::WriteProto(file_name, request)); |
| EXPECT_THAT(proto_reader::ReadProto<StartActionRequest>(file_name), |
| IsOkAndHolds(EqualsProto(R"pb(caller_cookie: "test")pb"))); |
| } |
| |
| } // namespace |