Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit da7229b

Browse files
committed
[NEW] Adding Bazaar support: add bzr to the adapter factory.
Add test_factory_bzr to the FactoryTest. And add validation.rb adapter module: Needed for adapter factory. Add bzr validation unit test. Michael
1 parent 1007828 commit da7229b

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

lib/scm/adapters/bzr/validation.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Scm::Adapters
2+
class BzrAdapter < AbstractAdapter
3+
def self.url_regex
4+
/^((http|https|ssh|file):\/\/((\w+@)?[A-Za-z0-9_\-\.]+(:\d+)?\/)?)?[A-Za-z0-9_\-\.\/\~\+]*$/
5+
end
6+
7+
def self.public_url_regex
8+
/^(http|https):\/\/(\w+@)?[A-Za-z0-9_\-\.]+(:\d+)?\/[A-Za-z0-9_\-\.\/\~\+]*$/
9+
end
10+
11+
def validate_server_connection
12+
return unless valid?
13+
@errors << [:failed, "The server did not respond to the 'bzr revno' command. Is the URL correct?"] unless self.exist?
14+
end
15+
end
16+
end

lib/scm/adapters/bzr_adapter.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ def english_name
55
end
66
end
77
end
8+
9+
require 'lib/scm/adapters/bzr/validation'

lib/scm/adapters/factory.rb

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def self.from_path(path)
1111
elsif FileTest.exist?(File.join(path, '.hg'))
1212
HgAdapter.new(:url => File.expand_path(path)).normalize
1313

14+
elsif FileTest.exist?(File.join(path, '.bzr'))
15+
BzrAdapter.new(:url => File.expand_path(path)).normalize
16+
1417
elsif FileTest.exist?(File.join(path, 'db'))
1518
SvnAdapter.new(:url => File.expand_path(path)).normalize
1619

test/unit/adapter_factory_test.rb

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ def test_factory_hg
1212
end
1313
end
1414

15+
def test_factory_bzr
16+
Scm::ScratchDir.new do |path|
17+
`cd #{path} && bzr init`
18+
bzr = Factory.from_path(path)
19+
assert bzr.is_a?(BzrAdapter)
20+
assert_equal bzr.url, path
21+
end
22+
end
23+
1524
def test_factory_git
1625
Scm::ScratchDir.new do |path|
1726
`cd #{path} && git init`

test/unit/bzr_validation_test.rb

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
require File.dirname(__FILE__) + '/../test_helper'
2+
3+
module Scm::Adapters
4+
class BzrValidationTest < Scm::Test
5+
def test_rejected_urls
6+
[ nil, "", "foo", "http:/", "http:://", "http://", "http://a",
7+
"www.selenic.com/repo/hello", # missing a protool prefix
8+
"http://www.selenic.com/repo/hello%20world", # no encoded strings allowed
9+
"http://www.selenic.com/repo/hello world", # no spaces allowed
10+
"git://www.selenic.com/repo/hello", # git protocol not allowed
11+
"svn://www.selenic.com/repo/hello" # svn protocol not allowed
12+
].each do |url|
13+
bzr = BzrAdapter.new(:url => url, :public_urls_only => true)
14+
assert bzr.validate_url.any?
15+
end
16+
end
17+
18+
def test_accepted_urls
19+
[ "http://www.selenic.com/repo/hello",
20+
"http://www.selenic.com:80/repo/hello",
21+
"https://www.selenic.com/repo/hello",
22+
].each do |url|
23+
bzr = BzrAdapter.new(:url => url, :public_urls_only => true)
24+
assert !bzr.validate_url
25+
end
26+
end
27+
28+
# These urls are not available to the public
29+
def test_rejected_public_urls
30+
[ "file:///home/test/bzr",
31+
"/home/test/bzr",
32+
"ssh://test@localhost/home/test/bzr",
33+
"ssh://localhost/home/test/bzr"
34+
].each do |url|
35+
bzr = BzrAdapter.new(:url => url, :public_urls_only => true)
36+
assert bzr.validate_url
37+
38+
bzr = BzrAdapter.new(:url => url)
39+
assert !bzr.validate_url
40+
end
41+
end
42+
43+
def test_guess_forge
44+
bzr = BzrAdapter.new(:url => nil)
45+
assert_equal nil, bzr.guess_forge
46+
47+
bzr = BzrAdapter.new(:url => "/home/test/bzr")
48+
assert_equal nil, bzr.guess_forge
49+
50+
bzr = BzrAdapter.new( :url => 'http://www.selenic.com/repo/hello')
51+
assert_equal 'www.selenic.com', bzr.guess_forge
52+
end
53+
end
54+
end

0 commit comments

Comments
 (0)