From e649e027b724c6d685770735ae6083932943c656 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 16 Aug 2023 12:06:16 +0200 Subject: tests: Stop using global logrus logger Stop using the global logrus logger. In one case we can simply use the logger provided by `log.Configure()`, while in the other case we can instead use the logging facilities provided by `testing.TB`. --- internal/git/gittest/repo.go | 3 +-- internal/testhelper/configure.go | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go index baa30c0ea..8ee2dfb20 100644 --- a/internal/git/gittest/repo.go +++ b/internal/git/gittest/repo.go @@ -9,7 +9,6 @@ import ( "runtime" "testing" - log "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" gitalyauth "gitlab.com/gitlab-org/gitaly/v16/auth" "gitlab.com/gitlab-org/gitaly/v16/client" @@ -315,7 +314,7 @@ func testRepositoryPath(tb testing.TB, repo string) string { if !isValidRepoPath(path) { makePath := filepath.Join(filepath.Dir(currentFile), "..", "..", "..") makeTarget := "prepare-test-repos" - log.Printf("local clone of test repository %q not found in %q, running `make %v`", repo, path, makeTarget) + tb.Logf("local clone of test repository %q not found in %q, running `make %v`", repo, path, makeTarget) testhelper.MustRunCommand(tb, nil, "make", "-C", makePath, makeTarget) } diff --git a/internal/testhelper/configure.go b/internal/testhelper/configure.go index 7f165ca05..399e20bfc 100644 --- a/internal/testhelper/configure.go +++ b/internal/testhelper/configure.go @@ -8,9 +8,9 @@ import ( "runtime" "testing" - log "github.com/sirupsen/logrus" + "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" - gitalylog "gitlab.com/gitlab-org/gitaly/v16/internal/log" + "gitlab.com/gitlab-org/gitaly/v16/internal/log" ) var testDirectory string @@ -81,7 +81,7 @@ func Run(m *testing.M, opts ...RunOption) { // configure sets up the global test configuration. On failure, // terminates the program. func configure() (_ func(), returnedErr error) { - gitalylog.Configure(os.Stdout, "json", "panic") + logger := log.Configure(os.Stdout, "json", "panic") for key, value := range map[string]string{ // We inject the following two variables, which instruct Git to search its @@ -129,7 +129,7 @@ func configure() (_ func(), returnedErr error) { } } - cleanup, err := configureTestDirectory() + cleanup, err := configureTestDirectory(logger) if err != nil { return nil, fmt.Errorf("configuring test directory: %w", err) } @@ -142,7 +142,7 @@ func configure() (_ func(), returnedErr error) { return cleanup, nil } -func configureTestDirectory() (_ func(), returnedErr error) { +func configureTestDirectory(logger logrus.FieldLogger) (_ func(), returnedErr error) { if testDirectory != "" { return nil, errors.New("test directory has already been configured") } @@ -165,7 +165,7 @@ func configureTestDirectory() (_ func(), returnedErr error) { cleanup := func() { if err := os.RemoveAll(testDirectory); err != nil { - log.Errorf("cleaning up test directory: %v", err) + logger.Errorf("cleaning up test directory: %v", err) } } defer func() { -- cgit v1.2.3