-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
commands_test.go
60 lines (52 loc) · 1.26 KB
/
commands_test.go
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
package main
import (
"net/url"
"path/filepath"
"sync"
"testing"
)
type _cloneArgs struct {
remote *url.URL
local string
shallow bool
branch string
recursive bool
bare bool
}
type _updateArgs struct {
local string
}
func withFakeGitBackend(t *testing.T, block func(*testing.T, string, *_cloneArgs, *_updateArgs)) {
tmpRoot := newTempDir(t)
defer func(orig []string) { _localRepositoryRoots = orig }(_localRepositoryRoots)
_localRepositoryRoots = []string{tmpRoot}
var cloneArgs _cloneArgs
var updateArgs _updateArgs
var originalGitBackend = GitBackend
tmpBackend := &VCSBackend{
Clone: func(vg *vcsGetOption) error {
cloneArgs = _cloneArgs{
remote: vg.url,
local: filepath.FromSlash(vg.dir),
shallow: vg.shallow,
branch: vg.branch,
recursive: vg.recursive,
bare: vg.bare,
}
return nil
},
Update: func(vg *vcsGetOption) error {
updateArgs = _updateArgs{
local: vg.dir,
}
return nil
},
}
defer func(orig string) { _home = orig }(_home)
_home = ""
homeOnce = &sync.Once{}
GitBackend = tmpBackend
vcsContentsMap[".git"] = tmpBackend
defer func() { GitBackend = originalGitBackend; vcsContentsMap[".git"] = originalGitBackend }()
block(t, tmpRoot, &cloneArgs, &updateArgs)
}