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:
authorPavlo Strokov <pstrokov@gitlab.com>2023-04-21 16:02:33 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2023-04-28 10:36:28 +0300
commit5fa62d4c1335758818850f6d868149f9208ba825 (patch)
tree9916b6306e428444b5e0f8efbea8ad245cdabe04
parent89a4d890c2441e3f3cf5affcdd868d1e21a48cd2 (diff)
praefect: Re-use config serialisation function in tests
-rw-r--r--internal/cli/praefect/subcmd_accept_dataloss_test.go10
-rw-r--r--internal/cli/praefect/subcmd_check_test.go11
-rw-r--r--internal/cli/praefect/subcmd_dataloss_test.go13
3 files changed, 4 insertions, 30 deletions
diff --git a/internal/cli/praefect/subcmd_accept_dataloss_test.go b/internal/cli/praefect/subcmd_accept_dataloss_test.go
index b2244f480..5348b8f5b 100644
--- a/internal/cli/praefect/subcmd_accept_dataloss_test.go
+++ b/internal/cli/praefect/subcmd_accept_dataloss_test.go
@@ -2,14 +2,10 @@ package praefect
import (
"context"
- "os"
- "path/filepath"
"testing"
- "github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
- "gitlab.com/gitlab-org/gitaly/v15/internal/helper/perm"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/service/info"
@@ -66,11 +62,7 @@ func TestAcceptDatalossSubcommand(t *testing.T) {
defer clean()
conf.SocketPath = ln.Addr().String()
- tmpDir := testhelper.TempDir(t)
- confData, err := toml.Marshal(conf)
- require.NoError(t, err)
- confPath := filepath.Join(tmpDir, "config.toml")
- require.NoError(t, os.WriteFile(confPath, confData, perm.PublicFile))
+ confPath := writeConfigToFile(t, conf)
type errorMatcher func(t *testing.T, err error)
diff --git a/internal/cli/praefect/subcmd_check_test.go b/internal/cli/praefect/subcmd_check_test.go
index aaedc3846..a37bb5b6f 100644
--- a/internal/cli/praefect/subcmd_check_test.go
+++ b/internal/cli/praefect/subcmd_check_test.go
@@ -5,15 +5,10 @@ import (
"context"
"errors"
"io"
- "os"
- "path/filepath"
"testing"
- "github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
- "gitlab.com/gitlab-org/gitaly/v15/internal/helper/perm"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/service"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
@@ -33,11 +28,7 @@ func TestCheckSubcommand(t *testing.T) {
},
}
- tmpDir := testhelper.TempDir(t)
- confData, err := toml.Marshal(conf)
- require.NoError(t, err)
- confPath := filepath.Join(tmpDir, "config.toml")
- require.NoError(t, os.WriteFile(confPath, confData, perm.PublicFile))
+ confPath := writeConfigToFile(t, conf)
testCases := []struct {
desc string
diff --git a/internal/cli/praefect/subcmd_dataloss_test.go b/internal/cli/praefect/subcmd_dataloss_test.go
index de62e8ae6..cb6dd19d6 100644
--- a/internal/cli/praefect/subcmd_dataloss_test.go
+++ b/internal/cli/praefect/subcmd_dataloss_test.go
@@ -2,14 +2,10 @@ package praefect
import (
"bytes"
- "os"
- "path/filepath"
"testing"
- "github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
- "gitlab.com/gitlab-org/gitaly/v15/internal/helper/perm"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/datastore"
"gitlab.com/gitlab-org/gitaly/v15/internal/praefect/service/info"
@@ -182,12 +178,7 @@ Virtual storage: virtual-storage-2
} {
t.Run(tc.desc, func(t *testing.T) {
cfg.VirtualStorages = tc.virtualStorages
-
- confData, err := toml.Marshal(cfg)
- require.NoError(t, err)
- tmpDir := testhelper.TempDir(t)
- confPath := filepath.Join(tmpDir, "config.toml")
- require.NoError(t, os.WriteFile(confPath, confData, perm.PublicFile))
+ confPath := writeConfigToFile(t, cfg)
var stdout bytes.Buffer
app := cli.App{
@@ -203,7 +194,7 @@ Virtual storage: virtual-storage-2
},
}
- err = app.Run(append([]string{progname, "dataloss"}, tc.args...))
+ err := app.Run(append([]string{progname, "dataloss"}, tc.args...))
require.Equal(t, tc.error, err, err)
if tc.error == nil {
require.Equal(t, tc.output, stdout.String())