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

testhelper_test.go « gittest « git « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47cefc0cd3567ec20d924e19d447b339f7cff7eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package gittest

import (
	"os"
	"path/filepath"
	"runtime"
	"testing"

	"github.com/stretchr/testify/require"
	"gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/config"
	"gitlab.com/gitlab-org/gitaly/v14/internal/testhelper"
	"gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb"
)

func TestMain(m *testing.M) {
	testhelper.Run(m)
}

// setup sets up a test configuration and repository. Ideally we'd use our central test helpers to
// do this, but because of an import cycle we can't.
func setup(t testing.TB) (config.Cfg, *gitalypb.Repository, string) {
	t.Helper()

	rootDir := testhelper.TempDir(t)

	var cfg config.Cfg

	cfg.SocketPath = "it is a stub to bypass Validate method"

	cfg.Storages = []config.Storage{
		{
			Name: "default",
			Path: filepath.Join(rootDir, "storage.d"),
		},
	}
	require.NoError(t, os.Mkdir(cfg.Storages[0].Path, 0o755))

	_, currentFile, _, ok := runtime.Caller(0)
	require.True(t, ok, "could not get caller info")
	cfg.Ruby.Dir = filepath.Join(filepath.Dir(currentFile), "../../../ruby")

	cfg.GitlabShell.Dir = filepath.Join(rootDir, "shell.d")
	require.NoError(t, os.Mkdir(cfg.GitlabShell.Dir, 0o755))

	cfg.BinDir = filepath.Join(rootDir, "bin.d")
	require.NoError(t, os.Mkdir(cfg.BinDir, 0o755))

	cfg.RuntimeDir = filepath.Join(rootDir, "run.d")
	require.NoError(t, os.Mkdir(cfg.RuntimeDir, 0o700))
	require.NoError(t, os.Mkdir(cfg.InternalSocketDir(), 0o700))

	require.NoError(t, cfg.Validate())

	repo, repoPath := CloneRepo(t, cfg, cfg.Storages[0])

	return cfg, repo, repoPath
}