main: rework the way the mock logger is passed

Pass the mock logger directly to `run()` instead of mocking
`logrus.New`. Doing the later leads to a data race when multiple
parallel tests modify the (global) `var logrusNew logrus.New`.

Thanks to Tomas Hozza for reporting.
This commit is contained in:
Michael Vogt 2024-06-06 17:36:31 +02:00
parent 95b4a9e250
commit 8ebefbdbc9
3 changed files with 7 additions and 24 deletions

View file

@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/sirupsen/logrus"
logrusTest "github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
@ -57,8 +58,8 @@ func runTestServer(t *testing.T) (baseURL, buildBaseDir string, loggerHook *logr
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
loggerHook, restore := main.MockLogger()
defer restore()
logger, loggerHook := logrusTest.NewNullLogger()
logger.SetLevel(logrus.DebugLevel)
args := []string{
"-host", host,
@ -66,7 +67,7 @@ func runTestServer(t *testing.T) (baseURL, buildBaseDir string, loggerHook *logr
"-build-path", buildBaseDir,
}
go func() {
_ = main.Run(ctx, args, os.Getenv)
_ = main.Run(ctx, args, os.Getenv, logger)
}()
err := waitReady(ctx, defaultTimeout, baseURL)