@@ -298,6 +298,7 @@ describe('logging-bunyan', function() {
298298 } ) ;
299299
300300 it ( 'should leave prefixed trace property as is if set' , function ( done ) {
301+ var oldTraceAgent = global . _google_trace_agent ;
301302 global . _google_trace_agent = {
302303 getCurrentContextId : function ( ) { return 'trace-from-agent' ; } ,
303304 getWriterProjectId : function ( ) { return 'project1' ; }
@@ -315,9 +316,44 @@ describe('logging-bunyan', function() {
315316 } ;
316317
317318 loggingBunyan . write ( recordWithTraceAlreadySet , '' , assert . ifError ) ;
319+
320+ global . _google_trace_agent = oldTraceAgent ;
318321 } ) ;
319322 } ) ;
320323
324+ it ( 'should not set prefixed trace property if trace unavailable' , function ( ) {
325+ FakeWritable . prototype . write = function ( record , encoding , callback ) {
326+ assert . deepStrictEqual ( record , RECORD ) ;
327+ assert . strictEqual ( encoding , '' ) ;
328+ assert . strictEqual ( callback , assert . ifError ) ;
329+ assert . strictEqual ( this , loggingBunyan ) ;
330+ } ;
331+ var oldTraceAgent = global . _google_trace_agent ;
332+
333+ global . _google_trace_agent = { } ;
334+ loggingBunyan . write ( RECORD , '' , assert . ifError ) ;
335+
336+ global . _google_trace_agent = {
337+ getCurrentContextId : function ( ) { return null ; } ,
338+ getWriterProjectId : function ( ) { return null ; }
339+ } ;
340+ loggingBunyan . write ( RECORD , '' , assert . ifError ) ;
341+
342+ global . _google_trace_agent = {
343+ getCurrentContextId : function ( ) { return null ; } ,
344+ getWriterProjectId : function ( ) { return 'project1' ; }
345+ } ;
346+ loggingBunyan . write ( RECORD , '' , assert . ifError ) ;
347+
348+ global . _google_trace_agent = {
349+ getCurrentContextId : function ( ) { return 'trace1' ; } ,
350+ getWriterProjectId : function ( ) { return null ; }
351+ } ;
352+ loggingBunyan . write ( RECORD , '' , assert . ifError ) ;
353+
354+ global . _google_trace_agent = oldTraceAgent ;
355+ } ) ;
356+
321357 describe ( '_write' , function ( ) {
322358 beforeEach ( function ( ) {
323359 fakeLogInstance . entry = function ( ) { } ;
0 commit comments