scutil 0.2.4 → 0.3.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.
@@ -1,6 +1,11 @@
1
1
 
2
2
  ==Changelog
3
3
 
4
+ ===0.3.0 | 2011-10-11
5
+
6
+ * Added set_options method to instance.
7
+ * Bug fixes.
8
+
4
9
  ===0.2.4 | 2011-10-02
5
10
 
6
11
  * More verbose logging.
File without changes
data/lib/scutil.rb CHANGED
@@ -30,7 +30,7 @@ require 'scutil/connection_cache'
30
30
  require 'scutil/system_connection'
31
31
 
32
32
  module Scutil
33
- SCUTIL_VERSION = '0.2.4'
33
+ SCUTIL_VERSION = '0.3.0'
34
34
  # By default, buffer 10M of data before writing.
35
35
  DEFAULT_OUTPUT_BUFFER_SIZE = 0xA00000
36
36
  # Checks for a command starting with _sudo_ by default.
@@ -195,7 +195,6 @@ module Scutil
195
195
  end
196
196
 
197
197
  channel.exec(cmd)
198
- # channel.wait
199
198
  end
200
199
 
201
200
  conn.loop
@@ -210,8 +209,4 @@ module Scutil
210
209
  return exit_status
211
210
  end
212
211
  end
213
-
214
- # def xfer_file(hostname, username, src, dst, direction=:to, command=nil, options={})
215
-
216
- # end
217
212
  end
data/lib/scutil/exec.rb CHANGED
@@ -15,7 +15,7 @@ module Scutil
15
15
  class Exec
16
16
  include Scutil
17
17
  attr_reader :hostname,:username
18
-
18
+
19
19
  def initialize(hostname, username, options={})
20
20
  @hostname = hostname
21
21
  @username = username
@@ -30,9 +30,13 @@ module Scutil
30
30
  # specified in the constructor.
31
31
  def exec_command(cmd, output=nil, options={})
32
32
  # Local map has precedence.
33
- @options.merge!(options)
33
+ set_options(options)
34
34
  Scutil.exec_command(@hostname, @username, cmd, output, @options)
35
35
  end
36
- # TODO: options should be customizable via an instance method.
36
+
37
+ def set_options(options={})
38
+ # Local map has precedence.
39
+ @options.merge!(options)
40
+ end
37
41
  end
38
42
  end
data/scutil.gemspec CHANGED
@@ -1,7 +1,8 @@
1
+
1
2
  Gem::Specification.new do |s|
2
3
  s.name = 'scutil'
3
- s.version = '0.2.4'
4
- s.date = '2011-10-02'
4
+ s.version = '0.3.0'
5
+ s.date = '2011-10-11'
5
6
  s.summary = 'SSH Command UTILity'
6
7
  s.description = <<-EOF
7
8
  Scutil is a library for conveniently executing commands
@@ -11,8 +12,8 @@ EOF
11
12
  s.email = 'marcantoniosr@gmail.com'
12
13
  s.license = 'MIT'
13
14
  s.homepage = 'http://marcantonio.github.com/scutil'
14
- s.rdoc_options << '--title' << 'SSH Command UTILity' << '--main' << 'README'
15
- s.extra_rdoc_files = ['README', 'THANKS', 'CHANGELOG']
15
+ s.rdoc_options << '--title' << 'SSH Command UTILity' << '--main' << 'README.rdoc'
16
+ s.extra_rdoc_files = ['README.rdoc', 'THANKS', 'CHANGELOG.md']
16
17
  s.add_runtime_dependency 'net-ssh', '>= 2.1.0'
17
18
  s.files = %w(
18
19
  lib/scutil.rb
@@ -21,8 +22,8 @@ lib/scutil/error.rb
21
22
  lib/scutil/exec.rb
22
23
  lib/scutil/system_connection.rb
23
24
  scutil.gemspec
24
- README
25
- CHANGELOG
25
+ README.rdoc
26
+ CHANGELOG.md
26
27
  THANKS
27
28
  test/test_scutil.rb
28
29
  )
data/test/test_scutil.rb CHANGED
@@ -127,8 +127,84 @@ class TestScutil < Test::Unit::TestCase
127
127
  assert_instance_of(Net::SSH::Connection::Session, conn.pty_connection)
128
128
  assert_nil(conn.connection)
129
129
  end
130
+
131
+ def test_alter_options
132
+ divert_stdout
133
+ @exec.exec_command(TRUE_COMMAND)
134
+ revert_stdout
135
+ assert_not_match(/\[#{TestScutil.hostname}\]/, @output.string)
136
+
137
+ @exec.set_options({ :scutil_verbose => true })
138
+
139
+ divert_stdout
140
+ @exec.exec_command(TRUE_COMMAND)
141
+ revert_stdout
142
+ assert_match(/\[#{TestScutil.hostname}\]/, @output.string)
143
+ end
144
+ end
145
+
146
+ class TestScutilAlt < Test::Unit::TestCase
147
+ TRUE_COMMAND = '/bin/true'
148
+ FALSE_COMMAND = '/bin/false'
149
+ FAKE_COMMAND = '/bin/no_such_command'
150
+
151
+ @hostname = nil
152
+ @port = nil
153
+ @user = nil
154
+
155
+ class << self
156
+ attr_accessor :hostname,:port,:user
157
+ end
158
+
159
+ def divert_stdout
160
+ @tmp_output = $stdout
161
+ $stdout = StringIO.new
162
+ end
163
+
164
+ def revert_stdout
165
+ @output = $stdout
166
+ $stdout = @tmp_output
167
+ end
168
+
169
+ def setup
170
+ @output = nil
171
+ @tmp_output = nil
172
+ end
173
+
174
+ def test_exec_doesnt_raise_an_exception
175
+ assert_nothing_raised do
176
+ Scutil.exec_command(TestScutil.hostname, TestScutil.user, TRUE_COMMAND, nil, { :port => TestScutil.port })
177
+ end
178
+ end
179
+
180
+ def test_run_successful_command
181
+ retval = Scutil.exec_command(TestScutil.hostname, TestScutil.user, TRUE_COMMAND, nil, { :port => TestScutil.port })
182
+ assert_equal 0, retval
183
+ end
184
+
185
+ def test_run_failed_command
186
+ retval = Scutil.exec_command(TestScutil.hostname, TestScutil.user, FALSE_COMMAND, nil, { :port => TestScutil.port })
187
+ assert_not_equal 0, retval
188
+ end
189
+
190
+ def test_added_to_cache
191
+ Scutil.exec_command(TestScutil.hostname, TestScutil.user, TRUE_COMMAND, nil, { :port => TestScutil.port })
192
+ assert(Scutil.connection_cache.exists?(TestScutil.hostname))
193
+ end
194
+
195
+ def test_exec_command_output
196
+ divert_stdout
197
+ Scutil.exec_command(TestScutil.hostname, TestScutil.user, 'echo "alpha"', nil, { :port => TestScutil.port })
198
+ revert_stdout
199
+ assert_equal "alpha", @output.string.chomp
200
+ end
201
+
202
+ def teardown
203
+ Scutil.connection_cache.remove_all
204
+ end
130
205
  end
131
206
 
207
+ # XXX: This breaks --name, et al.
132
208
  if ARGV[0].nil?
133
209
  puts "Usage: #{$0} host[:port]"
134
210
  exit(1)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: scutil
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.4
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marc Soda
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-02 00:00:00 Z
13
+ date: 2011-10-11 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-ssh
@@ -30,9 +30,9 @@ executables: []
30
30
  extensions: []
31
31
 
32
32
  extra_rdoc_files:
33
- - README
33
+ - README.rdoc
34
34
  - THANKS
35
- - CHANGELOG
35
+ - CHANGELOG.md
36
36
  files:
37
37
  - lib/scutil.rb
38
38
  - lib/scutil/connection_cache.rb
@@ -40,8 +40,8 @@ files:
40
40
  - lib/scutil/exec.rb
41
41
  - lib/scutil/system_connection.rb
42
42
  - scutil.gemspec
43
- - README
44
- - CHANGELOG
43
+ - README.rdoc
44
+ - CHANGELOG.md
45
45
  - THANKS
46
46
  - test/test_scutil.rb
47
47
  homepage: http://marcantonio.github.com/scutil
@@ -52,7 +52,7 @@ rdoc_options:
52
52
  - --title
53
53
  - SSH Command UTILity
54
54
  - --main
55
- - README
55
+ - README.rdoc
56
56
  require_paths:
57
57
  - lib
58
58
  required_ruby_version: !ruby/object:Gem::Requirement