@@ -293,6 +293,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
293
293
name string
294
294
content string
295
295
expectedConfigContext * model.NginxConfigContext
296
+ expectedLog string
296
297
allowedDirectories []string
297
298
}{
298
299
{
@@ -312,6 +313,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
312
313
protos .GetNginxOssInstance ([]string {}).GetInstanceMeta ().GetInstanceId (),
313
314
[]string {"127.0.0.1:1515" },
314
315
),
316
+ expectedLog : "" ,
315
317
allowedDirectories : []string {dir },
316
318
},
317
319
{
@@ -331,6 +333,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
331
333
protos .GetNginxPlusInstance ([]string {}).GetInstanceMeta ().GetInstanceId (),
332
334
[]string {"127.0.0.1:1515" },
333
335
),
336
+ expectedLog : "" ,
334
337
allowedDirectories : []string {dir },
335
338
},
336
339
{
@@ -366,6 +369,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
366
369
},
367
370
NAPSysLogServers : nil ,
368
371
},
372
+ expectedLog : "" ,
369
373
allowedDirectories : []string {dir },
370
374
},
371
375
{
@@ -383,6 +387,46 @@ func TestNginxConfigParser_Parse(t *testing.T) {
383
387
},
384
388
allowedDirectories : []string {dir },
385
389
},
390
+ {
391
+ name : "Test 5: Error Log outputting to stderr" ,
392
+ instance : protos .GetNginxPlusInstance ([]string {}),
393
+ content : testconfig .GetNginxConfigWithMultipleAccessLogs (
394
+ "stderr" ,
395
+ accessLog .Name (),
396
+ combinedAccessLog .Name (),
397
+ ltsvAccessLog .Name (),
398
+ ),
399
+ expectedConfigContext : modelHelpers .GetConfigContextWithoutErrorLog (
400
+ accessLog .Name (),
401
+ combinedAccessLog .Name (),
402
+ ltsvAccessLog .Name (),
403
+ protos .GetNginxPlusInstance ([]string {}).GetInstanceMeta ().GetInstanceId (),
404
+ []string {"127.0.0.1:1515" },
405
+ ),
406
+ expectedLog : "Currently error log outputs to stderr. Log monitoring is disabled while applying a " +
407
+ "config; log errors to file to enable error monitoring" ,
408
+ allowedDirectories : []string {dir },
409
+ },
410
+ {
411
+ name : "Test 6: Error Log outputting to stdout" ,
412
+ instance : protos .GetNginxPlusInstance ([]string {}),
413
+ content : testconfig .GetNginxConfigWithMultipleAccessLogs (
414
+ "stdout" ,
415
+ accessLog .Name (),
416
+ combinedAccessLog .Name (),
417
+ ltsvAccessLog .Name (),
418
+ ),
419
+ expectedConfigContext : modelHelpers .GetConfigContextWithoutErrorLog (
420
+ accessLog .Name (),
421
+ combinedAccessLog .Name (),
422
+ ltsvAccessLog .Name (),
423
+ protos .GetNginxPlusInstance ([]string {}).GetInstanceMeta ().GetInstanceId (),
424
+ []string {"127.0.0.1:1515" },
425
+ ),
426
+ expectedLog : "Currently error log outputs to stdout. Log monitoring is disabled while applying a " +
427
+ "config; log errors to file to enable error monitoring" ,
428
+ allowedDirectories : []string {dir },
429
+ },
386
430
}
387
431
388
432
for _ , test := range tests {
@@ -403,9 +447,17 @@ func TestNginxConfigParser_Parse(t *testing.T) {
403
447
agentConfig .AllowedDirectories = test .allowedDirectories
404
448
405
449
nginxConfig := NewNginxConfigParser (agentConfig )
450
+
451
+ logBuf := & bytes.Buffer {}
452
+ stub .StubLoggerWith (logBuf )
453
+
406
454
result , parseError := nginxConfig .Parse (ctx , test .instance )
407
455
require .NoError (t , parseError )
408
456
457
+ helpers .ValidateLog (t , test .expectedLog , logBuf )
458
+
459
+ logBuf .Reset ()
460
+
409
461
assert .ElementsMatch (t , test .expectedConfigContext .Files , result .Files )
410
462
assert .Equal (t , test .expectedConfigContext .NAPSysLogServers , result .NAPSysLogServers )
411
463
assert .Equal (t , test .expectedConfigContext .PlusAPI , result .PlusAPI )
0 commit comments