Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2020-11-13 10:25:09 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2020-11-17 10:07:45 +0300
commitd250926f3cadd7ee281819f6f3333c6e9a08c18c (patch)
treeac329ada5859a0acfca78a04bd43786a18948f6a
parentcc1fa4a1f1135a4aa76f08fbf5321c29755b81a5 (diff)
tests: Don't call log.Fatal in test setups
Because the `TestMain()` function doesn't yet have a proper test context which could be used to fail tests, we use `log.Fatal` to abort the whole test suite in case test setup fails. This has the downside though that it'll cause us to not execute any deferred funcitons, as it essentially boils down to a `log.Error()` followed by `os.Exit()`. Fix the issue by instead using `log.Error()` followed by returning an error return code.
-rw-r--r--cmd/gitaly-hooks/hooks_test.go5
-rw-r--r--internal/gitaly/service/blob/testhelper_test.go5
-rw-r--r--internal/gitaly/service/conflicts/testhelper_test.go6
-rw-r--r--internal/gitaly/service/namespace/namespace_test.go8
-rw-r--r--internal/gitaly/service/operations/testhelper_test.go9
-rw-r--r--internal/gitaly/service/remote/testhelper_test.go5
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go8
-rw-r--r--internal/gitaly/service/smarthttp/testhelper_test.go5
-rw-r--r--internal/gitaly/service/ssh/testhelper_test.go3
-rw-r--r--internal/gitaly/service/wiki/testhelper_test.go6
-rw-r--r--internal/praefect/replicator_test.go7
-rw-r--r--internal/supervisor/supervisor_test.go11
12 files changed, 49 insertions, 29 deletions
diff --git a/cmd/gitaly-hooks/hooks_test.go b/cmd/gitaly-hooks/hooks_test.go
index 98c04a36c..7c9d50bb9 100644
--- a/cmd/gitaly-hooks/hooks_test.go
+++ b/cmd/gitaly-hooks/hooks_test.go
@@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
- "log"
"os"
"os/exec"
"path"
@@ -14,6 +13,7 @@ import (
"strings"
"testing"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
@@ -41,7 +41,8 @@ func testMain(m *testing.M) int {
rubyDir, err := filepath.Abs("../../ruby")
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
config.Config.Ruby.Dir = rubyDir
diff --git a/internal/gitaly/service/blob/testhelper_test.go b/internal/gitaly/service/blob/testhelper_test.go
index 7c23ed835..600ff98f2 100644
--- a/internal/gitaly/service/blob/testhelper_test.go
+++ b/internal/gitaly/service/blob/testhelper_test.go
@@ -1,10 +1,10 @@
package blob
import (
- "log"
"os"
"testing"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/storage"
@@ -28,7 +28,8 @@ func testMain(m *testing.M) int {
testhelper.ConfigureRuby()
if err := rubyServer.Start(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer rubyServer.Stop()
diff --git a/internal/gitaly/service/conflicts/testhelper_test.go b/internal/gitaly/service/conflicts/testhelper_test.go
index 21ff9dee6..ac56960a6 100644
--- a/internal/gitaly/service/conflicts/testhelper_test.go
+++ b/internal/gitaly/service/conflicts/testhelper_test.go
@@ -31,7 +31,8 @@ func testMain(m *testing.M) int {
tempDir, err := ioutil.TempDir("", "gitaly")
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer os.RemoveAll(tempDir)
@@ -39,7 +40,8 @@ func testMain(m *testing.M) int {
config.Config.InternalSocketDir = tempDir + "/sock"
if err := RubyServer.Start(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer RubyServer.Stop()
diff --git a/internal/gitaly/service/namespace/namespace_test.go b/internal/gitaly/service/namespace/namespace_test.go
index c9aeb1396..9ba79e109 100644
--- a/internal/gitaly/service/namespace/namespace_test.go
+++ b/internal/gitaly/service/namespace/namespace_test.go
@@ -1,11 +1,11 @@
package namespace
import (
- "log"
"os"
"path/filepath"
"testing"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/helper"
@@ -30,11 +30,13 @@ func testMain(m *testing.M) int {
for _, st := range []string{"default", "other"} {
dir, err := filepath.Abs(filepath.Join("testdata", st))
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
if err := os.RemoveAll(dir); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
config.Config.Storages = append(config.Config.Storages,
diff --git a/internal/gitaly/service/operations/testhelper_test.go b/internal/gitaly/service/operations/testhelper_test.go
index b75fd346f..47567c886 100644
--- a/internal/gitaly/service/operations/testhelper_test.go
+++ b/internal/gitaly/service/operations/testhelper_test.go
@@ -49,13 +49,15 @@ func testMain(m *testing.M) int {
cwd, err := os.Getwd()
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
gitlabShellDir := filepath.Join(cwd, "testdata", "gitlab-shell")
os.RemoveAll(gitlabShellDir)
if err := os.MkdirAll(gitlabShellDir, 0755); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
config.Config.GitlabShell.Dir = filepath.Join(cwd, "testdata", "gitlab-shell")
@@ -73,7 +75,8 @@ func testMain(m *testing.M) int {
defer cleanupSrv()
if err := RubyServer.Start(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer RubyServer.Stop()
diff --git a/internal/gitaly/service/remote/testhelper_test.go b/internal/gitaly/service/remote/testhelper_test.go
index 9a0769661..c269a713b 100644
--- a/internal/gitaly/service/remote/testhelper_test.go
+++ b/internal/gitaly/service/remote/testhelper_test.go
@@ -1,10 +1,10 @@
package remote
import (
- "log"
"os"
"testing"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
@@ -28,7 +28,8 @@ func testMain(m *testing.M) int {
testhelper.ConfigureGitalySSH()
if err := RubyServer.Start(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer RubyServer.Stop()
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 3c2777c12..aea1a3b21 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -2,12 +2,12 @@ package repository
import (
"crypto/x509"
- "log"
"os"
"path/filepath"
"testing"
"time"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
@@ -49,13 +49,15 @@ func testMain(m *testing.M) int {
var err error
config.Config.GitlabShell.Dir, err = filepath.Abs("testdata/gitlab-shell")
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
testhelper.ConfigureGitalySSH()
if err := RubyServer.Start(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer RubyServer.Stop()
diff --git a/internal/gitaly/service/smarthttp/testhelper_test.go b/internal/gitaly/service/smarthttp/testhelper_test.go
index d432e7297..bb8cbe4f5 100644
--- a/internal/gitaly/service/smarthttp/testhelper_test.go
+++ b/internal/gitaly/service/smarthttp/testhelper_test.go
@@ -1,11 +1,11 @@
package smarthttp
import (
- "log"
"os"
"path/filepath"
"testing"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
gitalyauth "gitlab.com/gitlab-org/gitaly/auth"
diskcache "gitlab.com/gitlab-org/gitaly/internal/cache"
@@ -37,7 +37,8 @@ func testMain(m *testing.M) int {
cwd, err := os.Getwd()
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
config.Config.Ruby.Dir = filepath.Join(cwd, "../../../../ruby")
diff --git a/internal/gitaly/service/ssh/testhelper_test.go b/internal/gitaly/service/ssh/testhelper_test.go
index b3c0ded90..da2d79083 100644
--- a/internal/gitaly/service/ssh/testhelper_test.go
+++ b/internal/gitaly/service/ssh/testhelper_test.go
@@ -42,7 +42,8 @@ func testMain(m *testing.M) int {
err := os.RemoveAll(testPath)
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
testRepo = testhelper.TestRepository()
diff --git a/internal/gitaly/service/wiki/testhelper_test.go b/internal/gitaly/service/wiki/testhelper_test.go
index 31946d0e7..65697c0ff 100644
--- a/internal/gitaly/service/wiki/testhelper_test.go
+++ b/internal/gitaly/service/wiki/testhelper_test.go
@@ -45,7 +45,8 @@ func testMain(m *testing.M) int {
tempDir, err := ioutil.TempDir("", "gitaly")
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer os.RemoveAll(tempDir)
@@ -53,7 +54,8 @@ func testMain(m *testing.M) int {
config.Config.InternalSocketDir = tempDir + "/sock"
if err := rubyServer.Start(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer rubyServer.Stop()
diff --git a/internal/praefect/replicator_test.go b/internal/praefect/replicator_test.go
index 63529911e..9fb08e983 100644
--- a/internal/praefect/replicator_test.go
+++ b/internal/praefect/replicator_test.go
@@ -3,7 +3,6 @@ package praefect
import (
"context"
"io/ioutil"
- "log"
"net"
"os"
"path/filepath"
@@ -65,13 +64,15 @@ func testMain(m *testing.M) int {
var err error
gitaly_config.Config.GitlabShell.Dir, err = filepath.Abs("testdata/gitlab-shell")
if err != nil {
- log.Fatal(err)
+ logrus.Error(err)
+ return 1
}
testhelper.ConfigureGitalySSH()
if err := RubyServer.Start(); err != nil {
- log.Fatal(err)
+ logrus.Error(err)
+ return 1
}
defer RubyServer.Stop()
diff --git a/internal/supervisor/supervisor_test.go b/internal/supervisor/supervisor_test.go
index 2af3b655f..5cde07fe3 100644
--- a/internal/supervisor/supervisor_test.go
+++ b/internal/supervisor/supervisor_test.go
@@ -3,7 +3,6 @@ package supervisor
import (
"context"
"io/ioutil"
- "log"
"net"
"os"
"os/exec"
@@ -13,6 +12,7 @@ import (
"testing"
"time"
+ log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
@@ -33,13 +33,15 @@ func testMain(m *testing.M) int {
var err error
testDir, err = ioutil.TempDir("", "gitaly-supervisor-test")
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
defer os.RemoveAll(testDir)
scriptPath, err := filepath.Abs("test-scripts/pid-server.go")
if err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
testExe = filepath.Join(testDir, "pid-server")
@@ -48,7 +50,8 @@ func testMain(m *testing.M) int {
buildCmd.Stderr = os.Stderr
buildCmd.Stdout = os.Stdout
if err := buildCmd.Run(); err != nil {
- log.Fatal(err)
+ log.Error(err)
+ return 1
}
socketPath = filepath.Join(testDir, "socket")