@@ -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,12 +174,17 @@ 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 ):
177+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
178+ detect_resource ,
179+ )
180+
181+ RESOURCE = detect_resource (self .PROJECT )._to_dict ()
173182 TEXT = "TEXT"
174183 ENTRIES = [
175184 {
176185 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
177186 "textPayload" : TEXT ,
178- "resource" : { "type" : "global" , "labels" : {}} ,
187+ "resource" : RESOURCE ,
179188 }
180189 ]
181190 client = _Client (self .PROJECT )
@@ -187,13 +196,18 @@ def test_log_text_defaults(self):
187196 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
188197
189198 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+
190203 TEXT = "TEXT"
204+ RESOURCE = detect_resource (self .PROJECT )._to_dict ()
191205 DEFAULT_LABELS = {"foo" : "spam" }
192206 ENTRIES = [
193207 {
194208 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
195209 "textPayload" : TEXT ,
196- "resource" : { "type" : "global" , "labels" : {}} ,
210+ "resource" : RESOURCE ,
197211 "labels" : DEFAULT_LABELS ,
198212 }
199213 ]
@@ -263,12 +277,17 @@ def test_log_text_explicit(self):
263277 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
264278
265279 def test_log_struct_defaults (self ):
280+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
281+ detect_resource ,
282+ )
283+
266284 STRUCT = {"message" : "MESSAGE" , "weather" : "cloudy" }
285+ RESOURCE = detect_resource (self .PROJECT )._to_dict ()
267286 ENTRIES = [
268287 {
269288 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
270289 "jsonPayload" : STRUCT ,
271- "resource" : { "type" : "global" , "labels" : {}} ,
290+ "resource" : RESOURCE ,
272291 }
273292 ]
274293 client = _Client (self .PROJECT )
@@ -280,13 +299,18 @@ def test_log_struct_defaults(self):
280299 self .assertEqual (api ._write_entries_called_with , (ENTRIES , None , None , None ))
281300
282301 def test_log_struct_w_default_labels (self ):
302+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
303+ detect_resource ,
304+ )
305+
283306 STRUCT = {"message" : "MESSAGE" , "weather" : "cloudy" }
307+ RESOURCE = detect_resource (self .PROJECT )._to_dict ()
284308 DEFAULT_LABELS = {"foo" : "spam" }
285309 ENTRIES = [
286310 {
287311 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
288312 "jsonPayload" : STRUCT ,
289- "resource" : { "type" : "global" , "labels" : {}} ,
313+ "resource" : RESOURCE ,
290314 "labels" : DEFAULT_LABELS ,
291315 }
292316 ]
@@ -359,13 +383,16 @@ def test_log_proto_defaults(self):
359383 import json
360384 from google .protobuf .json_format import MessageToJson
361385 from google .protobuf .struct_pb2 import Struct , Value
386+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
387+ detect_resource ,
388+ )
362389
363390 message = Struct (fields = {"foo" : Value (bool_value = True )})
364391 ENTRIES = [
365392 {
366393 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
367394 "protoPayload" : json .loads (MessageToJson (message )),
368- "resource" : { "type" : "global" , "labels" : {}} ,
395+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
369396 }
370397 ]
371398 client = _Client (self .PROJECT )
@@ -380,14 +407,17 @@ def test_log_proto_w_default_labels(self):
380407 import json
381408 from google .protobuf .json_format import MessageToJson
382409 from google .protobuf .struct_pb2 import Struct , Value
410+ from google .cloud .logging_v2 .handlers ._monitored_resources import (
411+ detect_resource ,
412+ )
383413
384414 message = Struct (fields = {"foo" : Value (bool_value = True )})
385415 DEFAULT_LABELS = {"foo" : "spam" }
386416 ENTRIES = [
387417 {
388418 "logName" : "projects/%s/logs/%s" % (self .PROJECT , self .LOGGER_NAME ),
389419 "protoPayload" : json .loads (MessageToJson (message )),
390- "resource" : { "type" : "global" , "labels" : {}} ,
420+ "resource" : detect_resource ( self . PROJECT ). _to_dict () ,
391421 "labels" : DEFAULT_LABELS ,
392422 }
393423 ]
0 commit comments