-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit_t.go
114 lines (91 loc) · 1.94 KB
/
git_t.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package inspector
import (
"testing"
"github.com/libgit2/git2go"
)
const REPO_ENVY = "lazartravica/Envy"
const REPO_HEXY = "lazartravica/Hexy"
const REPO_GIT2GO = "libgit2/git2go"
const REPO_MUX = "gorilla/mux"
const REPO_CONSUL = "hashicorp/consul"
const REPO_DOCKER = "docker/docker"
func TestGetRepo(t *testing.T) {
repo, err := GetRepo(REPO_ENVY)
if err != nil {
t.Error(err)
}
defer repo.Free()
defer CleanTempDir()
}
func TestNumberOfCommits(t *testing.T) {
repo, err := GetRepo(REPO_HEXY)
if err != nil {
t.Error(err)
}
defer repo.Free()
defer CleanTempDir()
numberOfCommits, err :=GetNumberOfCommits(repo)
if err != nil {
t.Error(err)
}
if numberOfCommits != 41 {
t.Errorf("Number of commits is not 41, got: %d", numberOfCommits)
}
}
func TestRepoWalking(t *testing.T) {
repo, err := GetRepo(REPO_ENVY)
if err != nil {
t.Error(err)
}
defer repo.Free()
WalkCommits(repo, func(_, _ *git.Commit) bool {
return true
})
defer CleanTempDir()
}
func TestGetDiff(t *testing.T) {
repo, err := GetRepo(REPO_ENVY)
if err != nil {
t.Error(err)
}
defer repo.Free()
WalkCommits(repo, func(previous, current *git.Commit) bool {
diff, err := GetDiff(repo, previous, current)
if err != nil {
t.Error(err)
return false
}
defer diff.Free()
return true
})
defer CleanTempDir()
}
func TestWalkHunks(t *testing.T) {
repo, err := GetRepo(REPO_DOCKER)
if err != nil {
t.Error(err)
}
defer repo.Free()
defer CleanTempDir()
WalkCommits(repo, func(previous, current *git.Commit) bool {
diff, err := GetDiff(repo, previous, current)
if err != nil {
t.Error(err)
return false
}
defer diff.Free()
WalkHunks(diff, func(file git.DiffDelta, hunk git.DiffHunk) {
// time.Sleep(time.Millisecond)
})
return true
})
}
func TestListFiles(t *testing.T) {
repo, err := GetRepo(REPO_DOCKER)
if err != nil {
t.Error(err)
}
defer repo.Free()
defer CleanTempDir()
ListFilesInWorkingDir(REPO_DOCKER)
}