-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathgit_test.go
105 lines (100 loc) · 1.88 KB
/
git_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
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
package config
import (
"testing"
"github.com/matryer/is"
)
func TestNewRepoSource(t *testing.T) {
repoPath := "./testdata"
rs, err := NewRepoSource(repoPath)
repos := []string{
"z-repo",
"1-repo",
"a-repo",
"m-repo",
"b-repo",
}
for _, r := range repos {
rs.InitRepo(r, true)
}
is := is.New(t)
is.NoErr(err)
is.Equal(len(rs.repos), 5) // there should be 5 repos
}
func TestOrderReposAlphabetically(t *testing.T) {
repoPath := "./testdata"
rs, err := NewRepoSource(repoPath)
repos := []string{
"z-repo",
"1-repo",
"a-repo",
"m-repo",
"b-repo",
}
for _, r := range repos {
rs.InitRepo(r, true)
}
rs.Sort("alphabetical", []RepoConfig{})
expected := map[string]int{ // repos and their expected index
"1-repo": 0,
"a-repo": 1,
"b-repo": 2,
"m-repo": 3,
"z-repo": 4,
}
result := rs.AllRepos() // as returned from ls command
is := is.New(t)
is.NoErr(err)
for i, repo := range result {
is.Equal(expected[repo.Repo()], i) // repos should be alphabetically ordered
}
}
func TestOrderReposConfig(t *testing.T) {
repoPath := "./testdata"
rs, err := NewRepoSource(repoPath)
config := []RepoConfig{
{
Name: "test-repo-a",
Repo: "a-repo",
},
{
Name: "test-repo-1",
Repo: "1-repo",
},
{
Name: "test-repo-z",
Repo: "z-repo",
},
{
Name: "test-repo-b",
Repo: "b-repo",
},
{
Name: "test-repo-m",
Repo: "m-repo",
},
}
repos := []string{
"z-repo",
"1-repo",
"a-repo",
"m-repo",
"b-repo",
}
for _, r := range repos {
rs.InitRepo(r, true)
}
rs.Sort("config", config)
expected := map[string]int{ // repos and their expected index
"a-repo": 0,
"1-repo": 1,
"z-repo": 2,
"b-repo": 3,
"m-repo": 4,
}
result := rs.AllRepos() // as returned from ls command
is := is.New(t)
is.NoErr(err)
for i, repo := range result {
is.Equal(expected[repo.Repo()], i) // repos should be ordered as in config file
}
}