forked from rcoder/ohloh_scm
/
abstract_adapter_test.rb
106 lines (88 loc) · 3.03 KB
/
abstract_adapter_test.rb
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
require_relative '../test_helper'
module OhlohScm::Adapters
class AbstractAdapterTest < OhlohScm::Test
def test_simple_validation
scm = AbstractAdapter.new()
assert !scm.valid?
assert_equal [[:url, "The URL can't be blank."]], scm.errors
scm.url = "http://www.test.org/test"
assert scm.valid?
assert scm.errors.empty?
end
def test_valid_urls
['http://www.ohloh.net'].each do |url|
assert !AbstractAdapter.new(:url => url).validate_url
end
end
def test_invalid_urls
[nil, '', '*' * 121].each do |url|
assert AbstractAdapter.new(:url => url).validate_url.any?
end
end
def test_invalid_usernames
['no spaces allowed', '/', ':', 'a'*33].each do |username|
assert AbstractAdapter.new(:username => username).validate_username.any?
end
end
def test_valid_usernames
[nil,'','joe_36','a'*32].each do |username|
assert !AbstractAdapter.new(:username => username).validate_username
end
end
def test_invalid_passwords
['no spaces allowed', 'a'*33].each do |password|
assert AbstractAdapter.new(:password => password).validate_password.any?
end
end
def test_valid_passwords
[nil,'','abc','a'*32].each do |password|
assert !AbstractAdapter.new(:password => password).validate_password
end
end
def test_invalid_branch_names
['%','a'*81].each do |branch_name|
assert AbstractAdapter.new(:branch_name => branch_name).validate_branch_name.any?
end
end
def test_valid_branch_names
[nil,'','/trunk','_','a'*80].each do |branch_name|
assert !AbstractAdapter.new(:branch_name => branch_name).validate_branch_name
end
end
def test_normalize
scm = AbstractAdapter.new(:url => " http://www.test.org/test ", :username => " joe ", :password => " abc ", :branch_name => " trunk ")
scm.normalize
assert_equal "http://www.test.org/test", scm.url
assert_equal "trunk", scm.branch_name
assert_equal "joe", scm.username
assert_equal "abc", scm.password
end
def test_shellout
cmd = %q( ruby -e" t = 'Hello World'; STDOUT.puts t; STDERR.puts t " )
stdout = AbstractAdapter.run(cmd)
assert_equal "Hello World\n", stdout
end
def test_shellout_with_stderr
cmd = %q( ruby -e" t = 'Hello World'; STDOUT.puts t; STDERR.puts t " )
stdout, stderr, status = AbstractAdapter.run_with_err(cmd)
assert_equal 0, status.exitstatus
assert_equal "Hello World\n", stdout
assert_equal "Hello World\n", stderr
end
def test_shellout_large_output
cat = 'ruby -e" puts Array.new(65536){ 42 } "'
stdout = AbstractAdapter.run(cat)
assert_equal Array.new(65536){ 42 }.join("\n").concat("\n"), stdout
end
def test_shellout_error
cmd = "false"
assert_raise RuntimeError do
stdout = AbstractAdapter.run(cmd)
end
end
def test_string_encoder_must_return_path_to_script
string_encoder_path = File.expand_path('../../../bin/string_encoder', __FILE__)
assert_equal string_encoder_path, AbstractAdapter.new.string_encoder
end
end
end