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
|
package tempdir
import (
"context"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
)
func TestNewRepositorySuccess(t *testing.T) {
ctx, cancel := context.WithCancel(testhelper.Context(t))
cfg := testcfg.Build(t)
locator := config.NewLocator(cfg)
repo, tempDir, err := NewRepository(ctx, cfg.Storages[0].Name, locator)
require.NoError(t, err)
require.Equal(t, cfg.Storages[0].Name, repo.StorageName)
require.Contains(t, repo.RelativePath, tmpRootPrefix)
calculatedPath, err := locator.GetPath(repo)
require.NoError(t, err)
require.Equal(t, tempDir.Path(), calculatedPath)
require.NoError(t, os.WriteFile(filepath.Join(tempDir.Path(), "test"), []byte("hello"), 0o644))
require.DirExists(t, tempDir.Path())
cancel() // This should trigger async removal of the temporary directory
tempDir.WaitForCleanup()
require.NoDirExists(t, tempDir.Path())
}
func TestNewWithPrefix(t *testing.T) {
cfg := testcfg.Build(t)
locator := config.NewLocator(cfg)
ctx := testhelper.Context(t)
dir, err := NewWithPrefix(ctx, cfg.Storages[0].Name, "foobar-", locator)
require.NoError(t, err)
require.Contains(t, dir.Path(), "/foobar-")
}
func TestNewAsRepositoryFailStorageUnknown(t *testing.T) {
ctx := testhelper.Context(t)
_, err := New(ctx, "does-not-exist", config.NewLocator(config.Cfg{}))
require.Error(t, err)
}
|