-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgitconfig_test.go
170 lines (132 loc) · 3.67 KB
/
gitconfig_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package gitconfig
import (
"fmt"
. "github.com/onsi/gomega"
"testing"
)
func TestGlobal(t *testing.T) {
RegisterTestingT(t)
reset := withGlobalGitConfigFile(`
[user]
name = deeeet
email = [email protected]
[github]
user = ghdeeeet
`)
defer reset()
var err error
username, err := Global("user.name")
Expect(err).NotTo(HaveOccurred())
Expect(username).To(Equal("deeeet"))
email, err := Global("user.email")
Expect(err).NotTo(HaveOccurred())
Expect(email).To(Equal("[email protected]"))
githubuser, err := Global("github.user")
Expect(err).NotTo(HaveOccurred())
Expect(githubuser).To(Equal("ghdeeeet"))
nothing, err := Local("nothing.return")
Expect(err).To(HaveOccurred())
Expect(nothing).To(Equal(""))
}
func TestEntire(t *testing.T) {
RegisterTestingT(t)
includeFilePath := includeGitConfigFile(`
[user]
name = deeeet
email = [email protected]
`)
content := fmt.Sprintf(`
[include]
path = %s
`, includeFilePath)
reset := withGlobalGitConfigFile(content)
defer reset()
var err error
username, err := Entire("user.name")
Expect(err).NotTo(HaveOccurred())
Expect(username).To(Equal("deeeet"))
email, err := Entire("user.email")
Expect(err).NotTo(HaveOccurred())
Expect(email).To(Equal("[email protected]"))
nothing, err := Local("nothing.return")
Expect(err).To(HaveOccurred())
Expect(nothing).To(Equal(""))
}
func TestLocal(t *testing.T) {
RegisterTestingT(t)
reset := withLocalGitConfigFile("remote.origin.url", "[email protected]:tcnksm/go-test-gitconfig.git")
defer reset()
var err error
url, err := Local("remote.origin.url")
Expect(err).NotTo(HaveOccurred())
Expect(url).To(Equal("[email protected]:tcnksm/go-test-gitconfig.git"))
nothing, err := Local("nothing.return")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("the key `nothing.return` is not found"))
Expect(nothing).To(Equal(""))
}
func TestUsername(t *testing.T) {
RegisterTestingT(t)
reset := withGlobalGitConfigFile(`
[user]
name = taichi
email = [email protected]
`)
defer reset()
var err error
username, err := Username()
Expect(err).NotTo(HaveOccurred())
Expect(username).To(Equal("taichi"))
}
func TestEmail(t *testing.T) {
RegisterTestingT(t)
reset := withGlobalGitConfigFile(`
[user]
name = taichi
email = [email protected]
`)
defer reset()
var err error
username, err := Email()
Expect(err).NotTo(HaveOccurred())
Expect(username).To(Equal("[email protected]"))
}
func TestGithubToken(t *testing.T) {
RegisterTestingT(t)
reset := withGlobalGitConfigFile(`
[github]
token = 16c999e8c71134401a78d4d46435517b2271d6ac
`)
defer reset()
var err error
token, err := GithubToken()
Expect(err).NotTo(HaveOccurred())
Expect(token).To(Equal("16c999e8c71134401a78d4d46435517b2271d6ac"))
}
func TestOriginURL(t *testing.T) {
RegisterTestingT(t)
reset := withLocalGitConfigFile("remote.origin.url", "[email protected]:taichi/gitconfig.git")
defer reset()
var err error
url, err := OriginURL()
Expect(err).NotTo(HaveOccurred())
Expect(url).To(Equal("[email protected]:taichi/gitconfig.git"))
}
func TestRepository(t *testing.T) {
RegisterTestingT(t)
reset := withLocalGitConfigFile("remote.origin.url", "[email protected]:taichi/gitconfig.git")
defer reset()
var err error
repository, err := Repository()
Expect(err).NotTo(HaveOccurred())
Expect(repository).To(Equal("gitconfig"))
}
func TestRetrieveRepoName(t *testing.T) {
RegisterTestingT(t)
repo := retrieveRepoName("https://github.com/tcnksm/ghr.git")
Expect(repo).To(Equal("ghr"))
repo = retrieveRepoName("https://github.com/tcnksm/ghr")
Expect(repo).To(Equal("ghr"))
repo = retrieveRepoName("[email protected]:taichi/gitconfig.git")
Expect(repo).To(Equal("gitconfig"))
}