@@ -293,6 +293,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
293293 name string
294294 content string
295295 expectedConfigContext * model.NginxConfigContext
296+ expectedLog string
296297 allowedDirectories []string
297298 }{
298299 {
@@ -312,6 +313,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
312313 protos .GetNginxOssInstance ([]string {}).GetInstanceMeta ().GetInstanceId (),
313314 []string {"127.0.0.1:1515" },
314315 ),
316+ expectedLog : "" ,
315317 allowedDirectories : []string {dir },
316318 },
317319 {
@@ -331,6 +333,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
331333 protos .GetNginxPlusInstance ([]string {}).GetInstanceMeta ().GetInstanceId (),
332334 []string {"127.0.0.1:1515" },
333335 ),
336+ expectedLog : "" ,
334337 allowedDirectories : []string {dir },
335338 },
336339 {
@@ -366,6 +369,7 @@ func TestNginxConfigParser_Parse(t *testing.T) {
366369 },
367370 NAPSysLogServers : nil ,
368371 },
372+ expectedLog : "" ,
369373 allowedDirectories : []string {dir },
370374 },
371375 {
@@ -383,6 +387,46 @@ func TestNginxConfigParser_Parse(t *testing.T) {
383387 },
384388 allowedDirectories : []string {dir },
385389 },
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+ },
386430 }
387431
388432 for _ , test := range tests {
@@ -403,9 +447,17 @@ func TestNginxConfigParser_Parse(t *testing.T) {
403447 agentConfig .AllowedDirectories = test .allowedDirectories
404448
405449 nginxConfig := NewNginxConfigParser (agentConfig )
450+
451+ logBuf := & bytes.Buffer {}
452+ stub .StubLoggerWith (logBuf )
453+
406454 result , parseError := nginxConfig .Parse (ctx , test .instance )
407455 require .NoError (t , parseError )
408456
457+ helpers .ValidateLog (t , test .expectedLog , logBuf )
458+
459+ logBuf .Reset ()
460+
409461 assert .ElementsMatch (t , test .expectedConfigContext .Files , result .Files )
410462 assert .Equal (t , test .expectedConfigContext .NAPSysLogServers , result .NAPSysLogServers )
411463 assert .Equal (t , test .expectedConfigContext .PlusAPI , result .PlusAPI )
0 commit comments