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.

cvs_adapter_test.rb 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2020 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 File.expand_path('../../../../../../test_helper', __FILE__)
  19. class CvsAdapterTest < ActiveSupport::TestCase
  20. REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
  21. REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
  22. MODULE_NAME = 'test'
  23. if File.directory?(REPOSITORY_PATH)
  24. def setup
  25. @adapter = Redmine::Scm::Adapters::CvsAdapter.new(MODULE_NAME, REPOSITORY_PATH)
  26. end
  27. def test_scm_version
  28. to_test = { "\nConcurrent Versions System (CVS) 1.12.13 (client/server)\n" => [1,12,13],
  29. "\r\n1.12.12\r\n1.12.11" => [1,12,12],
  30. "1.12.11\r\n1.12.10\r\n" => [1,12,11]}
  31. to_test.each do |s, v|
  32. test_scm_version_for(s, v)
  33. end
  34. end
  35. def test_revisions_all
  36. cnt = 0
  37. @adapter.revisions('', nil, nil, :log_encoding => 'UTF-8') do |revision|
  38. cnt += 1
  39. end
  40. assert_equal 16, cnt
  41. end
  42. def test_revisions_from_rev3
  43. rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
  44. cnt = 0
  45. @adapter.revisions('', rev3_committed_on, nil, :log_encoding => 'UTF-8') do |revision|
  46. cnt += 1
  47. end
  48. assert_equal 4, cnt
  49. end
  50. def test_entries_rev3
  51. rev3_committed_on = Time.gm(2007, 12, 13, 16, 27, 22)
  52. entries = @adapter.entries('sources', rev3_committed_on)
  53. assert_equal 2, entries.size
  54. assert_equal entries[0].name, "watchers_controller.rb"
  55. assert_equal entries[0].lastrev.time, Time.gm(2007, 12, 13, 16, 27, 22)
  56. end
  57. def test_path_encoding_default_utf8
  58. adpt1 = Redmine::Scm::Adapters::CvsAdapter.new(
  59. MODULE_NAME,
  60. REPOSITORY_PATH
  61. )
  62. assert_equal "UTF-8", adpt1.path_encoding
  63. adpt2 = Redmine::Scm::Adapters::CvsAdapter.new(
  64. MODULE_NAME,
  65. REPOSITORY_PATH,
  66. nil,
  67. nil,
  68. ""
  69. )
  70. assert_equal "UTF-8", adpt2.path_encoding
  71. end
  72. def test_root_url_path
  73. to_test = {
  74. ':pserver:cvs_user:cvs_password@123.456.789.123:9876/repo' => '/repo',
  75. ':pserver:cvs_user:cvs_password@123.456.789.123/repo' => '/repo',
  76. ':pserver:cvs_user:cvs_password@cvs_server:/repo' => '/repo',
  77. ':pserver:cvs_user:cvs_password@cvs_server:9876/repo' => '/repo',
  78. ':pserver:cvs_user:cvs_password@cvs_server/repo' => '/repo',
  79. ':pserver:cvs_user:cvs_password@cvs_server/path/repo' => '/path/repo',
  80. ':ext:cvsservername:/path' => '/path'
  81. }
  82. to_test.each do |string, expected|
  83. assert_equal expected, Redmine::Scm::Adapters::CvsAdapter.new('foo', string).send(:root_url_path), "#{string} failed"
  84. end
  85. end
  86. private
  87. def test_scm_version_for(scm_command_version, version)
  88. @adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
  89. assert_equal version, @adapter.class.scm_command_version
  90. end
  91. else
  92. puts "Cvs test repository NOT FOUND. Skipping unit tests !!!"
  93. def test_fake; assert true end
  94. end
  95. end