-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpl_test.go
65 lines (57 loc) · 1.15 KB
/
gpl_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
61
62
63
64
65
package gpl
import (
"bytes"
"os"
"runtime"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRun(t *testing.T) {
CreateFakeRepositories()
expected := 0
os.Args = []string{
"gpl",
"testdata/project1",
"testdata/project2",
"testdata/project3",
"testdata/project4",
"testdata/project5",
}
assert.Equal(t, expected, DummyNew().Run(), "failed to gpl.Run")
RemoveFakeRepositories()
}
func DummyNew() *Gpl {
return &Gpl{
Stdin: os.Stdin,
Stdout: new(bytes.Buffer),
Stderr: new(bytes.Buffer),
CPU: runtime.NumCPU(),
Exec: func(path, command string, args ...string) (string, error) {
return "", nil
},
}
}
func CreateFakeRepositories() {
repositories := []string{
"testdata/project1/.git",
"testdata/project2/.git/svn",
"testdata/project3/.hg",
"testdata/project4/.svn",
"testdata/project5/_darcs",
}
for _, path := range repositories {
os.MkdirAll(path, 0755)
}
}
func RemoveFakeRepositories() {
repositories := []string{
"testdata/project1",
"testdata/project2",
"testdata/project3",
"testdata/project4",
"testdata/project5",
}
for _, path := range repositories {
os.RemoveAll(path)
}
}