@@ -80,17 +80,21 @@ TEST_F(FetchGCSObjectTests, MissingBucket) {
8080}
8181
8282TEST_F (FetchGCSObjectTests, ServerError) {
83- EXPECT_CALL (*mock_client_, ReadObject).WillOnce ([](gcs::internal::ReadObjectRangeRequest const & request) {
84- EXPECT_EQ (request.bucket_name (), " bucket-from-property" ) << request;
85- auto mock_source = std::make_unique<gcs::testing::MockObjectReadSource>();
86- ::testing::InSequence seq;
87- EXPECT_CALL (*mock_source, IsOpen).WillRepeatedly (testing::Return (true ));
88- EXPECT_CALL (*mock_source, Read).WillOnce (testing::Return (google::cloud::Status (google::cloud::StatusCode::kInvalidArgument , " Invalid Argument" )));
89- EXPECT_CALL (*mock_source, IsOpen).WillRepeatedly (testing::Return (false ));
90-
91- std::unique_ptr<gcs::internal::ObjectReadSource> object_read_source = std::move (mock_source);
92- return google::cloud::make_status_or (std::move (object_read_source));
93- });
83+ EXPECT_CALL (*mock_client_, ReadObject)
84+ .WillOnce ([](gcs::internal::ReadObjectRangeRequest const & request) {
85+ EXPECT_EQ (request.bucket_name (), " bucket-from-property" ) << request;
86+ auto mock_source = std::make_unique<gcs::testing::MockObjectReadSource>();
87+ ::testing::InSequence seq;
88+ EXPECT_CALL (*mock_source, IsOpen).WillRepeatedly (testing::Return (true ));
89+ EXPECT_CALL (*mock_source, Read)
90+ .WillOnce (testing::Return (google::cloud::Status (
91+ google::cloud::StatusCode::kInvalidArgument ,
92+ " Invalid Argument" )));
93+ EXPECT_CALL (*mock_source, IsOpen).WillRepeatedly (testing::Return (false ));
94+
95+ std::unique_ptr<gcs::internal::ObjectReadSource> object_read_source = std::move (mock_source);
96+ return google::cloud::make_status_or (std::move (object_read_source));
97+ });
9498 EXPECT_TRUE (test_controller_.getProcessor ()->setProperty (FetchGCSObject::Bucket.name , " bucket-from-property" ));
9599 const auto & result = test_controller_.trigger (" hello world" , {{std::string (minifi_gcp::GCS_BUCKET_ATTR ), " bucket-from-attribute" }});
96100 EXPECT_EQ (0 , result.at (FetchGCSObject::Success).size ());
@@ -107,24 +111,27 @@ TEST_F(FetchGCSObjectTests, HappyPath) {
107111 auto const l = (std::min)(n, text.size () - offset);
108112 std::memcpy (buf, text.data () + offset, l);
109113 offset += l;
110- return gcs::internal::ReadSourceResult{l, gcs::internal::HttpResponse{200 , {}, {}}};
114+ return gcs::internal::ReadSourceResult{
115+ l, gcs::internal::HttpResponse{200 , {}, {}}};
111116 };
112- EXPECT_CALL (*mock_client_, ReadObject).WillOnce ([&](gcs::internal::ReadObjectRangeRequest const & request) {
113- EXPECT_EQ (request.bucket_name (), " bucket-from-attribute" ) << request;
114- EXPECT_TRUE (request.HasOption <gcs::Generation>());
115- EXPECT_TRUE (request.GetOption <gcs::Generation>().has_value ());
116- EXPECT_EQ (23 , request.GetOption <gcs::Generation>().value ());
117- auto mock_source = std::make_unique<gcs::testing::MockObjectReadSource>();
118- ::testing::InSequence seq;
119- EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (true ));
120- EXPECT_CALL (*mock_source, Read).WillOnce (simulate_read);
121- EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (false ));
122-
123- return google::cloud::make_status_or (std::unique_ptr<gcs::internal::ObjectReadSource>(std::move (mock_source)));
124- });
117+ EXPECT_CALL (*mock_client_, ReadObject)
118+ .WillOnce ([&](gcs::internal::ReadObjectRangeRequest const & request) {
119+ EXPECT_EQ (request.bucket_name (), " bucket-from-attribute" ) << request;
120+ EXPECT_TRUE (request.HasOption <gcs::Generation>());
121+ EXPECT_TRUE (request.GetOption <gcs::Generation>().has_value ());
122+ EXPECT_EQ (23 , request.GetOption <gcs::Generation>().value ());
123+ auto mock_source = std::make_unique<gcs::testing::MockObjectReadSource>();
124+ ::testing::InSequence seq;
125+ EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (true ));
126+ EXPECT_CALL (*mock_source, Read).WillOnce (simulate_read);
127+ EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (false ));
128+
129+ return google::cloud::make_status_or (
130+ std::unique_ptr<gcs::internal::ObjectReadSource>(
131+ std::move (mock_source)));
132+ });
125133 EXPECT_TRUE (test_controller_.getProcessor ()->setProperty (FetchGCSObject::ObjectGeneration.name , " ${gcs.generation}" ));
126- const auto & result = test_controller_.trigger (" hello world" ,
127- {{std::string (minifi_gcp::GCS_BUCKET_ATTR ), " bucket-from-attribute" }, {std::string (minifi_gcp::GCS_GENERATION ), " 23" }});
134+ const auto & result = test_controller_.trigger (" hello world" , {{std::string (minifi_gcp::GCS_BUCKET_ATTR ), " bucket-from-attribute" }, {std::string (minifi_gcp::GCS_GENERATION ), " 23" }});
128135 ASSERT_EQ (1 , result.at (FetchGCSObject::Success).size ());
129136 EXPECT_EQ (0 , result.at (FetchGCSObject::Failure).size ());
130137 EXPECT_EQ (" stored text" , test_controller_.plan ->getContent (result.at (FetchGCSObject::Success)[0 ]));
@@ -138,19 +145,23 @@ TEST_F(FetchGCSObjectTests, EmptyGeneration) {
138145 auto const l = (std::min)(n, text.size () - offset);
139146 std::memcpy (buf, text.data () + offset, l);
140147 offset += l;
141- return gcs::internal::ReadSourceResult{l, gcs::internal::HttpResponse{200 , {}, {}}};
148+ return gcs::internal::ReadSourceResult{
149+ l, gcs::internal::HttpResponse{200 , {}, {}}};
142150 };
143- EXPECT_CALL (*mock_client_, ReadObject).WillOnce ([&](gcs::internal::ReadObjectRangeRequest const & request) {
144- EXPECT_EQ (request.bucket_name (), " bucket-from-attribute" ) << request;
145- EXPECT_FALSE (request.HasOption <gcs::Generation>());
146- auto mock_source = std::make_unique<gcs::testing::MockObjectReadSource>();
147- ::testing::InSequence seq;
148- EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (true ));
149- EXPECT_CALL (*mock_source, Read).WillOnce (simulate_read);
150- EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (false ));
151-
152- return google::cloud::make_status_or (std::unique_ptr<gcs::internal::ObjectReadSource>(std::move (mock_source)));
153- });
151+ EXPECT_CALL (*mock_client_, ReadObject)
152+ .WillOnce ([&](gcs::internal::ReadObjectRangeRequest const & request) {
153+ EXPECT_EQ (request.bucket_name (), " bucket-from-attribute" ) << request;
154+ EXPECT_FALSE (request.HasOption <gcs::Generation>());
155+ auto mock_source = std::make_unique<gcs::testing::MockObjectReadSource>();
156+ ::testing::InSequence seq;
157+ EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (true ));
158+ EXPECT_CALL (*mock_source, Read).WillOnce (simulate_read);
159+ EXPECT_CALL (*mock_source, IsOpen ()).WillRepeatedly (testing::Return (false ));
160+
161+ return google::cloud::make_status_or (
162+ std::unique_ptr<gcs::internal::ObjectReadSource>(
163+ std::move (mock_source)));
164+ });
154165 EXPECT_TRUE (test_controller_.getProcessor ()->setProperty (FetchGCSObject::ObjectGeneration.name , " ${gcs.generation}" ));
155166 const auto & result = test_controller_.trigger (" hello world" , {{std::string (minifi_gcp::GCS_BUCKET_ATTR ), " bucket-from-attribute" }});
156167 ASSERT_EQ (1 , result.at (FetchGCSObject::Success).size ());
@@ -160,8 +171,7 @@ TEST_F(FetchGCSObjectTests, EmptyGeneration) {
160171
161172TEST_F (FetchGCSObjectTests, InvalidGeneration) {
162173 EXPECT_TRUE (test_controller_.getProcessor ()->setProperty (FetchGCSObject::ObjectGeneration.name , " ${gcs.generation}" ));
163- const auto & result = test_controller_.trigger (" hello world" ,
164- {{std::string (minifi_gcp::GCS_BUCKET_ATTR ), " bucket-from-attribute" }, {std::string (minifi_gcp::GCS_GENERATION ), " 23 banana" }});
174+ const auto & result = test_controller_.trigger (" hello world" , {{std::string (minifi_gcp::GCS_BUCKET_ATTR ), " bucket-from-attribute" }, {std::string (minifi_gcp::GCS_GENERATION ), " 23 banana" }});
165175 ASSERT_EQ (0 , result.at (FetchGCSObject::Success).size ());
166176 EXPECT_EQ (1 , result.at (FetchGCSObject::Failure).size ());
167177 EXPECT_EQ (" hello world" , test_controller_.plan ->getContent (result.at (FetchGCSObject::Failure)[0 ]));
0 commit comments