-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrepository_store_test.go
53 lines (42 loc) · 1.3 KB
/
repository_store_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
package main
import (
"os/exec"
"strings"
"testing"
)
func execCommand(command string) string {
cmd := exec.Command("bash", "-c", command)
output, _ := cmd.Output()
return strings.Trim(string(output), " \n")
}
func errToBool(err error) bool {
if err == nil {
return false
}
return true
}
func TestGitRepositoryStore_GetRepository(t *testing.T) {
execCommand("cd fixtures/depot/project-x && rm -rf non-bare-repo-a && git clone repo-a.git non-bare-repo-a")
var tests = []struct {
repoPath string
actualRepoPath string
error bool
}{
{"project-x/repo-a.git", "fixtures/depot/project-x/repo-a.git", false},
{"project-x/non-bare-repo-a", "fixtures/depot/project-x/non-bare-repo-a/.git", false},
{"/project-y/repo-b.git/", "fixtures/depot/project-y/repo-b.git", false},
{"project-x/non-existent.git", "", true},
{"project-z/repo-b.git", "", true},
{"", "", true},
}
store := &GitRepositoryStore{"fixtures/depot"}
for _, test := range tests {
repo, err := store.GetRepository(test.repoPath)
if errToBool(err) != test.error {
t.Errorf("expected error to be %v for %v, got %v", test.error, test, err)
}
if err == nil && repo.Path() != test.actualRepoPath {
t.Errorf("expected actualRepoPath to be %v for %v, got %v", test.actualRepoPath, test, repo.Path())
}
}
}