##// END OF EJS Templates
scm: mercurial: add check scmid to RepositoryMercurialTest#test_fetch_changesets_from_scratch (#14361)...
Toshi MARUYAMA -
r12475:28fbc270fae8
parent child
Show More
@@ -1,400 +1,402
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoryMercurialTest < ActiveSupport::TestCase
21 21 fixtures :projects
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 26 NUM_REV = 32
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28
29 29 def setup
30 30 @project = Project.find(3)
31 31 @repository = Repository::Mercurial.create(
32 32 :project => @project,
33 33 :url => REPOSITORY_PATH,
34 34 :path_encoding => 'ISO-8859-1'
35 35 )
36 36 assert @repository
37 37 @char_1 = CHAR_1_HEX.dup
38 38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
39 39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
40 40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
41 41 if @char_1.respond_to?(:force_encoding)
42 42 @char_1.force_encoding('UTF-8')
43 43 @tag_char_1.force_encoding('UTF-8')
44 44 @branch_char_0.force_encoding('UTF-8')
45 45 @branch_char_1.force_encoding('UTF-8')
46 46 end
47 47 end
48 48
49 49 def test_blank_path_to_repository_error_message
50 50 set_language_if_valid 'en'
51 51 repo = Repository::Mercurial.new(
52 52 :project => @project,
53 53 :identifier => 'test'
54 54 )
55 55 assert !repo.save
56 56 assert_include "Path to repository can't be blank",
57 57 repo.errors.full_messages
58 58 end
59 59
60 60 def test_blank_path_to_repository_error_message_fr
61 61 set_language_if_valid 'fr'
62 62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 64 repo = Repository::Mercurial.new(
65 65 :project => @project,
66 66 :url => "",
67 67 :identifier => 'test',
68 68 :path_encoding => ''
69 69 )
70 70 assert !repo.save
71 71 assert_include str, repo.errors.full_messages
72 72 end
73 73
74 74 if File.directory?(REPOSITORY_PATH)
75 75 def test_scm_available
76 76 klass = Repository::Mercurial
77 77 assert_equal "Mercurial", klass.scm_name
78 78 assert klass.scm_adapter_class
79 79 assert_not_equal "", klass.scm_command
80 80 assert_equal true, klass.scm_available
81 81 end
82 82
83 83 def test_entries
84 84 entries = @repository.entries
85 85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 86 end
87 87
88 88 def test_fetch_changesets_from_scratch
89 89 assert_equal 0, @repository.changesets.count
90 90 @repository.fetch_changesets
91 91 @project.reload
92 92 assert_equal NUM_REV, @repository.changesets.count
93 93 assert_equal 46, @repository.filechanges.count
94 rev0 = @repository.changesets.find_by_revision('0')
94 95 assert_equal "Initial import.\nThe repository contains 3 files.",
95 @repository.changesets.find_by_revision('0').comments
96 rev0.comments
97 assert_equal "0885933ad4f6", rev0.scmid
96 98 end
97 99
98 100 def test_fetch_changesets_incremental
99 101 assert_equal 0, @repository.changesets.count
100 102 @repository.fetch_changesets
101 103 @project.reload
102 104 assert_equal NUM_REV, @repository.changesets.count
103 105 # Remove changesets with revision > 2
104 106 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
105 107 @project.reload
106 108 @repository.reload
107 109 assert_equal 3, @repository.changesets.count
108 110
109 111 @repository.fetch_changesets
110 112 @project.reload
111 113 assert_equal NUM_REV, @repository.changesets.count
112 114 end
113 115
114 116 def test_isodatesec
115 117 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
116 118 if @repository.scm.class.client_version_above?([1, 0])
117 119 assert_equal 0, @repository.changesets.count
118 120 @repository.fetch_changesets
119 121 @project.reload
120 122 assert_equal NUM_REV, @repository.changesets.count
121 123 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
122 124 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
123 125 end
124 126 end
125 127
126 128 def test_changeset_order_by_revision
127 129 assert_equal 0, @repository.changesets.count
128 130 @repository.fetch_changesets
129 131 @project.reload
130 132 assert_equal NUM_REV, @repository.changesets.count
131 133
132 134 c0 = @repository.latest_changeset
133 135 c1 = @repository.changesets.find_by_revision('0')
134 136 # sorted by revision (id), not by date
135 137 assert c0.revision.to_i > c1.revision.to_i
136 138 assert c0.committed_on < c1.committed_on
137 139 end
138 140
139 141 def test_latest_changesets
140 142 assert_equal 0, @repository.changesets.count
141 143 @repository.fetch_changesets
142 144 @project.reload
143 145 assert_equal NUM_REV, @repository.changesets.count
144 146
145 147 # with_limit
146 148 changesets = @repository.latest_changesets('', nil, 2)
147 149 assert_equal %w|31 30|, changesets.collect(&:revision)
148 150
149 151 # with_filepath
150 152 changesets = @repository.latest_changesets(
151 153 '/sql_escape/percent%dir/percent%file1.txt', nil)
152 154 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
153 155
154 156 changesets = @repository.latest_changesets(
155 157 '/sql_escape/underscore_dir/understrike_file.txt', nil)
156 158 assert_equal %w|30 12 9|, changesets.collect(&:revision)
157 159
158 160 changesets = @repository.latest_changesets('README', nil)
159 161 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
160 162
161 163 changesets = @repository.latest_changesets('README','8')
162 164 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
163 165
164 166 changesets = @repository.latest_changesets('README','8', 2)
165 167 assert_equal %w|8 6|, changesets.collect(&:revision)
166 168
167 169 # with_dirpath
168 170 changesets = @repository.latest_changesets('images', nil)
169 171 assert_equal %w|1 0|, changesets.collect(&:revision)
170 172
171 173 path = 'sql_escape/percent%dir'
172 174 changesets = @repository.latest_changesets(path, nil)
173 175 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
174 176
175 177 changesets = @repository.latest_changesets(path, '11')
176 178 assert_equal %w|11 10 9|, changesets.collect(&:revision)
177 179
178 180 changesets = @repository.latest_changesets(path, '11', 2)
179 181 assert_equal %w|11 10|, changesets.collect(&:revision)
180 182
181 183 path = 'sql_escape/underscore_dir'
182 184 changesets = @repository.latest_changesets(path, nil)
183 185 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
184 186
185 187 changesets = @repository.latest_changesets(path, '12')
186 188 assert_equal %w|12 9|, changesets.collect(&:revision)
187 189
188 190 changesets = @repository.latest_changesets(path, '12', 1)
189 191 assert_equal %w|12|, changesets.collect(&:revision)
190 192 end
191 193
192 194 def test_latest_changesets_tag
193 195 assert_equal 0, @repository.changesets.count
194 196 @repository.fetch_changesets
195 197 @project.reload
196 198 assert_equal NUM_REV, @repository.changesets.count
197 199
198 200 changesets = @repository.latest_changesets('', 'tag_test.00')
199 201 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
200 202
201 203 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
202 204 assert_equal %w|5 4|, changesets.collect(&:revision)
203 205
204 206 changesets = @repository.latest_changesets('sources', 'tag_test.00')
205 207 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
206 208
207 209 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
208 210 assert_equal %w|4 3|, changesets.collect(&:revision)
209 211 end
210 212
211 213 def test_latest_changesets_branch
212 214 assert_equal 0, @repository.changesets.count
213 215 @repository.fetch_changesets
214 216 @project.reload
215 217 assert_equal NUM_REV, @repository.changesets.count
216 218
217 219 if @repository.scm.class.client_version_above?([1, 6])
218 220 changesets = @repository.latest_changesets('', @branch_char_1)
219 221 assert_equal %w|27 26|, changesets.collect(&:revision)
220 222 end
221 223
222 224 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
223 225 assert_equal %w|27|, changesets.collect(&:revision)
224 226 end
225 227
226 228 def test_copied_files
227 229 assert_equal 0, @repository.changesets.count
228 230 @repository.fetch_changesets
229 231 @project.reload
230 232 assert_equal NUM_REV, @repository.changesets.count
231 233
232 234 cs1 = @repository.changesets.find_by_revision('13')
233 235 assert_not_nil cs1
234 236 c1 = cs1.filechanges.sort_by(&:path)
235 237 assert_equal 2, c1.size
236 238
237 239 assert_equal 'A', c1[0].action
238 240 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
239 241 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
240 242 assert_equal '3a330eb32958', c1[0].from_revision
241 243
242 244 assert_equal 'A', c1[1].action
243 245 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
244 246 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
245 247
246 248 cs2 = @repository.changesets.find_by_revision('15')
247 249 c2 = cs2.filechanges
248 250 assert_equal 1, c2.size
249 251
250 252 assert_equal 'A', c2[0].action
251 253 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
252 254 assert_equal '/README', c2[0].from_path
253 255 assert_equal '933ca60293d7', c2[0].from_revision
254 256
255 257 cs3 = @repository.changesets.find_by_revision('19')
256 258 c3 = cs3.filechanges
257 259 assert_equal 1, c3.size
258 260 assert_equal 'A', c3[0].action
259 261 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
260 262 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
261 263 assert_equal '5d9891a1b425', c3[0].from_revision
262 264 end
263 265
264 266 def test_find_changeset_by_name
265 267 assert_equal 0, @repository.changesets.count
266 268 @repository.fetch_changesets
267 269 @project.reload
268 270 assert_equal NUM_REV, @repository.changesets.count
269 271 %w|2 400bb8672109 400|.each do |r|
270 272 assert_equal '2', @repository.find_changeset_by_name(r).revision
271 273 end
272 274 end
273 275
274 276 def test_find_changeset_by_invalid_name
275 277 assert_equal 0, @repository.changesets.count
276 278 @repository.fetch_changesets
277 279 @project.reload
278 280 assert_equal NUM_REV, @repository.changesets.count
279 281 assert_nil @repository.find_changeset_by_name('100000')
280 282 end
281 283
282 284 def test_identifier
283 285 assert_equal 0, @repository.changesets.count
284 286 @repository.fetch_changesets
285 287 @project.reload
286 288 assert_equal NUM_REV, @repository.changesets.count
287 289 c = @repository.changesets.find_by_revision('2')
288 290 assert_equal c.scmid, c.identifier
289 291 end
290 292
291 293 def test_format_identifier
292 294 assert_equal 0, @repository.changesets.count
293 295 @repository.fetch_changesets
294 296 @project.reload
295 297 assert_equal NUM_REV, @repository.changesets.count
296 298 c = @repository.changesets.find_by_revision('2')
297 299 assert_equal '2:400bb8672109', c.format_identifier
298 300 end
299 301
300 302 def test_format_identifier_long_id
301 303 assert_equal 0, @repository.changesets.count
302 304 Changeset.create!(:repository => @repository,
303 305 :committed_on => Time.now,
304 306 :revision => '0',
305 307 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
306 308 :comments => 'test')
307 309 c = @repository.changesets.find_by_revision('0')
308 310 assert_equal '0:0885933ad4f6', c.format_identifier
309 311 end
310 312
311 313 def test_find_changeset_by_empty_name
312 314 assert_equal 0, @repository.changesets.count
313 315 @repository.fetch_changesets
314 316 @project.reload
315 317 assert_equal NUM_REV, @repository.changesets.count
316 318 ['', ' ', nil].each do |r|
317 319 assert_nil @repository.find_changeset_by_name(r)
318 320 end
319 321 end
320 322
321 323 def test_parents
322 324 assert_equal 0, @repository.changesets.count
323 325 @repository.fetch_changesets
324 326 @project.reload
325 327 assert_equal NUM_REV, @repository.changesets.count
326 328 r1 = @repository.changesets.find_by_revision('0')
327 329 assert_equal [], r1.parents
328 330 r2 = @repository.changesets.find_by_revision('1')
329 331 assert_equal 1, r2.parents.length
330 332 assert_equal "0885933ad4f6",
331 333 r2.parents[0].identifier
332 334 r3 = @repository.changesets.find_by_revision('30')
333 335 assert_equal 2, r3.parents.length
334 336 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
335 337 assert_equal "3a330eb32958", r4[0]
336 338 assert_equal "a94b0528f24f", r4[1]
337 339 end
338 340
339 341 def test_activities
340 342 c = Changeset.new(:repository => @repository,
341 343 :committed_on => Time.now,
342 344 :revision => '123',
343 345 :scmid => 'abc400bb8672',
344 346 :comments => 'test')
345 347 assert c.event_title.include?('123:abc400bb8672:')
346 348 assert_equal 'abc400bb8672', c.event_url[:rev]
347 349 end
348 350
349 351 def test_previous
350 352 assert_equal 0, @repository.changesets.count
351 353 @repository.fetch_changesets
352 354 @project.reload
353 355 assert_equal NUM_REV, @repository.changesets.count
354 356 %w|28 3ae45e2d177d 3ae45|.each do |r1|
355 357 changeset = @repository.find_changeset_by_name(r1)
356 358 %w|27 7bbf4c738e71 7bbf|.each do |r2|
357 359 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
358 360 end
359 361 end
360 362 end
361 363
362 364 def test_previous_nil
363 365 assert_equal 0, @repository.changesets.count
364 366 @repository.fetch_changesets
365 367 @project.reload
366 368 assert_equal NUM_REV, @repository.changesets.count
367 369 %w|0 0885933ad4f6 0885|.each do |r1|
368 370 changeset = @repository.find_changeset_by_name(r1)
369 371 assert_nil changeset.previous
370 372 end
371 373 end
372 374
373 375 def test_next
374 376 assert_equal 0, @repository.changesets.count
375 377 @repository.fetch_changesets
376 378 @project.reload
377 379 assert_equal NUM_REV, @repository.changesets.count
378 380 %w|27 7bbf4c738e71 7bbf|.each do |r2|
379 381 changeset = @repository.find_changeset_by_name(r2)
380 382 %w|28 3ae45e2d177d 3ae45|.each do |r1|
381 383 assert_equal @repository.find_changeset_by_name(r1), changeset.next
382 384 end
383 385 end
384 386 end
385 387
386 388 def test_next_nil
387 389 assert_equal 0, @repository.changesets.count
388 390 @repository.fetch_changesets
389 391 @project.reload
390 392 assert_equal NUM_REV, @repository.changesets.count
391 393 %w|31 31eeee7395c8 31eee|.each do |r1|
392 394 changeset = @repository.find_changeset_by_name(r1)
393 395 assert_nil changeset.next
394 396 end
395 397 end
396 398 else
397 399 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
398 400 def test_fake; assert true end
399 401 end
400 402 end
General Comments 0
You need to be logged in to leave comments. Login now