@@ -17,7 +17,7 @@ import (
1717// buildRudderServerBinary builds the rudder-server binary and returns its path.
1818func buildRudderServerBinary (t * testing.T , binaryPath string ) {
1919 name := "testbinary"
20- buildCmd := exec .Command ("go" , "build" , "-o" , binaryPath , "../../main.go" )
20+ buildCmd := exec .Command ("go" , "build" , "-cover" , "- o" , binaryPath , "../../main.go" )
2121 buildCmd .Stderr = os .Stderr
2222 buildCmd .Stdout = os .Stdout
2323 if err := buildCmd .Run (); err != nil {
@@ -26,8 +26,10 @@ func buildRudderServerBinary(t *testing.T, binaryPath string) {
2626}
2727
2828// startRudderServer starts a rudder-server process with the given environment configuration in a separate goroutine managed by the provided errgroup.Group.
29- func startRudderServer (ctx context.Context , g * errgroup.Group , name , binaryPath string , configs map [string ]string ) {
29+ func startRudderServer (t * testing. T , ctx context.Context , g * errgroup.Group , name , binaryPath string , configs map [string ]string ) {
3030 g .Go (func () error {
31+ coverDir := t .TempDir ()
32+ configs ["GOCOVERDIR" ] = coverDir
3133 cmd := exec .CommandContext (ctx , binaryPath )
3234 cmd .Env = append (os .Environ (), lo .MapToSlice (configs , func (k , v string ) string {
3335 return config .ConfigKeyToEnv (config .DefaultEnvPrefix , k ) + "=" + v
@@ -37,6 +39,7 @@ func startRudderServer(ctx context.Context, g *errgroup.Group, name, binaryPath
3739 if err := cmd .Start (); err != nil {
3840 return fmt .Errorf ("server %q: failed to start: %w" , name , err )
3941 }
42+ defer convertCoverageData (t , coverDir , name + "-profile.out" )
4043 if err := cmd .Wait (); err != nil {
4144 if exitErr , ok := err .(* exec.ExitError ); ok {
4245 if status , ok := exitErr .Sys ().(syscall.WaitStatus ); ok {
@@ -50,3 +53,11 @@ func startRudderServer(ctx context.Context, g *errgroup.Group, name, binaryPath
5053 return nil
5154 })
5255}
56+
57+ func convertCoverageData (t * testing.T , coverDir , outputFile string ) {
58+ cmd := exec .Command ("go" , "tool" , "covdata" , "textfmt" , "-i=" + coverDir , "-o=" + outputFile )
59+ cmd .Stderr = os .Stderr
60+ if err := cmd .Run (); err != nil {
61+ t .Logf ("failed to convert coverage data: %v" , err )
62+ }
63+ }
0 commit comments