-
Notifications
You must be signed in to change notification settings - Fork 253
/
test_command_map.rb
78 lines (62 loc) · 2.18 KB
/
test_command_map.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
require 'helper'
require 'sshkit'
module SSHKit
class TestCommandMap < UnitTest
def test_defaults
map = CommandMap.new
assert_equal map[:rake], "/usr/bin/env rake"
assert_equal map[:test], "test"
end
def test_setter
map = CommandMap.new
map[:rake] = "/usr/local/rbenv/shims/rake"
assert_equal map[:rake], "/usr/local/rbenv/shims/rake"
end
def test_setter_procs
map = CommandMap.new
i = 0
map[:rake] = -> { i += 1; "/usr/local/rbenv/shims/rake#{i}" }
assert_equal map[:rake], "/usr/local/rbenv/shims/rake1"
assert_equal map[:rake], "/usr/local/rbenv/shims/rake2"
end
def test_prefix
map = CommandMap.new
map.prefix[:rake].push("/home/deployer/.rbenv/bin/rbenv exec")
map.prefix[:rake].push("bundle exec")
assert_equal map[:rake], "/home/deployer/.rbenv/bin/rbenv exec bundle exec rake"
end
def test_prefix_procs
map = CommandMap.new
map.prefix[:rake].push("/home/deployer/.rbenv/bin/rbenv exec")
map.prefix[:rake].push(proc{ "bundle exec" })
assert_equal map[:rake], "/home/deployer/.rbenv/bin/rbenv exec bundle exec rake"
end
def test_prefix_unshift
map = CommandMap.new
map.prefix[:rake].push("bundle exec")
map.prefix[:rake].unshift("/home/deployer/.rbenv/bin/rbenv exec")
assert_equal map[:rake], "/home/deployer/.rbenv/bin/rbenv exec bundle exec rake"
end
def test_indifferent_setter
map = CommandMap.new
map[:rake] = "/usr/local/rbenv/shims/rake"
map["rake"] = "/usr/local/rbenv/shims/rake2"
assert_equal "/usr/local/rbenv/shims/rake2", map[:rake]
end
def test_indifferent_prefix
map = CommandMap.new
map.prefix[:rake].push("/home/deployer/.rbenv/bin/rbenv exec")
map.prefix["rake"].push("bundle exec")
assert_equal map[:rake], "/home/deployer/.rbenv/bin/rbenv exec bundle exec rake"
end
def test_prefix_initialization_is_thread_safe
map = CommandMap.new
threads = Array.new(3) do
Thread.new do
(1..1_000).each { |i| assert_equal([], map.prefix[i.to_s]) }
end
end
threads.each(&:join)
end
end
end