Skip to content

Commit 5e27356

Browse files
committed
minimize formatting changes for easier review
1 parent 4b7dd06 commit 5e27356

5 files changed

Lines changed: 166 additions & 140 deletions

File tree

extensions/gcp/tests/DeleteGCSObjectTests.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ TEST_F(DeleteGCSObjectTests, MissingBucket) {
8282
}
8383

8484
TEST_F(DeleteGCSObjectTests, ServerGivesPermaError) {
85-
EXPECT_CALL(*mock_client_, DeleteObject).WillOnce(testing::Return(PermanentError()));
85+
EXPECT_CALL(*mock_client_, DeleteObject)
86+
.WillOnce(testing::Return(PermanentError()));
8687
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(DeleteGCSObject::Bucket.name, "bucket-from-property"));
8788
const auto& result = test_controller_.trigger("hello world");
8889
EXPECT_EQ(0, result.at(DeleteGCSObject::Success).size());
@@ -105,13 +106,14 @@ TEST_F(DeleteGCSObjectTests, ServerGivesTransientErrors) {
105106
}
106107

107108
TEST_F(DeleteGCSObjectTests, HandlingSuccessfullDeletion) {
108-
EXPECT_CALL(*mock_client_, DeleteObject).WillOnce([](DeleteObjectRequest const& request) {
109-
EXPECT_EQ("bucket-from-attribute", request.bucket_name());
110-
EXPECT_TRUE(request.HasOption<gcs::Generation>());
111-
EXPECT_TRUE(request.GetOption<gcs::Generation>().has_value());
112-
EXPECT_EQ(23, request.GetOption<gcs::Generation>().value());
113-
return google::cloud::make_status_or(gcs::internal::EmptyResponse{});
114-
});
109+
EXPECT_CALL(*mock_client_, DeleteObject)
110+
.WillOnce([](DeleteObjectRequest const& request) {
111+
EXPECT_EQ("bucket-from-attribute", request.bucket_name());
112+
EXPECT_TRUE(request.HasOption<gcs::Generation>());
113+
EXPECT_TRUE(request.GetOption<gcs::Generation>().has_value());
114+
EXPECT_EQ(23, request.GetOption<gcs::Generation>().value());
115+
return google::cloud::make_status_or(gcs::internal::EmptyResponse{});
116+
});
115117
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(DeleteGCSObject::ObjectGeneration.name, "${gcs.generation}"));
116118
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"}});
117119
ASSERT_EQ(1, result.at(DeleteGCSObject::Success).size());
@@ -120,11 +122,12 @@ TEST_F(DeleteGCSObjectTests, HandlingSuccessfullDeletion) {
120122
}
121123

122124
TEST_F(DeleteGCSObjectTests, EmptyGeneration) {
123-
EXPECT_CALL(*mock_client_, DeleteObject).WillOnce([](DeleteObjectRequest const& request) {
124-
EXPECT_EQ("bucket-from-attribute", request.bucket_name());
125-
EXPECT_FALSE(request.HasOption<gcs::Generation>());
126-
return google::cloud::make_status_or(gcs::internal::EmptyResponse{});
127-
});
125+
EXPECT_CALL(*mock_client_, DeleteObject)
126+
.WillOnce([](DeleteObjectRequest const& request) {
127+
EXPECT_EQ("bucket-from-attribute", request.bucket_name());
128+
EXPECT_FALSE(request.HasOption<gcs::Generation>());
129+
return google::cloud::make_status_or(gcs::internal::EmptyResponse{});
130+
});
128131
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(DeleteGCSObject::ObjectGeneration.name, "${gcs.generation}"));
129132
const auto& result = test_controller_.trigger("hello world", {{std::string(minifi_gcp::GCS_BUCKET_ATTR), "bucket-from-attribute"}});
130133
ASSERT_EQ(1, result.at(DeleteGCSObject::Success).size());

extensions/gcp/tests/FetchGCSObjectTests.cpp

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,21 @@ TEST_F(FetchGCSObjectTests, MissingBucket) {
8080
}
8181

8282
TEST_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

161172
TEST_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]));

extensions/gcp/tests/GCPCredentialsControllerServiceTests.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,20 @@ using GCPCredentialsControllerService = minifi_gcp::GCPCredentialsControllerServ
3535
namespace {
3636

3737
std::string create_mock_service_json() {
38-
auto root = rapidjson::Document(rapidjson::kObjectType);
38+
rapidjson::Document root = rapidjson::Document(rapidjson::kObjectType);
3939
root.AddMember("type", "service_account", root.GetAllocator());
4040
root.AddMember("project_id", "mock_project_id", root.GetAllocator());
4141
root.AddMember("private_key_id", "my_private_key_id", root.GetAllocator());
42-
root.AddMember("private_key",
43-
"-----BEGIN PRIVATE KEY-----\n"
44-
"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAo2Eyw6KfcYOSD0D1\n"
45-
"7cw3+M/Qkv5xXwaxxHlAZk+Bscjkm2S37iQwm87mLnhyr7nnAUXZTHsR6SDrBhj7\n"
46-
"9xvM1QIDAQABAkB1RTJL7HGn5/myCz27J4fRh1E+AXbc75Av55yLE2yTb+qwfX3m\n"
47-
"eAw0dZAIRQ8ZuXw7su71bW2YyB43RwXOnGWtAiEA0zo0bu6h8LPAK9y65zw8KNuF\n"
48-
"A+Rif5+7K12uv1XgCWsCIQDGAqSH6JToI7yHOup47XM1CKMnjBDe67ExJPuDH3HS\n"
49-
"vwIgAI+RABJmH6t6gSNO47pHNpyOl9oNYOVdq9nN0vg5Zg0CIQDEDjXOg9F8kHXJ\n"
50-
"B+LFXYamyiiRrbO+pWvKly2ZRPc0jQIgfZyH0JGjJKZTLog14owyAA+JUkHTh7Em\n"
51-
"8o9ev8MeLoM=\n"
52-
"-----END PRIVATE KEY-----",
53-
root.GetAllocator());
42+
root.AddMember("private_key", "-----BEGIN PRIVATE KEY-----\n"
43+
"MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAo2Eyw6KfcYOSD0D1\n"
44+
"7cw3+M/Qkv5xXwaxxHlAZk+Bscjkm2S37iQwm87mLnhyr7nnAUXZTHsR6SDrBhj7\n"
45+
"9xvM1QIDAQABAkB1RTJL7HGn5/myCz27J4fRh1E+AXbc75Av55yLE2yTb+qwfX3m\n"
46+
"eAw0dZAIRQ8ZuXw7su71bW2YyB43RwXOnGWtAiEA0zo0bu6h8LPAK9y65zw8KNuF\n"
47+
"A+Rif5+7K12uv1XgCWsCIQDGAqSH6JToI7yHOup47XM1CKMnjBDe67ExJPuDH3HS\n"
48+
"vwIgAI+RABJmH6t6gSNO47pHNpyOl9oNYOVdq9nN0vg5Zg0CIQDEDjXOg9F8kHXJ\n"
49+
"B+LFXYamyiiRrbO+pWvKly2ZRPc0jQIgfZyH0JGjJKZTLog14owyAA+JUkHTh7Em\n"
50+
"8o9ev8MeLoM=\n"
51+
"-----END PRIVATE KEY-----", root.GetAllocator());
5452
root.AddMember("client_email", "my_client_email", root.GetAllocator());
5553
root.AddMember("client_id", "my_client_id", root.GetAllocator());
5654
rapidjson::StringBuffer buffer;
@@ -62,7 +60,8 @@ std::string create_mock_service_json() {
6260
std::optional<std::filesystem::path> create_mock_json_file(const std::filesystem::path& dir_path) {
6361
std::filesystem::path path = dir_path / "mock_credentials.json";
6462
std::ofstream p{path};
65-
if (!p) { return std::nullopt; }
63+
if (!p)
64+
return std::nullopt;
6665
p << create_mock_service_json();
6766
p.close();
6867
return path;

extensions/gcp/tests/ListGCSBucketTests.cpp

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class ListGCSBucketMocked : public ListGCSBucket {
5151
auto CreateObject(int index, int generation = 1) {
5252
std::string id = "object-" + std::to_string(index);
5353
std::string name = id;
54-
std::string link = "https://storage.googleapis.com/storage/v1/b/test-bucket/" + id + "#1";
54+
std::string link =
55+
"https://storage.googleapis.com/storage/v1/b/test-bucket/" + id + "#1";
5556
nlohmann::json metadata{
5657
{"bucket", "test-bucket"},
5758
{"id", id},
@@ -98,7 +99,9 @@ TEST_F(ListGCSBucketTests, ServerGivesPermaError) {
9899
}
99100

100101
TEST_F(ListGCSBucketTests, ServerGivesTransientErrors) {
101-
auto return_temp_error = [](ListObjectsRequest const&) { return google::cloud::StatusOr<ListObjectsResponse>(TransientError()); };
102+
auto return_temp_error = [](ListObjectsRequest const&) {
103+
return google::cloud::StatusOr<ListObjectsResponse>(TransientError());
104+
};
102105
EXPECT_CALL(*mock_client_, ListObjects).WillOnce(return_temp_error);
103106
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(ListGCSBucket::NumberOfRetries.name, "1"));
104107
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(ListGCSBucket::Bucket.name, "bucket-from-property"));
@@ -107,34 +110,38 @@ TEST_F(ListGCSBucketTests, ServerGivesTransientErrors) {
107110
}
108111

109112
TEST_F(ListGCSBucketTests, WithoutVersions) {
110-
EXPECT_CALL(*mock_client_, ListObjects).WillOnce([](ListObjectsRequest const& req) -> google::cloud::StatusOr<ListObjectsResponse> {
111-
EXPECT_EQ("bucket-from-property", req.bucket_name());
112-
EXPECT_TRUE(req.HasOption<gcs::Versions>());
113-
EXPECT_FALSE(req.GetOption<gcs::Versions>().value());
113+
EXPECT_CALL(*mock_client_, ListObjects)
114+
.WillOnce([](ListObjectsRequest const& req)
115+
-> google::cloud::StatusOr<ListObjectsResponse> {
116+
EXPECT_EQ("bucket-from-property", req.bucket_name());
117+
EXPECT_TRUE(req.HasOption<gcs::Versions>());
118+
EXPECT_FALSE(req.GetOption<gcs::Versions>().value());
114119

115-
ListObjectsResponse response;
116-
response.items.emplace_back(CreateObject(1, 1));
117-
response.items.emplace_back(CreateObject(1, 2));
118-
response.items.emplace_back(CreateObject(1, 3));
119-
return response;
120-
});
120+
ListObjectsResponse response;
121+
response.items.emplace_back(CreateObject(1, 1));
122+
response.items.emplace_back(CreateObject(1, 2));
123+
response.items.emplace_back(CreateObject(1, 3));
124+
return response;
125+
});
121126
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(ListGCSBucket::Bucket.name, "bucket-from-property"));
122127
const auto& result = test_controller_.trigger();
123128
EXPECT_EQ(3, result.at(ListGCSBucket::Success).size());
124129
}
125130

126131
TEST_F(ListGCSBucketTests, WithVersions) {
127-
EXPECT_CALL(*mock_client_, ListObjects).WillOnce([](ListObjectsRequest const& req) -> google::cloud::StatusOr<ListObjectsResponse> {
128-
EXPECT_EQ("bucket-from-property", req.bucket_name());
129-
EXPECT_TRUE(req.HasOption<gcs::Versions>());
130-
EXPECT_TRUE(req.GetOption<gcs::Versions>().value());
132+
EXPECT_CALL(*mock_client_, ListObjects)
133+
.WillOnce([](ListObjectsRequest const& req)
134+
-> google::cloud::StatusOr<ListObjectsResponse> {
135+
EXPECT_EQ("bucket-from-property", req.bucket_name());
136+
EXPECT_TRUE(req.HasOption<gcs::Versions>());
137+
EXPECT_TRUE(req.GetOption<gcs::Versions>().value());
131138

132-
ListObjectsResponse response;
133-
response.items.emplace_back(CreateObject(1));
134-
response.items.emplace_back(CreateObject(2));
135-
response.items.emplace_back(CreateObject(3));
136-
return response;
137-
});
139+
ListObjectsResponse response;
140+
response.items.emplace_back(CreateObject(1));
141+
response.items.emplace_back(CreateObject(2));
142+
response.items.emplace_back(CreateObject(3));
143+
return response;
144+
});
138145
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(ListGCSBucket::Bucket.name, "bucket-from-property"));
139146
EXPECT_TRUE(test_controller_.getProcessor()->setProperty(ListGCSBucket::ListAllVersions.name, "true"));
140147
const auto& result = test_controller_.trigger();

0 commit comments

Comments
 (0)