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

packfile_test.go « packfile « git « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9bad0bfd740d25c1a26e0d695948fe1ddd3eab95 (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 packfile_test

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

	"github.com/stretchr/testify/require"
	"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
	"gitlab.com/gitlab-org/gitaly/internal/git/packfile"
	"gitlab.com/gitlab-org/gitaly/internal/testhelper"
	"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
)

func TestMain(m *testing.M) {
	os.Exit(testMain(m))
}

func testMain(m *testing.M) int {
	defer testhelper.MustHaveNoChildProcess()
	cleanup := testhelper.Configure()
	defer cleanup()
	return m.Run()
}

func TestList(t *testing.T) {
	cfg := testcfg.Build(t)
	tempDir := testhelper.TempDir(t)

	emptyRepo := filepath.Join(tempDir, "empty.git")
	gittest.Exec(t, cfg, "init", "--bare", emptyRepo)

	populatedRepo := filepath.Join(tempDir, "populated")
	gittest.Exec(t, cfg, "init", populatedRepo)
	for i := 0; i < 10; i++ {
		gittest.Exec(t, cfg, "-C", populatedRepo, "commit",
			"--allow-empty", "--message", "commit message")
	}
	gittest.Exec(t, cfg, "-C", populatedRepo, "repack", "-ad")

	testCases := []struct {
		desc     string
		path     string
		numPacks int
	}{
		{desc: "empty", path: emptyRepo},
		{desc: "1 pack no alternates", path: filepath.Join(populatedRepo, ".git"), numPacks: 1},
	}

	for _, tc := range testCases {
		t.Run(tc.desc, func(t *testing.T) {
			out, err := packfile.List(filepath.Join(tc.path, "objects"))
			require.NoError(t, err)
			require.Len(t, out, tc.numPacks)
		})
	}
}