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

tmpdir.go « testhelpers « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de104a049429ff9a96eb0fd708271d5d9dc23b5b (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
package testhelpers

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

	"github.com/stretchr/testify/require"

	"gitlab.com/gitlab-org/gitlab-pages/internal/vfs"
	"gitlab.com/gitlab-org/gitlab-pages/internal/vfs/local"
)

var fs = vfs.Instrumented(&local.VFS{})

func TmpDir(tb testing.TB, pattern string) (vfs.Root, string) {
	tb.Helper()

	tmpDir, err := os.MkdirTemp("", pattern)
	require.NoError(tb, err)

	// On some systems `/tmp` can be a symlink
	tmpDir, err = filepath.EvalSymlinks(tmpDir)
	require.NoError(tb, err)

	root, err := fs.Root(context.Background(), tmpDir, "")
	require.NoError(tb, err)

	tb.Cleanup(func() {
		require.NoError(tb, os.RemoveAll(tmpDir))
	})

	return root, tmpDir
}