77
88const test = require ( 'node:test' )
99const assert = require ( 'assert' )
10+ const helper = require ( '../../lib/agent_helper' )
1011const fetchAzureFunctionInfo = require ( '../../../lib/utilization/azurefunction-info' )
1112
12- test ( 'fetchAzureFunctionInfo should return null if detect_azurefunction is disabled' , ( t , end ) => {
13- const agent = {
13+ test . beforeEach ( ( ctx ) => {
14+ const agent = helper . loadMockedAgent ( {
1415 config : {
1516 utilization : {
16- detect_azurefunction : false
17+ detect_azurefunction : true
1718 }
1819 }
19- }
20+ } )
21+ ctx . nr = { agent }
22+ } )
23+
24+ test . afterEach ( ( ctx ) => {
25+ helper . unloadAgent ( ctx . nr . agent )
26+ ctx . nr . agent = null
27+ fetchAzureFunctionInfo . clearCache ( )
28+ } )
29+
30+ test ( 'should return null if detect_azurefunction is disabled' , ( ctx , end ) => {
31+ const agent = ctx . nr . agent
32+ agent . config . utilization . detect_azurefunction = false
2033
2134 fetchAzureFunctionInfo ( agent , ( err , result ) => {
2235 assert . strictEqual ( err , null )
@@ -25,20 +38,23 @@ test('fetchAzureFunctionInfo should return null if detect_azurefunction is disab
2538 } )
2639} )
2740
28- test ( 'fetchAzureFunctionInfo should derive metadata from required environment variables' , ( t , end ) => {
29- const agent = {
30- config : {
31- utilization : {
32- detect_azurefunction : true
33- }
34- }
35- }
41+ test ( 'should return null if required environment variables are missing' , ( ctx , end ) => {
42+ const agent = ctx . nr . agent
43+
44+ fetchAzureFunctionInfo ( agent , ( err , result ) => {
45+ assert . strictEqual ( err , null )
46+ assert . strictEqual ( result , null )
47+ end ( )
48+ } )
49+ } )
50+
51+ test ( 'should derive metadata from required environment variables' , ( ctx , end ) => {
52+ const agent = ctx . nr . agent
3653
3754 process . env . REGION_NAME = 'Central US'
3855 process . env . WEBSITE_OWNER_NAME = '12345+resource-group'
3956 process . env . WEBSITE_SITE_NAME = 'my-function-app'
4057
41- fetchAzureFunctionInfo . clearCache ( )
4258 fetchAzureFunctionInfo ( agent , ( err , result ) => {
4359 assert . strictEqual ( err , null )
4460 assert . deepStrictEqual ( result , {
@@ -49,25 +65,18 @@ test('fetchAzureFunctionInfo should derive metadata from required environment va
4965 } )
5066} )
5167
52- test ( 'fetchAzureFunctionInfo should derive metadata from required and optional environment variables' , ( t , end ) => {
53- const agent = {
54- config : {
55- utilization : {
56- detect_azurefunction : true
57- }
58- }
59- }
68+ test ( 'should derive metadata from required and optional environment variables' , ( ctx , end ) => {
69+ const agent = ctx . nr . agent
6070
6171 process . env . REGION_NAME = 'Central US'
62- process . env . WEBSITE_RESOURCE_GROUP = 'resource-group'
72+ process . env . WEBSITE_RESOURCE_GROUP = 'resource-group-actual '
6373 process . env . WEBSITE_OWNER_NAME = '12345+resource-group'
6474 process . env . WEBSITE_SITE_NAME = 'my-function-app'
6575
66- fetchAzureFunctionInfo . clearCache ( )
6776 fetchAzureFunctionInfo ( agent , ( err , result ) => {
6877 assert . strictEqual ( err , null )
6978 assert . deepStrictEqual ( result , {
70- 'faas.app_name' : '/subscriptions/12345/resourceGroups/resource-group/providers/Microsoft.Web/sites/my-function-app' ,
79+ 'faas.app_name' : '/subscriptions/12345/resourceGroups/resource-group-actual /providers/Microsoft.Web/sites/my-function-app' ,
7180 'cloud.region' : 'Central US'
7281 } )
7382 end ( )
0 commit comments