You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repository_cvs_test.rb 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006- Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require_relative '../test_helper'
  19. class RepositoryCvsTest < ActiveSupport::TestCase
  20. fixtures :projects
  21. include Redmine::I18n
  22. REPOSITORY_PATH = repository_path('cvs')
  23. REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
  24. # CVS module
  25. MODULE_NAME = 'test'
  26. CHANGESETS_NUM = 7
  27. def setup
  28. User.current = nil
  29. @project = Project.find(3)
  30. @repository = Repository::Cvs.create(:project => @project,
  31. :root_url => REPOSITORY_PATH,
  32. :url => MODULE_NAME,
  33. :log_encoding => 'UTF-8')
  34. assert @repository
  35. end
  36. def test_blank_module_error_message
  37. set_language_if_valid 'en'
  38. repo = Repository::Cvs.new(
  39. :project => @project,
  40. :identifier => 'test',
  41. :log_encoding => 'UTF-8',
  42. :root_url => REPOSITORY_PATH
  43. )
  44. assert !repo.save
  45. assert_include "Module cannot be blank",
  46. repo.errors.full_messages
  47. end
  48. def test_blank_module_error_message_fr
  49. set_language_if_valid 'fr'
  50. repo = Repository::Cvs.new(
  51. :project => @project,
  52. :identifier => 'test',
  53. :log_encoding => 'UTF-8',
  54. :path_encoding => '',
  55. :url => '',
  56. :root_url => REPOSITORY_PATH
  57. )
  58. assert !repo.save
  59. assert_include 'Module doit être renseigné(e)', repo.errors.full_messages
  60. end
  61. def test_blank_cvsroot_error_message
  62. set_language_if_valid 'en'
  63. repo = Repository::Cvs.new(
  64. :project => @project,
  65. :identifier => 'test',
  66. :log_encoding => 'UTF-8',
  67. :url => MODULE_NAME
  68. )
  69. assert !repo.save
  70. assert_include "CVSROOT cannot be blank",
  71. repo.errors.full_messages
  72. end
  73. def test_blank_cvsroot_error_message_fr
  74. set_language_if_valid 'fr'
  75. repo = Repository::Cvs.new(
  76. :project => @project,
  77. :identifier => 'test',
  78. :log_encoding => 'UTF-8',
  79. :path_encoding => '',
  80. :url => MODULE_NAME,
  81. :root_url => ''
  82. )
  83. assert !repo.save
  84. assert_include 'CVSROOT doit être renseigné(e)', repo.errors.full_messages
  85. end
  86. def test_root_url_should_be_validated_against_regexp_set_in_configuration
  87. Redmine::Configuration.with 'scm_cvs_path_regexp' => '/cvspath/[a-z]+' do
  88. repo = Repository::Cvs.new(
  89. :project => @project,
  90. :identifier => 'test',
  91. :log_encoding => 'UTF-8',
  92. :path_encoding => '',
  93. :url => MODULE_NAME
  94. )
  95. repo.root_url = '/wrong_path'
  96. assert repo.invalid?
  97. assert repo.errors[:root_url].present?
  98. repo.root_url = '/cvspath/foo'
  99. assert repo.valid?
  100. end
  101. end
  102. if File.directory?(REPOSITORY_PATH)
  103. def test_fetch_changesets_from_scratch
  104. assert_equal 0, @repository.changesets.count
  105. @repository.fetch_changesets
  106. @project.reload
  107. assert_equal CHANGESETS_NUM, @repository.changesets.count
  108. assert_equal 16, @repository.filechanges.count
  109. assert_not_nil @repository.changesets.find_by_comments('Two files changed')
  110. r2 = @repository.changesets.find_by_revision('2')
  111. assert_equal 'v1-20071213-162510', r2.scmid
  112. end
  113. def test_fetch_changesets_incremental
  114. assert_equal 0, @repository.changesets.count
  115. @repository.fetch_changesets
  116. @project.reload
  117. assert_equal CHANGESETS_NUM, @repository.changesets.count
  118. # Remove changesets with revision > 3
  119. @repository.changesets.each {|c| c.destroy if c.revision.to_i > 3}
  120. @project.reload
  121. @repository.reload
  122. assert_equal 3, @repository.changesets.count
  123. assert_equal %w|3 2 1|, @repository.changesets.collect(&:revision)
  124. rev3_commit = @repository.changesets.reorder('committed_on DESC').first
  125. assert_equal '3', rev3_commit.revision
  126. # 2007-12-14 01:27:22 +0900
  127. rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
  128. assert_equal 'HEAD-20071213-162722', rev3_commit.scmid
  129. assert_equal rev3_committed_on, rev3_commit.committed_on
  130. latest_rev = @repository.latest_changeset
  131. assert_equal rev3_committed_on, latest_rev.committed_on
  132. @repository.fetch_changesets
  133. @project.reload
  134. @repository.reload
  135. assert_equal CHANGESETS_NUM, @repository.changesets.count
  136. assert_equal %w|7 6 5 4 3 2 1|, @repository.changesets.collect(&:revision)
  137. rev5_commit = @repository.changesets.find_by_revision('5')
  138. assert_equal 'HEAD-20071213-163001', rev5_commit.scmid
  139. # 2007-12-14 01:30:01 +0900
  140. rev5_committed_on = Time.gm(2007, 12, 13, 16, 30, 1)
  141. assert_equal rev5_committed_on, rev5_commit.committed_on
  142. end
  143. def test_deleted_files_should_not_be_listed
  144. assert_equal 0, @repository.changesets.count
  145. @repository.fetch_changesets
  146. @project.reload
  147. assert_equal CHANGESETS_NUM, @repository.changesets.count
  148. entries = @repository.entries('sources')
  149. assert entries.detect {|e| e.name == 'watchers_controller.rb'}
  150. assert_nil entries.detect {|e| e.name == 'welcome_controller.rb'}
  151. end
  152. def test_entries_rev3
  153. assert_equal 0, @repository.changesets.count
  154. @repository.fetch_changesets
  155. @project.reload
  156. assert_equal CHANGESETS_NUM, @repository.changesets.count
  157. rev3_commit = @repository.changesets.find_by_revision('3')
  158. assert_equal "3", rev3_commit.revision
  159. assert_equal "LANG", rev3_commit.committer
  160. assert_equal 2, rev3_commit.filechanges.length
  161. filechanges = rev3_commit.filechanges.order(:path => :asc)
  162. assert_equal "1.2", filechanges[0].revision
  163. assert_equal "1.2", filechanges[1].revision
  164. assert_equal "/README", filechanges[0].path
  165. assert_equal "/sources/watchers_controller.rb", filechanges[1].path
  166. entries = @repository.entries('', '3')
  167. assert_kind_of Redmine::Scm::Adapters::Entries, entries
  168. assert_equal 3, entries.size
  169. assert_equal "README", entries[2].name
  170. assert_equal 'UTF-8', entries[2].path.encoding.to_s
  171. assert_equal Time.gm(2007, 12, 13, 16, 27, 22), entries[2].lastrev.time
  172. assert_equal '3', entries[2].lastrev.identifier
  173. assert_equal '3', entries[2].lastrev.revision
  174. assert_equal 'LANG', entries[2].lastrev.author
  175. end
  176. def test_entries_invalid_path
  177. assert_equal 0, @repository.changesets.count
  178. @repository.fetch_changesets
  179. @project.reload
  180. assert_equal CHANGESETS_NUM, @repository.changesets.count
  181. assert_nil @repository.entries('missing')
  182. assert_nil @repository.entries('missing', '3')
  183. end
  184. def test_entries_invalid_revision
  185. assert_equal 0, @repository.changesets.count
  186. @repository.fetch_changesets
  187. @project.reload
  188. assert_equal CHANGESETS_NUM, @repository.changesets.count
  189. assert_nil @repository.entries('', '123')
  190. end
  191. def test_cat
  192. assert_equal 0, @repository.changesets.count
  193. @repository.fetch_changesets
  194. @project.reload
  195. assert_equal CHANGESETS_NUM, @repository.changesets.count
  196. buf = @repository.cat('README')
  197. assert buf
  198. lines = buf.split("\n")
  199. assert_equal 3, lines.length
  200. buf = lines[1].gsub(/\r$/, "")
  201. assert_equal 'with one change', buf
  202. buf = @repository.cat('README', '1')
  203. assert buf
  204. lines = buf.split("\n")
  205. assert_equal 1, lines.length
  206. buf = lines[0].gsub(/\r$/, "")
  207. assert_equal 'CVS test repository', buf
  208. assert_nil @repository.cat('missing.rb')
  209. # sources/welcome_controller.rb is removed at revision 5.
  210. assert @repository.cat('sources/welcome_controller.rb', '4')
  211. assert @repository.cat('sources/welcome_controller.rb', '5').blank?
  212. # invalid revision
  213. assert @repository.cat('README', '123').blank?
  214. end
  215. def test_annotate
  216. assert_equal 0, @repository.changesets.count
  217. @repository.fetch_changesets
  218. @project.reload
  219. assert_equal CHANGESETS_NUM, @repository.changesets.count
  220. ann = @repository.annotate('README')
  221. assert ann
  222. assert_equal 3, ann.revisions.length
  223. assert_equal '1.2', ann.revisions[1].revision
  224. assert_equal 'LANG', ann.revisions[1].author
  225. assert_equal 'with one change', ann.lines[1]
  226. ann = @repository.annotate('README', '1')
  227. assert ann
  228. assert_equal 1, ann.revisions.length
  229. assert_equal '1.1', ann.revisions[0].revision
  230. assert_equal 'LANG', ann.revisions[0].author
  231. assert_equal 'CVS test repository', ann.lines[0]
  232. # invalid revision
  233. assert_nil @repository.annotate('README', '123')
  234. end
  235. else
  236. puts "CVS test repository NOT FOUND. Skipping unit tests !!!"
  237. def test_fake; assert true end
  238. end
  239. end