-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_local_remotes_to_gitolite_UnitTests.py
298 lines (256 loc) · 7.66 KB
/
update_local_remotes_to_gitolite_UnitTests.py
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import unittest
import sys
import imp
from update_local_remotes_to_gitolite import *
#
# Helper functions
#
def assertEqualsLineByLine(testObj, stringIn, stringExpected):
stringInArray = stringIn.split("\n")
stringExpectedArray = stringExpected.split("\n")
for i in xrange(len(stringExpectedArray)):
if i > len(stringInArray):
testObj.assertEqual(None, stringExpectedArray[i])
else:
testObj.assertEqual(stringInArray[i], stringExpectedArray[i])
if len(stringInArray) > len(stringExpectedArray):
testObj.assertEqual(stringInArray[len(stringExpectedArray)], None)
#
# Test data
#
git_config_file_1 = \
"""
[core]
urltrick1
urltrick2 = dummystuff
[remote "origin"]
url = casl-dev:/git-root/Trilinos
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "other1"]
url = casl-dev:/git-root/casl_trilinos
[remote "mamba"]
url = casl-dev:/git-root/casl_mamba
[remote "urltrick"]
url = something.at.com:/junk/something/Trilinos
"""
git_config_file_1_out = \
"""
[core]
urltrick1
urltrick2 = dummystuff
[remote "origin"]
url = git@casl-dev:Trilinos
fetch = +refs/heads/*:refs/remotes/origin/*
[remote "other1"]
url = git@casl-dev:Trilinos
[remote "mamba"]
url = git@casl-dev:Mamba
[remote "urltrick"]
url = something.at.com:/junk/something/Trilinos
"""
git_config_file_2 = \
"""
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
sparsecheckout = false
[remote "origin"]
url = casl-dev:/git-root/Trilinos
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "casl-dev"]
url = casl-dev:/git-root/Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev/*
[remote "casl-dev-collab"]
url = casl-dev.ornl.gov:/git-root/collaboration/Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev-collab/*
[remote "casl-dev2"]
url = [email protected]:/git-root/Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev2/*
[remote "casl-dev3"]
url = 8vt@casl-dev:/git-root/collaboration/Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev3/*
[remote "ssg"]
url = software.sandia.gov:/space/git/Trilinos
fetch = +refs/heads/*:refs/remotes/ssg/*
[remote "urltrick"]
url = something.at.com:/junk/something/Trilinos
"""
git_config_file_2_out = \
"""
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
sparsecheckout = false
[remote "origin"]
url = git@casl-dev:Trilinos
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[remote "casl-dev"]
url = git@casl-dev:Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev/*
[remote "casl-dev-collab"]
url = git@casl-dev:collaboration/Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev-collab/*
[remote "casl-dev2"]
url = git@casl-dev:Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev2/*
[remote "casl-dev3"]
url = git@casl-dev:collaboration/Trilinos
fetch = +refs/heads/*:refs/remotes/casl-dev3/*
[remote "ssg"]
url = software.sandia.gov:/space/git/Trilinos
fetch = +refs/heads/*:refs/remotes/ssg/*
[remote "urltrick"]
url = something.at.com:/junk/something/Trilinos
"""
#
# Unit tests
#
class test_getRemoteUrlDirct(unittest.TestCase):
def test_1(self):
urlDict = getRemoteUrlDict("casl-dev:/git-root/Trilinos")
urlDict_expected = {
"userid" : "",
"machine" : "casl-dev",
"baseDir" : "/git-root",
"repoName" : "Trilinos"
}
self.assertEqual(urlDict, urlDict_expected)
def test_1b(self):
urlDict = getRemoteUrlDict("casl-dev:/git-root/Trilinos.git")
urlDict_expected = {
"userid" : "",
"machine" : "casl-dev",
"baseDir" : "/git-root",
"repoName" : "Trilinos"
}
self.assertEqual(urlDict, urlDict_expected)
def test_2(self):
urlDict = getRemoteUrlDict("8vt@casl-dev:/git-root/Trilinos")
urlDict_expected = {
"userid" : "8vt",
"machine" : "casl-dev",
"baseDir" : "/git-root",
"repoName" : "Trilinos"
}
self.assertEqual(urlDict, urlDict_expected)
def test_3(self):
urlDict = getRemoteUrlDict("[email protected]:/git-root/collaboration/Trilinos")
urlDict_expected = {
"userid" : "8vt",
"machine" : "casl-dev.ornl.gov",
"baseDir" : "/git-root/collaboration",
"repoName" : "Trilinos"
}
self.assertEqual(urlDict, urlDict_expected)
def test_3(self):
urlDict = getRemoteUrlDict("/home/8vt/git/Trilinos")
urlDict_expected = {
"userid" : "",
"machine" : "",
"baseDir" : "/home/8vt/git",
"repoName" : "Trilinos"
}
self.assertEqual(urlDict, urlDict_expected)
class test_matchesMachineAndBaseDir(unittest.TestCase):
def test_1(self):
self.assertEqual(
matchesMachineAndBaseDir(
getRemoteUrlDict("casl-dev:/git-root/Trilinos"),
"casl-dev", "/git-root"
),
True
)
def test_2(self):
self.assertEqual(
matchesMachineAndBaseDir(
getRemoteUrlDict("casl-dev:/git-root/Trilinos"),
"casl-dev", "/git-roots"
),
False
)
def test_2b(self):
self.assertEqual(
matchesMachineAndBaseDir(
getRemoteUrlDict("casl-dev:/some-other-path/Trilinos"),
"casl-dev", "/git-roots"
),
False
)
def test_3(self):
self.assertEqual(
matchesMachineAndBaseDir(
getRemoteUrlDict("casl-dev:/git-root/collaboration/Trilinos"),
"casl-dev", "/git-root"
),
True
)
def test_4(self):
self.assertEqual(
matchesMachineAndBaseDir(
getRemoteUrlDict("[email protected]:/git-root/COBRA-TF"),
"casl-dev", "/git-root"
),
False
)
def test_5(self):
self.assertEqual(
matchesMachineAndBaseDir(
getRemoteUrlDict("[email protected]:/git-root/COBRA-TF"),
"casl-dev.ornl.gov", "/git-root"
),
True
)
class test_getNewRemoteUrlStrFromOldUrlDict(unittest.TestCase):
def test_1(self):
newRemoteUrlStr = getNewRemoteUrlStrFromOldUrlDict(
getRemoteUrlDict("casl-dev.ornl.gov:/git-root/Trilinos"),
"/git-root", "git@casl-dev:", {}
)
newRemoteUrlStr_expected = "git@casl-dev:Trilinos"
self.assertEqual(newRemoteUrlStr, newRemoteUrlStr_expected)
def test_1b(self):
newRemoteUrlStr = getNewRemoteUrlStrFromOldUrlDict(
getRemoteUrlDict("casl-dev.ornl.gov:/git-root/casl_trilinos"),
"/git-root", "git@casl-dev:", { "casl_trilinos" : "Trilinos" }
)
newRemoteUrlStr_expected = "git@casl-dev:Trilinos"
self.assertEqual(newRemoteUrlStr, newRemoteUrlStr_expected)
def test_2(self):
newRemoteUrlStr = getNewRemoteUrlStrFromOldUrlDict(
getRemoteUrlDict("casl-dev:/git-root/collaboration/Trilinos"),
"/git-root", "git@casl-dev:", {}
)
newRemoteUrlStr_expected = "git@casl-dev:collaboration/Trilinos"
self.assertEqual(newRemoteUrlStr, newRemoteUrlStr_expected)
def test_3(self):
self.assertRaises(
Exception,
getNewRemoteUrlStrFromOldUrlDict,
getRemoteUrlDict("casl-dev:/some-other-path/Trilinos"),
"/git-root", "git@casl-dev:", {}
)
class test_updateGitConfigFileStr(unittest.TestCase):
def test_1(self):
newGetConfigFileStr = updateGitConfigFileStr(git_config_file_1,
["casl-dev"], "/git-root", "git@casl-dev:",
{ "casl_trilinos":"Trilinos", "casl_mamba":"Mamba" } )
assertEqualsLineByLine(self, newGetConfigFileStr, git_config_file_1_out)
def test_2(self):
newGetConfigFileStr = updateGitConfigFileStr(git_config_file_2,
["casl-dev", "casl-dev.ornl.gov"], "/git-root", "git@casl-dev:", {} )
assertEqualsLineByLine(self, newGetConfigFileStr, git_config_file_2_out)
#
# Main()
#
if __name__ == '__main__':
unittest.main()