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
58
59
60
61
62
63
64
65
66
67
68
|
package repository
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestNewGoGitRepo(t *testing.T) {
// Plain
plainRoot, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(plainRoot)
_, err = InitGoGitRepo(plainRoot)
require.NoError(t, err)
plainGitDir := filepath.Join(plainRoot, ".git")
// Bare
bareRoot, err := ioutil.TempDir("", "")
require.NoError(t, err)
defer os.RemoveAll(bareRoot)
_, err = InitBareGoGitRepo(bareRoot)
require.NoError(t, err)
bareGitDir := bareRoot
tests := []struct {
inPath string
outPath string
err bool
}{
// errors
{"/", "", true},
// parent dir of a repo
{filepath.Dir(plainRoot), "", true},
// Plain repo
{plainRoot, plainGitDir, false},
{plainGitDir, plainGitDir, false},
{path.Join(plainGitDir, "objects"), plainGitDir, false},
// Bare repo
{bareRoot, bareGitDir, false},
{bareGitDir, bareGitDir, false},
{path.Join(bareGitDir, "objects"), bareGitDir, false},
}
for i, tc := range tests {
r, err := OpenGoGitRepo(tc.inPath, nil)
if tc.err {
require.Error(t, err, i)
} else {
require.NoError(t, err, i)
assert.Equal(t, filepath.ToSlash(tc.outPath), filepath.ToSlash(r.path), i)
}
}
}
func TestGoGitRepo(t *testing.T) {
RepoTest(t, CreateGoGitTestRepo, CleanupTestRepos)
}
|