55 */
66
77const test = require ( 'tape' )
8- const config = require ( '../lib/config' )
8+ const { clear , getConfig , readConfigJson , readRootConfigFile , getMainModulePath } = require ( '../lib/config' )
99const { HttpStatusCodeErrorsBuilder } = require ( '../lib/instrumentation/http/http-status-code-errors-builder' )
1010const log = require ( '../lib/utils/log/logger' )
1111
1212test ( 'Agent ID required field' , function ( t ) {
1313 t . plan ( 1 )
1414
15- config . clear ( )
15+ clear ( )
1616 delete process . env . PINPOINT_AGENT_ID
1717 delete process . env . PINPOINT_APPLICATION_NAME
1818
19- const conf = config . getConfig ( )
19+ const conf = getConfig ( )
2020
2121 t . true ( conf . agentId . length == 16 )
2222} )
@@ -26,8 +26,8 @@ test('Should be configured with environment variable', function (t) {
2626
2727 const agentId = 'id-from-env'
2828 process . env . PINPOINT_AGENT_ID = agentId
29- config . clear ( )
30- const conf = config . getConfig ( )
29+ clear ( )
30+ const conf = getConfig ( )
3131
3232 t . equal ( agentId , conf . agentId )
3333} )
@@ -37,8 +37,8 @@ test('Should be configured with argument', function (t) {
3737
3838 process . env . PINPOINT_AGENT_ID = 'id-from-env'
3939 const agentId = 'id-from-argument'
40- config . clear ( )
41- const conf = config . getConfig ( {
40+ clear ( )
41+ const conf = getConfig ( {
4242 'agent-id' : agentId
4343 } , false )
4444
@@ -49,7 +49,7 @@ test('Should be read from config file', function (t) {
4949 t . plan ( 1 )
5050
5151 const testConfig = require ( './pinpoint-config-test' )
52- const result = config . readConfigJson ( testConfig )
52+ const result = readConfigJson ( testConfig )
5353 log . debug ( result )
5454 t . ok ( result )
5555} )
@@ -58,33 +58,33 @@ test('deadline config', (t) => {
5858 t . plan ( 1 )
5959
6060 const json = require ( '../lib/pinpoint-config-default' )
61- const result = config . readConfigJson ( json )
61+ const result = readConfigJson ( json )
6262 t . equal ( result . streamDeadlineMinutesClientSide , 10 )
6363} )
6464
65- test ( 'main moudle path' , ( t ) => {
66- config . clear ( )
67- const conf = config . readRootConfigFile ( )
65+ test ( 'main module path' , ( t ) => {
66+ clear ( )
67+ const conf = readRootConfigFile ( )
6868 t . deepEqual ( conf , { } , 'configuration is null object' )
69- let actual = config . getMainModulePath ( require )
69+ let actual = getMainModulePath ( require )
7070
71- actual = config . getMainModulePath ( { } )
72- t . true ( actual === undefined , 'config. getMainModulePath({}) return value is undefined' )
71+ actual = getMainModulePath ( { } )
72+ t . true ( actual === undefined , 'getMainModulePath({}) return value is undefined' )
7373
74- actual = config . getMainModulePath ( )
75- t . true ( actual === undefined , 'config. getMainModulePath() return value is undefined' )
74+ actual = getMainModulePath ( )
75+ t . true ( actual === undefined , 'getMainModulePath() return value is undefined' )
7676
77- actual = config . getMainModulePath ( null )
78- t . true ( actual === undefined , 'config. getMainModulePath(null) return value is undefined' )
77+ actual = getMainModulePath ( null )
78+ t . true ( actual === undefined , 'getMainModulePath(null) return value is undefined' )
7979
80- actual = config . getMainModulePath ( { main : { } } )
81- t . true ( actual === undefined , 'config. getMainModulePath({ main: {} }) return value is undefined' )
80+ actual = getMainModulePath ( { main : { } } )
81+ t . true ( actual === undefined , 'getMainModulePath({ main: {} }) return value is undefined' )
8282
83- actual = config . getMainModulePath ( { main : { filename : '/test' } } )
84- t . equal ( actual , '/' , 'config. getMainModulePath({ main: { filename: \' / test\' } }) return value is /' )
83+ actual = getMainModulePath ( { main : { filename : '/test' } } )
84+ t . equal ( actual , '/' , 'getMainModulePath({ main: { filename: \' / test\' } }) return value is /' )
8585
86- actual = config . getMainModulePath ( { main : { filename : '/test/test1' } } )
87- t . equal ( actual , '/test' , 'config. getMainModulePath({ main: { filename: \' / test\' } }) return value is /' )
86+ actual = getMainModulePath ( { main : { filename : '/test/test1' } } )
87+ t . equal ( actual , '/test' , 'getMainModulePath({ main: { filename: \' / test\' } }) return value is /' )
8888
8989 t . end ( )
9090} )
@@ -98,73 +98,73 @@ test('main moudle path', (t) => {
9898// public static final int AGENT_ID_MAX_LEN = 24;
9999// }
100100test ( 'Agent ID length check' , ( t ) => {
101- config . clear ( )
101+ clear ( )
102102 process . env [ 'PINPOINT_AGENT_ID' ] = 'agentId'
103103 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appication-name'
104104 process . env [ 'PINPOINT_AGENT_NAME' ] = 'agent-name'
105105
106- let given = config . getConfig ( )
106+ let given = getConfig ( )
107107 t . true ( given . enable , 'configuration agentId, Name, ApplicationName enable agent id' )
108108 t . equal ( given . agentName , 'agent-name' , 'agent name is agent name' )
109109
110110 delete process . env . PINPOINT_AGENT_ID
111111 delete process . env . PINPOINT_APPLICATION_NAME
112112
113- config . clear ( )
113+ clear ( )
114114 process . env [ 'PINPOINT_AGENT_ID' ] = 'agentIdagentIdagentIdage'
115115 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
116116
117- given = config . getConfig ( )
117+ given = getConfig ( )
118118 t . true ( given . enable , 'maxlength agentID and application Name' )
119119
120120 delete process . env . PINPOINT_AGENT_ID
121121 delete process . env . PINPOINT_APPLICATION_NAME
122122
123- config . clear ( )
123+ clear ( )
124124 process . env [ 'PINPOINT_AGENT_ID' ] = 'agentIdagentIdagentIdageE'
125125 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
126126
127- given = config . getConfig ( )
127+ given = getConfig ( )
128128 t . false ( given . enable , 'maxlength agentID error' )
129129
130130 delete process . env . PINPOINT_AGENT_ID
131131 delete process . env . PINPOINT_APPLICATION_NAME
132132
133- config . clear ( )
133+ clear ( )
134134 process . env [ 'PINPOINT_AGENT_ID' ] = 'agentIdagentIdagentIdage'
135135 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappicationE'
136136
137- given = config . getConfig ( )
137+ given = getConfig ( )
138138 t . false ( given . enable , 'maxlength application Name error' )
139139
140140 delete process . env . PINPOINT_AGENT_ID
141141 delete process . env . PINPOINT_APPLICATION_NAME
142142
143- config . clear ( )
143+ clear ( )
144144 process . env [ 'PINPOINT_AGENT_ID' ] = '~'
145145 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
146146
147- given = config . getConfig ( )
147+ given = getConfig ( )
148148 t . false ( given . enable , 'invalide agent ID' )
149149
150150 delete process . env . PINPOINT_AGENT_ID
151151 delete process . env . PINPOINT_APPLICATION_NAME
152152
153- config . clear ( )
153+ clear ( )
154154 process . env [ 'PINPOINT_AGENT_ID' ] = 'agentIdagentIdagentIdage'
155155 process . env [ 'PINPOINT_APPLICATION_NAME' ] = '~'
156156
157- given = config . getConfig ( )
157+ given = getConfig ( )
158158 t . false ( given . enable , 'invalide application name' )
159159
160160 delete process . env . PINPOINT_AGENT_ID
161161 delete process . env . PINPOINT_AGENT_NAME
162162 delete process . env . PINPOINT_APPLICATION_NAME
163163
164- config . clear ( )
164+ clear ( )
165165 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
166166
167- given = config . getConfig ( )
167+ given = getConfig ( )
168168 t . true ( given . enable , 'agent ID nullable test' )
169169 t . equal ( given . applicationName , 'appicationnameappication' , 'application name is appicationnameappication' )
170170 t . equal ( given . agentId . length , 16 , 'random generated agent ID length is 16' )
@@ -173,8 +173,8 @@ test('Agent ID length check', (t) => {
173173 delete process . env . PINPOINT_AGENT_NAME
174174 delete process . env . PINPOINT_APPLICATION_NAME
175175
176- config . clear ( )
177- given = config . getConfig ( )
176+ clear ( )
177+ given = getConfig ( )
178178 t . false ( given . enable , 'Application Name must be set' )
179179 t . true ( given . agentId . length === 16 , 'Agent ID was generated randomly' )
180180 t . false ( given . agentName , 'Agent Name is optional value and only set from developer' )
@@ -184,10 +184,10 @@ test('Agent ID length check', (t) => {
184184 delete process . env . PINPOINT_AGENT_NAME
185185 delete process . env . PINPOINT_APPLICATION_NAME
186186
187- config . clear ( )
187+ clear ( )
188188 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
189189 process . env [ 'PINPOINT_AGENT_NAME' ] = 'agent name'
190- given = config . getConfig ( )
190+ given = getConfig ( )
191191 t . false ( given . enable , 'Application Name must be set' )
192192 t . true ( given . agentId . length === 16 , 'Agent ID was generated randomly' )
193193 t . equal ( given . agentName , 'agent name' , 'Agent Name is optional value and only set from developer' )
@@ -197,10 +197,10 @@ test('Agent ID length check', (t) => {
197197 delete process . env . PINPOINT_AGENT_NAME
198198 delete process . env . PINPOINT_APPLICATION_NAME
199199
200- config . clear ( )
200+ clear ( )
201201 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
202202 process . env [ 'PINPOINT_AGENT_NAME' ] = 'agent?name'
203- given = config . getConfig ( )
203+ given = getConfig ( )
204204 t . false ( given . enable , 'Application Name must be set' )
205205 t . true ( given . agentId . length === 16 , 'Agent ID was generated randomly' )
206206 t . equal ( given . agentName , 'agent?name' , 'Agent Name is optional value and only set from developer' )
@@ -210,10 +210,10 @@ test('Agent ID length check', (t) => {
210210 delete process . env . PINPOINT_AGENT_NAME
211211 delete process . env . PINPOINT_APPLICATION_NAME
212212
213- config . clear ( )
213+ clear ( )
214214 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
215215 process . env [ 'PINPOINT_AGENT_NAME' ] = 'agentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagen'
216- given = config . getConfig ( )
216+ given = getConfig ( )
217217 t . false ( given . enable , 'Application Name must be set' )
218218 t . true ( given . agentId . length === 16 , 'Agent ID was generated randomly' )
219219 t . equal ( given . agentName , 'agentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagen' , 'Agent Name is optional value and only set from developer' )
@@ -223,10 +223,10 @@ test('Agent ID length check', (t) => {
223223 delete process . env . PINPOINT_AGENT_NAME
224224 delete process . env . PINPOINT_APPLICATION_NAME
225225
226- config . clear ( )
226+ clear ( )
227227 process . env [ 'PINPOINT_APPLICATION_NAME' ] = 'appicationnameappication'
228228 process . env [ 'PINPOINT_AGENT_NAME' ] = 'agentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameage'
229- given = config . getConfig ( )
229+ given = getConfig ( )
230230 t . true ( given . enable , 'Application Name must be set' )
231231 t . true ( given . agentId . length === 16 , 'Agent ID was generated randomly' )
232232 t . equal ( given . agentName , 'agentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameagentnameage' , 'Agent Name is optional value and only set from developer' )
@@ -240,49 +240,49 @@ test('Agent ID length check', (t) => {
240240} )
241241
242242test ( 'callSite config' , ( t ) => {
243- config . clear ( )
243+ clear ( )
244244
245- let given = config . getConfig ( )
245+ let given = getConfig ( )
246246 t . false ( given . traceLocationAndFileNameOfCallSite , 'default value is false' )
247247
248- config . clear ( )
248+ clear ( )
249249 process . env [ 'PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE' ] = ''
250- given = config . getConfig ( )
250+ given = getConfig ( )
251251 t . false ( given . traceLocationAndFileNameOfCallSite , 'default value is true validation' )
252252
253- config . clear ( )
253+ clear ( )
254254 process . env [ 'PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE' ] = 'false'
255- given = config . getConfig ( )
255+ given = getConfig ( )
256256 t . false ( given . traceLocationAndFileNameOfCallSite , 'false value is false' )
257257
258- config . clear ( )
258+ clear ( )
259259 process . env [ 'PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE' ] = 'true'
260- given = config . getConfig ( )
260+ given = getConfig ( )
261261 t . true ( given . traceLocationAndFileNameOfCallSite , 'true value is true' )
262262 delete process . env . PINPOINT_TRACE_LOCATION_AND_FILENAME_OF_CALL_SITE
263263
264- config . clear ( )
264+ clear ( )
265265 process . env [ 'PINPOINT_PROFILER_SQL_STAT' ] = 'true'
266- given = config . getConfig ( )
266+ given = getConfig ( )
267267 t . true ( given . profilerSqlStat , 'profilerSqlStat is true' )
268268 delete process . env . PINPOINT_PROFILER_SQL_STAT
269269 t . end ( )
270270} )
271271
272272test ( 'sampling Rate' , ( t ) => {
273- config . clear ( )
273+ clear ( )
274274 let conf = require ( '../lib/config' ) . getConfig ( )
275275 t . equal ( conf . sampleRate , 10 , 'default sampling rate is 10' )
276276
277- config . clear ( )
277+ clear ( )
278278 conf = require ( '../lib/config' ) . getConfig ( { 'sampling' : { 'rate' : 20 } } )
279279 t . equal ( conf . sampleRate , 20 , 'sampling rate is 20' )
280280
281281 t . end ( )
282282} )
283283
284284test ( 'HTTP Status Code Errors' , ( t ) => {
285- config . clear ( )
285+ clear ( )
286286 let conf = require ( '../lib/config' ) . getConfig ( )
287287 t . equal ( conf . httpStatusCodeErrors , '5xx,401,403' , 'default http status code errors is 5xx,401,403' )
288288
@@ -295,21 +295,21 @@ test('HTTP Status Code Errors', (t) => {
295295} )
296296
297297test ( 'Logger levels' , ( t ) => {
298- config . clear ( )
298+ clear ( )
299299 const conf = require ( '../lib/config' ) . getConfig ( )
300300 t . deepEqual ( conf . loggerLevels , { 'default-logger' : 'WARN' } , 'default logger levels is =warn' )
301301
302- config . clear ( )
302+ clear ( )
303303 process . env [ 'PINPOINT_LOGGER_LEVELS' ] = 'grpc=INFO,sql=WARN,http=INFO'
304304 const confWithEnv = require ( '../lib/config' ) . getConfig ( )
305305 t . deepEqual ( confWithEnv . loggerLevels , { 'grpc' : 'INFO' , 'sql' : 'WARN' , 'http' : 'INFO' } , 'logger levels from env is grpc=INFO,sql=WARN,http=INFO' )
306306
307- config . clear ( )
307+ clear ( )
308308 process . env [ 'PINPOINT_LOGGER_LEVELS' ] = '.nemo=DEBUG'
309309 const confWithAppender = require ( '../lib/config' ) . getConfig ( )
310310 t . deepEqual ( confWithAppender . loggerLevels , { '.nemo' : 'DEBUG' } , 'logger levels from env is .nemo=DEBUG' )
311311
312- config . clear ( )
312+ clear ( )
313313 process . env [ 'PINPOINT_LOGGER_LEVELS' ] = 'grpc=DEBUG,sql=ERROR,http=TRACE'
314314 const confWithEnvDebug = require ( '../lib/config' ) . getConfig ( )
315315 t . deepEqual ( confWithEnvDebug . loggerLevels , { 'grpc' : 'DEBUG' , 'sql' : 'ERROR' , 'http' : 'TRACE' } , 'logger levels from env is grpc=DEBUG,sql=ERROR,http=TRACE' )
0 commit comments