sshkit 1.7.1 → 1.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/.travis.yml +2 -2
- data/BREAKING_API_WISHLIST.md +14 -0
- data/CHANGELOG.md +74 -0
- data/CONTRIBUTING.md +43 -0
- data/EXAMPLES.md +265 -169
- data/Gemfile +7 -0
- data/README.md +274 -9
- data/RELEASING.md +16 -8
- data/Rakefile +8 -0
- data/lib/sshkit.rb +0 -9
- data/lib/sshkit/all.rb +6 -4
- data/lib/sshkit/backends/abstract.rb +42 -42
- data/lib/sshkit/backends/connection_pool.rb +57 -8
- data/lib/sshkit/backends/local.rb +21 -50
- data/lib/sshkit/backends/netssh.rb +45 -98
- data/lib/sshkit/backends/printer.rb +3 -23
- data/lib/sshkit/backends/skipper.rb +4 -8
- data/lib/sshkit/color.rb +51 -20
- data/lib/sshkit/command.rb +68 -47
- data/lib/sshkit/configuration.rb +38 -5
- data/lib/sshkit/deprecation_logger.rb +17 -0
- data/lib/sshkit/formatters/abstract.rb +28 -4
- data/lib/sshkit/formatters/black_hole.rb +1 -2
- data/lib/sshkit/formatters/dot.rb +3 -10
- data/lib/sshkit/formatters/pretty.rb +31 -56
- data/lib/sshkit/formatters/simple_text.rb +6 -44
- data/lib/sshkit/host.rb +5 -6
- data/lib/sshkit/logger.rb +0 -1
- data/lib/sshkit/mapping_interaction_handler.rb +47 -0
- data/lib/sshkit/runners/parallel.rb +1 -1
- data/lib/sshkit/runners/sequential.rb +1 -1
- data/lib/sshkit/version.rb +1 -1
- data/sshkit.gemspec +0 -1
- data/test/functional/backends/test_local.rb +14 -1
- data/test/functional/backends/test_netssh.rb +58 -50
- data/test/helper.rb +2 -2
- data/test/unit/backends/test_abstract.rb +145 -0
- data/test/unit/backends/test_connection_pool.rb +27 -2
- data/test/unit/backends/test_printer.rb +47 -47
- data/test/unit/formatters/test_custom.rb +65 -0
- data/test/unit/formatters/test_dot.rb +25 -32
- data/test/unit/formatters/test_pretty.rb +114 -22
- data/test/unit/formatters/test_simple_text.rb +83 -0
- data/test/unit/test_color.rb +69 -5
- data/test/unit/test_command.rb +53 -18
- data/test/unit/test_command_map.rb +0 -4
- data/test/unit/test_configuration.rb +47 -7
- data/test/unit/test_coordinator.rb +45 -52
- data/test/unit/test_deprecation_logger.rb +38 -0
- data/test/unit/test_host.rb +3 -4
- data/test/unit/test_logger.rb +0 -1
- data/test/unit/test_mapping_interaction_handler.rb +101 -0
- metadata +37 -41
- data/lib/sshkit/utils/capture_output_methods.rb +0 -13
- data/test/functional/test_coordinator.rb +0 -17
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module SSHKit
|
4
|
+
|
5
|
+
class TestDeprecationLogger < UnitTest
|
6
|
+
|
7
|
+
def output
|
8
|
+
@output ||= String.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def logger
|
12
|
+
@logger ||= DeprecationLogger.new(output)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_hides_duplicate_deprecation_warnings
|
16
|
+
line_number = generate_warning
|
17
|
+
generate_warning
|
18
|
+
|
19
|
+
actual_lines = output.lines.to_a
|
20
|
+
|
21
|
+
assert_equal(2, actual_lines.size)
|
22
|
+
assert_equal "[Deprecated] Some message\n", actual_lines[0]
|
23
|
+
assert_match %r{ \(Called from .*sshkit/test/unit/test_deprecation_logger.rb:#{line_number}:in `generate_warning'\)\n}, actual_lines[1]
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_handles_nil_output
|
27
|
+
DeprecationLogger.new(nil).log('Some message')
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def generate_warning
|
33
|
+
logger.log('Some message')
|
34
|
+
__LINE__-1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/test/unit/test_host.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'helper'
|
2
|
-
require 'etc'
|
3
2
|
|
4
3
|
module SSHKit
|
5
4
|
|
@@ -46,8 +45,9 @@ module SSHKit
|
|
46
45
|
h = Host.new :local
|
47
46
|
assert h.local?
|
48
47
|
assert_nil h.port
|
49
|
-
|
50
|
-
assert_equal
|
48
|
+
username_candidates = ENV['USER'] || ENV['LOGNAME'] || ENV['USERNAME']
|
49
|
+
assert_equal username_candidates, h.username
|
50
|
+
assert_equal 'localhost', h.hostname
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_does_not_confuse_ipv6_hosts_with_port_specification
|
@@ -65,7 +65,6 @@ module SSHKit
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def test_assert_hosts_compare_equal
|
68
|
-
assert Host.new('example.com') == Host.new('example.com')
|
69
68
|
assert Host.new('example.com').eql? Host.new('example.com')
|
70
69
|
assert Host.new('example.com').equal? Host.new('example.com')
|
71
70
|
end
|
data/test/unit/test_logger.rb
CHANGED
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module SSHKit
|
4
|
+
|
5
|
+
class TestMappingInteractionHandler < UnitTest
|
6
|
+
def channel
|
7
|
+
@channel ||= mock
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
@output = stub()
|
13
|
+
SSHKit.config.output = @output
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_calls_send_data_with_mapped_input_when_stdout_matches
|
17
|
+
handler = MappingInteractionHandler.new('Server output' => "some input\n")
|
18
|
+
channel.expects(:send_data).with("some input\n")
|
19
|
+
handler.on_data(nil, :stdout, 'Server output', channel)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_calls_send_data_with_mapped_input_when_stderr_matches
|
23
|
+
handler = MappingInteractionHandler.new('Server output' => "some input\n")
|
24
|
+
channel.expects(:send_data).with("some input\n")
|
25
|
+
handler.on_data(nil, :stderr, 'Server output', channel)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_logs_unmatched_interaction_if_constructed_with_a_log_level
|
29
|
+
@output.expects(:debug).with('Looking up response for stdout message "Server output\n"')
|
30
|
+
@output.expects(:debug).with('Unable to find interaction handler mapping for stdout: "Server output\n" so no response was sent')
|
31
|
+
|
32
|
+
MappingInteractionHandler.new({}, :debug).on_data(nil, :stdout, "Server output\n", channel)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_logs_matched_interaction_if_constructed_with_a_log_level
|
36
|
+
handler = MappingInteractionHandler.new({"Server output\n" => "Some input\n"}, :debug)
|
37
|
+
|
38
|
+
channel.stubs(:send_data)
|
39
|
+
@output.expects(:debug).with('Looking up response for stdout message "Server output\n"')
|
40
|
+
@output.expects(:debug).with('Sending "Some input\n"')
|
41
|
+
|
42
|
+
handler.on_data(nil, :stdout, "Server output\n", channel)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_supports_regex_keys
|
46
|
+
handler = MappingInteractionHandler.new({/Some \w+ output\n/ => "Input\n"})
|
47
|
+
channel.expects(:send_data).with("Input\n")
|
48
|
+
handler.on_data(nil, :stdout, "Some lovely output\n", channel)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_supports_lambda_mapping
|
52
|
+
channel.expects(:send_data).with("GREAT Input\n")
|
53
|
+
|
54
|
+
mapping = lambda do |server_output|
|
55
|
+
case server_output
|
56
|
+
when /Some (\w+) output\n/
|
57
|
+
"#{$1.upcase} Input\n"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
MappingInteractionHandler.new(mapping).on_data(nil, :stdout, "Some great output\n", channel)
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def test_matches_keys_in_ofer
|
66
|
+
interaction_handler = MappingInteractionHandler.new({
|
67
|
+
"Specific output\n" => "Specific Input\n",
|
68
|
+
/.*/ => "Default Input\n"
|
69
|
+
})
|
70
|
+
|
71
|
+
channel.expects(:send_data).with("Specific Input\n")
|
72
|
+
interaction_handler.on_data(nil, :stdout, "Specific output\n", channel)
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_supports_default_mapping
|
76
|
+
interaction_handler = MappingInteractionHandler.new({
|
77
|
+
"Specific output\n" => "Specific Input\n",
|
78
|
+
/.*/ => "Default Input\n"
|
79
|
+
})
|
80
|
+
|
81
|
+
channel.expects(:send_data).with("Specific Input\n")
|
82
|
+
interaction_handler.on_data(nil, :stdout, "Specific output\n", channel)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_raises_for_unsupported_mapping_type
|
86
|
+
raised_error = assert_raises RuntimeError do
|
87
|
+
MappingInteractionHandler.new(Object.new)
|
88
|
+
end
|
89
|
+
assert_equal('Unsupported mapping type: Object - only Hash and Proc mappings are supported', raised_error.message)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_raises_for_unsupported_channel_type
|
93
|
+
handler = MappingInteractionHandler.new({"Some output\n" => "Whatever"})
|
94
|
+
raised_error = assert_raises RuntimeError do
|
95
|
+
handler.on_data(nil, :stdout, "Some output\n", Object.new)
|
96
|
+
end
|
97
|
+
assert_match(/Unable to write response data to channel #<Object:.*> - does not support 'send_data' or 'write'/, raised_error.message)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lee Hambley
|
@@ -9,124 +9,110 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: net-ssh
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 2.8.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 2.8.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: net-scp
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - '>='
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: 1.1.2
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: 1.1.2
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: colorize
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - ">="
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 0.7.0
|
49
|
-
type: :runtime
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - ">="
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 0.7.0
|
56
42
|
- !ruby/object:Gem::Dependency
|
57
43
|
name: minitest
|
58
44
|
requirement: !ruby/object:Gem::Requirement
|
59
45
|
requirements:
|
60
|
-
- -
|
46
|
+
- - '>='
|
61
47
|
- !ruby/object:Gem::Version
|
62
48
|
version: 2.11.3
|
63
|
-
- -
|
49
|
+
- - <
|
64
50
|
- !ruby/object:Gem::Version
|
65
51
|
version: 2.12.0
|
66
52
|
type: :development
|
67
53
|
prerelease: false
|
68
54
|
version_requirements: !ruby/object:Gem::Requirement
|
69
55
|
requirements:
|
70
|
-
- -
|
56
|
+
- - '>='
|
71
57
|
- !ruby/object:Gem::Version
|
72
58
|
version: 2.11.3
|
73
|
-
- -
|
59
|
+
- - <
|
74
60
|
- !ruby/object:Gem::Version
|
75
61
|
version: 2.12.0
|
76
62
|
- !ruby/object:Gem::Dependency
|
77
63
|
name: rake
|
78
64
|
requirement: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
|
-
- -
|
66
|
+
- - '>='
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '0'
|
83
69
|
type: :development
|
84
70
|
prerelease: false
|
85
71
|
version_requirements: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- -
|
73
|
+
- - '>='
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '0'
|
90
76
|
- !ruby/object:Gem::Dependency
|
91
77
|
name: turn
|
92
78
|
requirement: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- -
|
80
|
+
- - '>='
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '0'
|
97
83
|
type: :development
|
98
84
|
prerelease: false
|
99
85
|
version_requirements: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- -
|
87
|
+
- - '>='
|
102
88
|
- !ruby/object:Gem::Version
|
103
89
|
version: '0'
|
104
90
|
- !ruby/object:Gem::Dependency
|
105
91
|
name: unindent
|
106
92
|
requirement: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- -
|
94
|
+
- - '>='
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
type: :development
|
112
98
|
prerelease: false
|
113
99
|
version_requirements: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- -
|
101
|
+
- - '>='
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
- !ruby/object:Gem::Dependency
|
119
105
|
name: mocha
|
120
106
|
requirement: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- -
|
108
|
+
- - '>='
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
111
|
type: :development
|
126
112
|
prerelease: false
|
127
113
|
version_requirements: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- -
|
115
|
+
- - '>='
|
130
116
|
- !ruby/object:Gem::Version
|
131
117
|
version: '0'
|
132
118
|
description: A comprehensive toolkit for remotely running commands in a structured
|
@@ -138,9 +124,10 @@ executables: []
|
|
138
124
|
extensions: []
|
139
125
|
extra_rdoc_files: []
|
140
126
|
files:
|
141
|
-
-
|
142
|
-
-
|
143
|
-
-
|
127
|
+
- .gitignore
|
128
|
+
- .travis.yml
|
129
|
+
- .yardopts
|
130
|
+
- BREAKING_API_WISHLIST.md
|
144
131
|
- CHANGELOG.md
|
145
132
|
- CONTRIBUTING.md
|
146
133
|
- EXAMPLES.md
|
@@ -168,6 +155,7 @@ files:
|
|
168
155
|
- lib/sshkit/command_map.rb
|
169
156
|
- lib/sshkit/configuration.rb
|
170
157
|
- lib/sshkit/coordinator.rb
|
158
|
+
- lib/sshkit/deprecation_logger.rb
|
171
159
|
- lib/sshkit/dsl.rb
|
172
160
|
- lib/sshkit/exception.rb
|
173
161
|
- lib/sshkit/formatters/abstract.rb
|
@@ -178,35 +166,39 @@ files:
|
|
178
166
|
- lib/sshkit/host.rb
|
179
167
|
- lib/sshkit/log_message.rb
|
180
168
|
- lib/sshkit/logger.rb
|
169
|
+
- lib/sshkit/mapping_interaction_handler.rb
|
181
170
|
- lib/sshkit/runners/abstract.rb
|
182
171
|
- lib/sshkit/runners/group.rb
|
183
172
|
- lib/sshkit/runners/null.rb
|
184
173
|
- lib/sshkit/runners/parallel.rb
|
185
174
|
- lib/sshkit/runners/sequential.rb
|
186
|
-
- lib/sshkit/utils/capture_output_methods.rb
|
187
175
|
- lib/sshkit/version.rb
|
188
176
|
- sshkit.gemspec
|
189
177
|
- test/boxes.json
|
190
178
|
- test/functional/backends/test_local.rb
|
191
179
|
- test/functional/backends/test_netssh.rb
|
192
|
-
- test/functional/test_coordinator.rb
|
193
180
|
- test/functional/test_ssh_server_comes_up_for_functional_tests.rb
|
194
181
|
- test/helper.rb
|
195
182
|
- test/support/vagrant_wrapper.rb
|
183
|
+
- test/unit/backends/test_abstract.rb
|
196
184
|
- test/unit/backends/test_connection_pool.rb
|
197
185
|
- test/unit/backends/test_local.rb
|
198
186
|
- test/unit/backends/test_netssh.rb
|
199
187
|
- test/unit/backends/test_printer.rb
|
200
188
|
- test/unit/core_ext/test_string.rb
|
189
|
+
- test/unit/formatters/test_custom.rb
|
201
190
|
- test/unit/formatters/test_dot.rb
|
202
191
|
- test/unit/formatters/test_pretty.rb
|
192
|
+
- test/unit/formatters/test_simple_text.rb
|
203
193
|
- test/unit/test_color.rb
|
204
194
|
- test/unit/test_command.rb
|
205
195
|
- test/unit/test_command_map.rb
|
206
196
|
- test/unit/test_configuration.rb
|
207
197
|
- test/unit/test_coordinator.rb
|
198
|
+
- test/unit/test_deprecation_logger.rb
|
208
199
|
- test/unit/test_host.rb
|
209
200
|
- test/unit/test_logger.rb
|
201
|
+
- test/unit/test_mapping_interaction_handler.rb
|
210
202
|
homepage: http://github.com/capistrano/sshkit
|
211
203
|
licenses:
|
212
204
|
- GPL3
|
@@ -217,17 +209,17 @@ require_paths:
|
|
217
209
|
- lib
|
218
210
|
required_ruby_version: !ruby/object:Gem::Requirement
|
219
211
|
requirements:
|
220
|
-
- -
|
212
|
+
- - '>='
|
221
213
|
- !ruby/object:Gem::Version
|
222
214
|
version: '0'
|
223
215
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
224
216
|
requirements:
|
225
|
-
- -
|
217
|
+
- - '>='
|
226
218
|
- !ruby/object:Gem::Version
|
227
219
|
version: '0'
|
228
220
|
requirements: []
|
229
221
|
rubyforge_project:
|
230
|
-
rubygems_version: 2.
|
222
|
+
rubygems_version: 2.0.14
|
231
223
|
signing_key:
|
232
224
|
specification_version: 4
|
233
225
|
summary: SSHKit makes it easy to write structured, testable SSH commands in Ruby
|
@@ -235,21 +227,25 @@ test_files:
|
|
235
227
|
- test/boxes.json
|
236
228
|
- test/functional/backends/test_local.rb
|
237
229
|
- test/functional/backends/test_netssh.rb
|
238
|
-
- test/functional/test_coordinator.rb
|
239
230
|
- test/functional/test_ssh_server_comes_up_for_functional_tests.rb
|
240
231
|
- test/helper.rb
|
241
232
|
- test/support/vagrant_wrapper.rb
|
233
|
+
- test/unit/backends/test_abstract.rb
|
242
234
|
- test/unit/backends/test_connection_pool.rb
|
243
235
|
- test/unit/backends/test_local.rb
|
244
236
|
- test/unit/backends/test_netssh.rb
|
245
237
|
- test/unit/backends/test_printer.rb
|
246
238
|
- test/unit/core_ext/test_string.rb
|
239
|
+
- test/unit/formatters/test_custom.rb
|
247
240
|
- test/unit/formatters/test_dot.rb
|
248
241
|
- test/unit/formatters/test_pretty.rb
|
242
|
+
- test/unit/formatters/test_simple_text.rb
|
249
243
|
- test/unit/test_color.rb
|
250
244
|
- test/unit/test_command.rb
|
251
245
|
- test/unit/test_command_map.rb
|
252
246
|
- test/unit/test_configuration.rb
|
253
247
|
- test/unit/test_coordinator.rb
|
248
|
+
- test/unit/test_deprecation_logger.rb
|
254
249
|
- test/unit/test_host.rb
|
255
250
|
- test/unit/test_logger.rb
|
251
|
+
- test/unit/test_mapping_interaction_handler.rb
|