@@ -26,7 +26,12 @@ import * as stackdriver from '../src/types/stackdriver';
2626
2727DEFAULT_CONFIG . allowExpressions = true ;
2828DEFAULT_CONFIG . workingDirectory = path . join ( __dirname , '..' , '..' ) ;
29- import { Debuglet , CachedPromise , FindFilesResult } from '../src/agent/debuglet' ;
29+ import {
30+ Debuglet ,
31+ CachedPromise ,
32+ FindFilesResult ,
33+ Platforms ,
34+ } from '../src/agent/debuglet' ;
3035import { ScanResults } from '../src/agent/io/scanner' ;
3136import * as extend from 'extend' ;
3237import { Debug } from '../src/client/stackdriver/debug' ;
@@ -1542,6 +1547,48 @@ describe('Debuglet', () => {
15421547 ) ;
15431548 assert . strictEqual ( debuggee . canaryMode , 'CANARY_MODE_ALWAYS_DISABLED' ) ;
15441549 } ) ;
1550+
1551+ it ( 'should correctly identify default platform.' , ( ) => {
1552+ const debuggee = Debuglet . createDebuggee (
1553+ 'some project' ,
1554+ 'id' ,
1555+ { service : 'some-service' , version : 'production' } ,
1556+ { } ,
1557+ false ,
1558+ packageInfo
1559+ ) ;
1560+ assert . ok ( debuggee . labels ! . platform === Platforms . DEFAULT ) ;
1561+ } ) ;
1562+
1563+ it ( 'should correctly identify GCF (legacy) platform.' , ( ) => {
1564+ // GCF sets this env var on older runtimes.
1565+ process . env . FUNCTION_NAME = 'mock' ;
1566+ const debuggee = Debuglet . createDebuggee (
1567+ 'some project' ,
1568+ 'id' ,
1569+ { service : 'some-service' , version : 'production' } ,
1570+ { } ,
1571+ false ,
1572+ packageInfo
1573+ ) ;
1574+ assert . ok ( debuggee . labels ! . platform === Platforms . CLOUD_FUNCTION ) ;
1575+ delete process . env . FUNCTION_NAME ; // Don't contaminate test environment.
1576+ } ) ;
1577+
1578+ it ( 'should correctly identify GCF (modern) platform.' , ( ) => {
1579+ // GCF sets this env var on modern runtimes.
1580+ process . env . FUNCTION_TARGET = 'mock' ;
1581+ const debuggee = Debuglet . createDebuggee (
1582+ 'some project' ,
1583+ 'id' ,
1584+ { service : 'some-service' , version : 'production' } ,
1585+ { } ,
1586+ false ,
1587+ packageInfo
1588+ ) ;
1589+ assert . ok ( debuggee . labels ! . platform === Platforms . CLOUD_FUNCTION ) ;
1590+ delete process . env . FUNCTION_TARGET ; // Don't contaminate test environment.
1591+ } ) ;
15451592 } ) ;
15461593
15471594 describe ( '_createUniquifier' , ( ) => {
0 commit comments