@@ -99,11 +99,15 @@ def test_batch_w_alternate_client(self):
9999 self .assertIs (batch .client , client2 )
100100
101101 def test_log_empty_defaults_w_default_labels (self ):
102+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
103+ detect_resource ,
104+ )
105+
102106 DEFAULT_LABELS = {"foo" : "spam" }
103107 ENTRIES = [
104108 {
105109 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
106- "resource" : { "type" : "global" , "labels" : {}} ,
110+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
107111 "labels" : DEFAULT_LABELS ,
108112 }
109113 ]
@@ -170,7 +174,11 @@ def test_log_empty_w_explicit(self):
170174 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
171175
172176 def test_log_text_defaults (self ):
173- RESOURCE = {"type" : "global" , "labels" : {}}
177+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
178+ detect_resource ,
179+ )
180+
181+ RESOURCE = detect_resource (self .PROJECT )._to_dict ()
174182 TEXT = "TEXT"
175183 ENTRIES = [
176184 {
@@ -188,8 +196,12 @@ def test_log_text_defaults(self):
188196 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
189197
190198 def test_log_text_w_unicode_and_default_labels (self ):
199+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
200+ detect_resource ,
201+ )
202+
191203 TEXT = "TEXT"
192- RESOURCE = { "type" : "global" , "labels" : {}}
204+ RESOURCE = detect_resource ( self . PROJECT ). _to_dict ()
193205 DEFAULT_LABELS = {"foo" : "spam" }
194206 ENTRIES = [
195207 {
@@ -265,8 +277,12 @@ def test_log_text_explicit(self):
265277 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
266278
267279 def test_log_struct_defaults (self ):
280+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
281+ detect_resource ,
282+ )
283+
268284 STRUCT = {"message" : "MESSAGE" , "weather" : "cloudy" }
269- RESOURCE = { "type" : "global" , "labels" : {}}
285+ RESOURCE = detect_resource ( self . PROJECT ). _to_dict ()
270286 ENTRIES = [
271287 {
272288 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
@@ -283,8 +299,12 @@ def test_log_struct_defaults(self):
283299 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
284300
285301 def test_log_struct_w_default_labels (self ):
302+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
303+ detect_resource ,
304+ )
305+
286306 STRUCT = {"message" : "MESSAGE" , "weather" : "cloudy" }
287- RESOURCE = { "type" : "global" , "labels" : {}}
307+ RESOURCE = detect_resource ( self . PROJECT ). _to_dict ()
288308 DEFAULT_LABELS = {"foo" : "spam" }
289309 ENTRIES = [
290310 {
@@ -360,6 +380,9 @@ def test_log_struct_w_explicit(self):
360380 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
361381
362382 def test_log_proto_defaults (self ):
383+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
384+ detect_resource ,
385+ )
363386 import json
364387 from google .protobuf .json_format import MessageToJson
365388 from google .protobuf .struct_pb2 import Struct , Value
@@ -369,7 +392,7 @@ def test_log_proto_defaults(self):
369392 {
370393 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
371394 "protoPayload" : json .loads (MessageToJson (message )),
372- "resource" : { "type" : "global" , "labels" : {}} ,
395+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
373396 }
374397 ]
375398 client = _Client (self .PROJECT )
@@ -381,6 +404,9 @@ def test_log_proto_defaults(self):
381404 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
382405
383406 def test_log_proto_w_default_labels (self ):
407+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
408+ detect_resource ,
409+ )
384410 import json
385411 from google .protobuf .json_format import MessageToJson
386412 from google .protobuf .struct_pb2 import Struct , Value
@@ -391,7 +417,7 @@ def test_log_proto_w_default_labels(self):
391417 {
392418 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
393419 "protoPayload" : json .loads (MessageToJson (message )),
394- "resource" : { "type" : "global" , "labels" : {}} ,
420+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
395421 "labels" : DEFAULT_LABELS ,
396422 }
397423 ]
@@ -465,11 +491,15 @@ def test_log_proto_w_explicit(self):
465491 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
466492
467493 def test_log_inference_empty (self ):
494+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
495+ detect_resource ,
496+ )
497+
468498 DEFAULT_LABELS = {"foo" : "spam" }
469499 ENTRIES = [
470500 {
471501 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
472- "resource" : { "type" : "global" , "labels" : {}} ,
502+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
473503 "labels" : DEFAULT_LABELS ,
474504 }
475505 ]
@@ -482,13 +512,16 @@ def test_log_inference_empty(self):
482512 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
483513
484514 def test_log_inference_text (self ):
485- RESOURCE = {"type" : "global" , "labels" : {}}
515+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
516+ detect_resource ,
517+ )
518+
486519 TEXT = "TEXT"
487520 ENTRIES = [
488521 {
489522 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
490523 "textPayload" : TEXT ,
491- "resource" : RESOURCE ,
524+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
492525 }
493526 ]
494527 client = _Client (self .PROJECT )
@@ -500,13 +533,16 @@ def test_log_inference_text(self):
500533 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
501534
502535 def test_log_inference_struct (self ):
536+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
537+ detect_resource ,
538+ )
539+
503540 STRUCT = {"message" : "MESSAGE" , "weather" : "cloudy" }
504- RESOURCE = {"type" : "global" , "labels" : {}}
505541 ENTRIES = [
506542 {
507543 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
508544 "jsonPayload" : STRUCT ,
509- "resource" : RESOURCE ,
545+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
510546 }
511547 ]
512548 client = _Client (self .PROJECT )
@@ -521,13 +557,16 @@ def test_log_inference_proto(self):
521557 import json
522558 from google .protobuf .json_format import MessageToJson
523559 from google .protobuf .struct_pb2 import Struct , Value
560+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
561+ detect_resource ,
562+ )
524563
525564 message = Struct (fields = {"foo" : Value (bool_value = True )})
526565 ENTRIES = [
527566 {
528567 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
529568 "protoPayload" : json .loads (MessageToJson (message )),
530- "resource" : { "type" : "global" , "labels" : {}} ,
569+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
531570 }
532571 ]
533572 client = _Client (self .PROJECT )
0 commit comments