@@ -28,7 +28,10 @@ namespace {
28
28
29
29
namespace v2 = ::google::storage::v2;
30
30
using ::google::cloud::testing_util::IsProtoEqual;
31
+ using ::testing::AllOf;
31
32
using ::testing::ElementsAre;
33
+ using ::testing::ElementsAreArray;
34
+ using ::testing::Property;
32
35
using ::testing::UnorderedElementsAre;
33
36
34
37
TEST (GrpcBucketRequestParser, DeleteBucketMetadataAllOptions) {
@@ -212,6 +215,70 @@ TEST(GrpcBucketRequestParser, ListBucketsResponse) {
212
215
EXPECT_THAT (names, ElementsAre (" test-bucket-1" , " test-bucket-2" ));
213
216
}
214
217
218
+ TEST (GrpcBucketRequestParser, GetIamPolicyRequest) {
219
+ google::iam::v1::GetIamPolicyRequest expected;
220
+ ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
221
+ R"pb(
222
+ resource: "projects/_/buckets/test-bucket"
223
+ options { requested_policy_version: 3 }
224
+ )pb" ,
225
+ &expected));
226
+
227
+ GetBucketIamPolicyRequest req (" test-bucket" );
228
+ req.set_multiple_options (
229
+ RequestedPolicyVersion (3 ), UserProject (" test-user-project" ),
230
+ QuotaUser (" test-quota-user" ), UserIp (" test-user-ip" ));
231
+ auto const actual = GrpcBucketRequestParser::ToProto (req);
232
+ EXPECT_THAT (actual, IsProtoEqual (expected));
233
+ }
234
+
235
+ TEST (GrpcBucketRequestParser, NativeIamPolicy) {
236
+ google::iam::v1::Policy input;
237
+ ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
238
+ R"pb(
239
+ version: 7
240
+ bindings {
241
+ role: "role/test.only"
242
+ members: "test-1"
243
+ members: "test-2"
244
+ condition {
245
+ expression: "test-expression"
246
+ title: "test-title"
247
+ description: "test-description"
248
+ location: "test-location"
249
+ }
250
+ }
251
+ bindings { role: "role/another.test.only" members: "test-3" }
252
+ etag: "test-etag"
253
+ )pb" ,
254
+ &input));
255
+
256
+ auto const actual = GrpcBucketRequestParser::FromProto (input);
257
+ EXPECT_EQ (7 , actual.version ());
258
+ EXPECT_EQ (" test-etag" , actual.etag ());
259
+ NativeIamBinding b0 (
260
+ " role/test.only" , {" test-1" , " test-2" },
261
+ {" test-expression" , " test-title" , " test-description" , " test-location" });
262
+ NativeIamBinding b1 (" role/another.test.only" , {" test-3" });
263
+
264
+ auto match_expr = [](NativeExpression const & e) {
265
+ return AllOf (Property (&NativeExpression::expression, e.expression ()),
266
+ Property (&NativeExpression::title, e.title ()),
267
+ Property (&NativeExpression::description, e.description ()),
268
+ Property (&NativeExpression::location, e.location ()));
269
+ };
270
+ auto match_binding = [&](NativeIamBinding const & b) {
271
+ return AllOf (
272
+ Property (&NativeIamBinding::role, b.role ()),
273
+ Property (&NativeIamBinding::members, ElementsAreArray (b.members ())),
274
+ Property (&NativeIamBinding::has_condition, b.has_condition ()));
275
+ };
276
+ ASSERT_THAT (actual.bindings (),
277
+ ElementsAre (match_binding (b0), match_binding (b1)));
278
+ ASSERT_TRUE (actual.bindings ()[0 ].has_condition ());
279
+ ASSERT_THAT (actual.bindings ()[0 ].condition (), match_expr (b0.condition ()));
280
+ }
281
+
215
282
TEST (GrpcBucketRequestParser, PatchBucketRequestAllOptions) {
216
283
google::storage::v2::UpdateBucketRequest expected;
217
284
ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
0 commit comments