@@ -260,6 +260,39 @@ def test_list_entry_with_requestlog(self):
260
260
protobuf_entry .to_api_repr ()["protoPayload" ]["@type" ], type_url
261
261
)
262
262
263
+ def test_list_entry_with_auditdata (self ):
264
+ """
265
+ Test emitting and listing logs containing a google.iam.v1.logging.AuditData proto message
266
+ """
267
+ from google .protobuf import descriptor_pool
268
+ from google .cloud .logging_v2 import entries
269
+
270
+ pool = descriptor_pool .Default ()
271
+ type_name = "google.iam.v1.logging.AuditData"
272
+ type_url = "type.googleapis.com/" + type_name
273
+ # Make sure the descriptor is known in the registry.
274
+ # Raises KeyError if unknown
275
+ pool .FindMessageTypeByName (type_name )
276
+
277
+ # create log
278
+ req_dict = {"@type" : type_url , "policyDelta" : {}}
279
+ req_struct = self ._dict_to_struct (req_dict )
280
+
281
+ logger = Config .CLIENT .logger (f"auditdata-proto-{ uuid .uuid1 ()} " )
282
+ logger .log_proto (req_struct )
283
+
284
+ # retrieve log
285
+ retry = RetryErrors ((TooManyRequests , StopIteration ), max_tries = 8 )
286
+ protobuf_entry = retry (lambda : next (logger .list_entries ()))()
287
+
288
+ self .assertIsInstance (protobuf_entry , entries .ProtobufEntry )
289
+ self .assertIsNone (protobuf_entry .payload_pb )
290
+ self .assertIsInstance (protobuf_entry .payload_json , dict )
291
+ self .assertEqual (protobuf_entry .payload_json ["@type" ], type_url )
292
+ self .assertEqual (
293
+ protobuf_entry .to_api_repr ()["protoPayload" ]["@type" ], type_url
294
+ )
295
+
263
296
def test_log_text (self ):
264
297
TEXT_PAYLOAD = "System test: test_log_text"
265
298
logger = Config .CLIENT .logger (self ._logger_name ("log_text" ))
0 commit comments