rush2 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -30
- data/VERSION +1 -1
- data/lib/rush.rb +0 -1
- data/lib/rush/commands.rb +24 -6
- data/lib/rush/shell.rb +22 -18
- data/spec/access_spec.rb +34 -34
- data/spec/array_ext_spec.rb +9 -9
- data/spec/box_spec.rb +72 -72
- data/spec/commands_spec.rb +43 -43
- data/spec/embeddable_shell_spec.rb +4 -4
- data/spec/entry_spec.rb +123 -123
- data/spec/file_spec.rb +79 -79
- data/spec/find_by_spec.rb +9 -9
- data/spec/fixnum_ext_spec.rb +3 -3
- data/spec/local_spec.rb +91 -91
- data/spec/process_set_spec.rb +46 -46
- data/spec/process_spec.rb +58 -56
- data/spec/rush_spec.rb +19 -19
- data/spec/shell_spec.rb +1 -1
- data/spec/ssh_tunnel_spec.rb +122 -122
- metadata +3 -5
- data/lib/rush/remote.rb +0 -33
- data/spec/remote_spec.rb +0 -140
data/spec/process_set_spec.rb
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
describe Rush::ProcessSet do
|
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
|
-
|
4
|
+
before do
|
5
|
+
@process = double('process')
|
6
|
+
@set = Rush::ProcessSet.new([ @process ])
|
7
|
+
end
|
8
|
+
|
9
|
+
it "is Enumerable" do
|
10
|
+
expect(@set.select { |s| s == @process }).to eq [ @process ]
|
11
|
+
end
|
12
|
+
|
13
|
+
it "defines size" do
|
14
|
+
expect(@set.size).to eq 1
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defines first" do
|
18
|
+
expect(@set.first).to eq @process
|
19
|
+
end
|
20
|
+
|
21
|
+
it "is equal to sets with the same contents" do
|
22
|
+
expect(@set).to eq Rush::ProcessSet.new([ @process ])
|
23
|
+
end
|
24
|
+
|
25
|
+
it "is equal to arrays with the same contents" do
|
26
|
+
expect(@set).to eq [ @process ]
|
27
|
+
end
|
28
|
+
|
29
|
+
it "kills all processes in the set" do
|
30
|
+
expect(@process).to receive(:kill)
|
31
|
+
@set.kill
|
32
|
+
end
|
33
|
+
|
34
|
+
it "checks the alive? state of all processes in the set" do
|
35
|
+
expect(@process).to receive(:alive?).and_return(true)
|
36
|
+
expect(@set.alive?).to eq [ true ]
|
37
|
+
end
|
38
|
+
|
39
|
+
it "filters the set from a conditions hash and returns the filtered set" do
|
40
|
+
allow(@process).to receive(:pid).and_return(123)
|
41
|
+
expect(@set.filter(:pid => 123).first).to eq @process
|
42
|
+
expect(@set.filter(:pid => 456).size).to eq 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it "filters with regexps if provided in the conditions" do
|
46
|
+
allow(@process).to receive(:command).and_return('foobaz')
|
47
|
+
expect(@set.filter(:command => /baz/).first).to eq @process
|
48
|
+
expect(@set.filter(:command => /blerg/).size).to eq 0
|
49
|
+
end
|
50
50
|
end
|
data/spec/process_spec.rb
CHANGED
@@ -1,73 +1,75 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
describe Rush::Process do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
before do
|
5
|
+
@pid = fork do
|
6
|
+
sleep 999
|
7
|
+
end
|
8
|
+
@process = Rush::Process.all.detect { |p| p.pid == @pid }
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
after do
|
12
|
+
system "kill -9 #{@pid}"
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
unless RUBY_PLATFORM.match(/darwin/) # OS x reports pids weird
|
16
|
+
it 'knows all its child processes' do
|
17
|
+
parent = Rush::Process.all.detect { |p| p.pid == Process.pid }
|
18
|
+
expect(parent.children).to eq [@process]
|
19
|
+
end
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
it 'gets the list of all processes' do
|
23
|
+
list = Rush::Process.all
|
24
|
+
expect(list.size).to be > 5
|
25
|
+
expect(list.first).to be_kind_of Rush::Process
|
26
|
+
end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
it 'knows the pid' do
|
29
|
+
expect(@process.pid).to eq @pid
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
it 'knows the uid' do
|
33
|
+
expect(@process.uid).to eq ::Process.uid
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
it 'knows the executed binary' do
|
37
|
+
expect(@process.command).to match(/(ruby|rbx)/)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
it 'knows the command line' do
|
41
|
+
expect(@process.cmdline).to match(/rspec/)
|
42
|
+
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
it 'knows the memory used' do
|
45
|
+
expect(@process.mem).to be > 0
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
it 'knows the cpu used' do
|
49
|
+
expect(@process.cpu).to be >= 0
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
it 'knows the parent process pid' do
|
53
|
+
expect(@process.parent_pid).to eq Process.pid
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
it 'knows the parent process' do
|
57
|
+
this = Rush::Box.new.processes
|
58
|
+
.select { |p| p.pid == Process.pid }
|
59
|
+
.first
|
60
|
+
expect(@process.parent).to eq this
|
61
|
+
end
|
60
62
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
it 'can kill itself' do
|
64
|
+
process = Rush.bash('sleep 30', background: true)
|
65
|
+
expect(process.alive?).to eq true
|
66
|
+
process.kill
|
67
|
+
sleep 0.1
|
68
|
+
expect(process.alive?).to eq false
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
it 'if box and pid are the same, process is equal' do
|
72
|
+
other = Rush::Process.new({ pid: @process.pid }, @process.box)
|
73
|
+
expect(@process).to eq other
|
74
|
+
end
|
73
75
|
end
|
data/spec/rush_spec.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
|
3
3
|
describe Rush do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
it 'fetches a local file path' do
|
5
|
+
expect(Rush['/etc/hosts'].full_path).to eq('/etc/hosts')
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
it 'fetches the dir of __FILE__' do
|
9
|
+
expect(Rush.dir(__FILE__).name).to eq('spec')
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
it 'fetches the launch dir (aka current working directory or pwd)' do
|
13
|
+
allow(Dir).to receive(:pwd).and_return('/tmp')
|
14
|
+
expect(Rush.launch_dir).to eq(Rush::Box.new['/tmp/'])
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
it 'runs a bash command' do
|
18
|
+
expect(Rush.bash('echo hi')).to eq("hi\n")
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
it 'gets the list of local processes' do
|
22
|
+
expect(Rush.processes).to be_kind_of(Rush::ProcessSet)
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
it 'gets my process' do
|
26
|
+
expect(Rush.my_process.pid).to eq(Process.pid)
|
27
|
+
end
|
28
28
|
end
|
data/spec/shell_spec.rb
CHANGED
@@ -23,7 +23,7 @@ describe Rush::Shell do
|
|
23
23
|
it 'Complete method names' do
|
24
24
|
expect(@shell.complete('Rush.meth')).
|
25
25
|
to eq(["Rush.method_part", "Rush.method_defined?", "Rush.methods", "Rush.method"])
|
26
|
-
expect(@shell.complete('Rush.methods.inc')).to
|
26
|
+
expect(@shell.complete('Rush.methods.inc')).to include "Rush.methods.include?"
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'Complete paths' do
|
data/spec/ssh_tunnel_spec.rb
CHANGED
@@ -1,122 +1,122 @@
|
|
1
|
-
require_relative 'base'
|
2
|
-
|
3
|
-
describe Rush::SshTunnel do
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
end
|
1
|
+
# require_relative 'base'
|
2
|
+
#
|
3
|
+
# describe Rush::SshTunnel do
|
4
|
+
# before do
|
5
|
+
# @tunnel = Rush::SshTunnel.new('spec.example.com')
|
6
|
+
# @tunnel.stub(:config).and_return(mock_config_start)
|
7
|
+
# @tunnel.stub(:display)
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# after do
|
11
|
+
# mock_config_cleanup
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# it "ensure_tunnel sets everything up for the tunnel when one does not already exist" do
|
15
|
+
# @tunnel.should_receive(:push_credentials)
|
16
|
+
# @tunnel.should_receive(:launch_rushd)
|
17
|
+
# @tunnel.should_receive(:establish_tunnel)
|
18
|
+
# @tunnel.ensure_tunnel
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# it "ensure_tunnel uses the existing port as long as the tunnel is still alive" do
|
22
|
+
# @tunnel.should_receive(:tunnel_alive?).and_return(true)
|
23
|
+
# @tunnel.instance_eval("@port = 2345")
|
24
|
+
# @tunnel.ensure_tunnel
|
25
|
+
# @tunnel.port.should == 2345
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# it "existing tunnel is used when it is specified in the tunnels file" do
|
29
|
+
# @tunnel.config.tunnels_file.write "spec.example.com:4567\n"
|
30
|
+
# @tunnel.should_receive(:tunnel_alive?).and_return(true)
|
31
|
+
# @tunnel.should_not_receive(:setup_everything)
|
32
|
+
# @tunnel.ensure_tunnel
|
33
|
+
# @tunnel.port.should == 4567
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# it "tunnel host is always local" do
|
37
|
+
# @tunnel.host.should == 'localhost'
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# it "picks the first port number when there are no tunnels yet" do
|
41
|
+
# @tunnel.next_available_port.should == 7771
|
42
|
+
# end
|
43
|
+
#
|
44
|
+
# it "picks the next port number when there is already a tunnel" do
|
45
|
+
# @tunnel.config.tunnels_file.write("#{@tunnel.host}:7771")
|
46
|
+
# @tunnel.next_available_port.should == 7772
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# it "establishes a tunnel and saves it to ~/.rush/tunnels" do
|
50
|
+
# @tunnel.should_receive(:make_ssh_tunnel)
|
51
|
+
# @tunnel.should_receive(:port).exactly(0).times
|
52
|
+
# @tunnel.establish_tunnel
|
53
|
+
# @tunnel.config.tunnels_file.contents.should == "spec.example.com:7771\n"
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# it "converts instance vars to options hash for ssh_tunnel_command" do
|
57
|
+
# @tunnel.instance_eval("@port = 1234")
|
58
|
+
# @tunnel.tunnel_options.should == {
|
59
|
+
# :local_port => 1234,
|
60
|
+
# :remote_port => 7770,
|
61
|
+
# :ssh_host => 'spec.example.com'
|
62
|
+
# }
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# it "ssh_stall_command uses an infinite loop for :timeout => :infinite" do
|
66
|
+
# @tunnel.ssh_stall_command(:timeout => :infinite).should match(/while .* sleep .* done/)
|
67
|
+
# end
|
68
|
+
#
|
69
|
+
# it "ssh_stall_command sleeps for the number of seconds given as the :timeout option" do
|
70
|
+
# @tunnel.ssh_stall_command(:timeout => 123).should == "sleep 123"
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# it "ssh_stall_command uses the default timeout when no options are given" do
|
74
|
+
# @tunnel.ssh_stall_command.should == "sleep 9000"
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# it "constructs the ssh tunnel command (everything but stall) from the options hash" do
|
78
|
+
# @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(
|
79
|
+
# :local_port => 123,
|
80
|
+
# :remote_port => 456,
|
81
|
+
# :ssh_host => 'example.com'
|
82
|
+
# )
|
83
|
+
# @tunnel.ssh_tunnel_command_without_stall.should == "ssh -f -L 123:127.0.0.1:456 example.com"
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# it "combines the tunnel command without stall and the stall command into the final command" do
|
87
|
+
# @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
|
88
|
+
# @tunnel.should_receive(:ssh_stall_command).and_return('sleep 123')
|
89
|
+
# @tunnel.ssh_tunnel_command.should == 'ssh command "sleep 123"'
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# it "ssh_tunnel_command request that the port be set" do
|
93
|
+
# @tunnel.should_receive(:tunnel_options).at_least(:once).and_return(:local_port => nil)
|
94
|
+
# lambda { @tunnel.ssh_tunnel_command }.should raise_error(Rush::SshTunnel::NoPortSelectedYet)
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
#
|
98
|
+
# it "push_credentials uses ssh to append to remote host's passwords file" do
|
99
|
+
# @tunnel.should_receive(:ssh_append_to_credentials).and_return(true)
|
100
|
+
# @tunnel.push_credentials
|
101
|
+
# end
|
102
|
+
#
|
103
|
+
# it "launches rushd on the remote host via ssh" do
|
104
|
+
# @tunnel.should_receive(:ssh) do |cmd|
|
105
|
+
# cmd.should match(/rushd/)
|
106
|
+
# end
|
107
|
+
# @tunnel.launch_rushd
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# it "tunnel_alive? checks whether a tunnel is still up" do
|
111
|
+
# @tunnel.should_receive(:tunnel_count_command).and_return("echo 1")
|
112
|
+
# @tunnel.tunnel_alive?.should be_true
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# it "tunnel_count_command greps ps to find the ssh tunnel" do
|
116
|
+
# @tunnel.should_receive(:ssh_tunnel_command_without_stall).and_return('ssh command')
|
117
|
+
# command = @tunnel.tunnel_count_command
|
118
|
+
# command.should match(/ps/)
|
119
|
+
# command.should match(/grep/)
|
120
|
+
# command.should match(/ssh command/)
|
121
|
+
# end
|
122
|
+
# end
|