@@ -707,33 +707,65 @@ func TestConfigureWithCore(t *testing.T) {
707707		zapcore .NewJSONEncoder (zap .NewProductionEncoderConfig ()),
708708		zapcore .AddSync (& b ),
709709		zapcore .InfoLevel )
710- 	err  :=  ConfigureWithCore (Config {}, core )
711- 	if  err  !=  nil  {
712- 		t .Fatalf ("Unexpected err: %s" , err )
713- 	}
714- 	Info ("The quick brown %s jumped over the lazy %s." , "fox" , "dog" )
715- 	var  r  map [string ]interface {}
716710
717- 	err  =  json .Unmarshal (b .Bytes (), & r )
718- 	if  err  !=  nil  {
719- 		t .Fatalf ("unable to json unmarshal '%s': %s" , b .String (), err )
720- 	}
711+ 	t .Run ("test default config" , func (t  * testing.T ) {
712+ 		err  :=  ConfigureWithCore (Config {}, core )
713+ 		if  err  !=  nil  {
714+ 			t .Fatalf ("Unexpected err: %s" , err )
715+ 		}
716+ 		Info ("The quick brown %s jumped over the lazy %s." , "fox" , "dog" )
717+ 		var  r  map [string ]interface {}
721718
722- 	val , prs  :=  r ["msg" ]
723- 	if  ! prs  {
724- 		t .Fatalf ("expected 'msg' field not present in '%s'" , b .String ())
725- 	}
726- 	if  val  !=  testMsg  {
727- 		t .Fatalf ("expected msg of '%s', got '%s'" , testMsg , val )
728- 	}
719+ 		err  =  json .Unmarshal (b .Bytes (), & r )
720+ 		if  err  !=  nil  {
721+ 			t .Fatalf ("unable to json unmarshal '%s': %s" , b .String (), err )
722+ 		}
723+ 
724+ 		val , prs  :=  r ["msg" ]
725+ 		if  ! prs  {
726+ 			t .Fatalf ("expected 'msg' field not present in '%s'" , b .String ())
727+ 		}
728+ 		if  val  !=  testMsg  {
729+ 			t .Fatalf ("expected msg of '%s', got '%s'" , testMsg , val )
730+ 		}
731+ 		val , prs  =  r ["level" ]
732+ 		if  ! prs  {
733+ 			t .Fatalf ("expected 'level' field not present in '%s'" , b .String ())
734+ 		}
735+ 		if  val  !=  "info"  {
736+ 			t .Fatalf ("expected log.level of 'info', got '%s'" , val )
737+ 		}
738+ 	})
739+ 
740+ 	b .Reset ()
741+ 	t .Run ("test `with_fields` config" , func (t  * testing.T ) {
742+ 		config  :=  Config {
743+ 			WithFields : map [string ]any {
744+ 				"component" : "elastic-agent" ,
745+ 			},
746+ 		}
747+ 		err  :=  ConfigureWithCore (config , core )
748+ 		if  err  !=  nil  {
749+ 			t .Fatalf ("Unexpected err: %s" , err )
750+ 		}
751+ 		Info ("The quick brown %s jumped over the lazy %s." , "fox" , "dog" )
752+ 		var  r  map [string ]interface {}
753+ 
754+ 		err  =  json .Unmarshal (b .Bytes (), & r )
755+ 		if  err  !=  nil  {
756+ 			t .Fatalf ("unable to json unmarshal '%s': %s" , b .String (), err )
757+ 		}
758+ 		// test `with_fields` works correctly 
759+ 		expectedMsg  :=  "elastic-agent" 
760+ 		val , prs  :=  r ["component" ]
761+ 		if  ! prs  {
762+ 			t .Fatalf ("expected 'component' field not present in '%s'" , b .String ())
763+ 		}
764+ 		if  val  !=  expectedMsg  {
765+ 			t .Fatalf ("expected msg of '%s', got '%s'" , expectedMsg , val )
766+ 		}
767+ 	})
729768
730- 	val , prs  =  r ["level" ]
731- 	if  ! prs  {
732- 		t .Fatalf ("expected 'level' field not present in '%s'" , b .String ())
733- 	}
734- 	if  val  !=  "info"  {
735- 		t .Fatalf ("expected log.level of 'info', got '%s'" , val )
736- 	}
737769}
738770
739771func  strField (key , val  string ) zapcore.Field  {
0 commit comments