kanrisuru 0.8.13 → 0.8.17

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +2 -2
  4. data/lib/kanrisuru/core/disk.rb +1 -1
  5. data/lib/kanrisuru/core/stat.rb +1 -3
  6. data/lib/kanrisuru/core/transfer.rb +12 -1
  7. data/lib/kanrisuru/remote/cluster.rb +1 -1
  8. data/lib/kanrisuru/version.rb +1 -1
  9. data/spec/functional/core/path_spec.rb +32 -80
  10. data/spec/functional/core/stat_spec.rb +14 -89
  11. data/spec/functional/core/stream_spec.rb +103 -112
  12. data/spec/functional/core/transfer_spec.rb +175 -102
  13. data/spec/functional/os_package_spec.rb +3 -3
  14. data/spec/helper/expect_helpers.rb +8 -0
  15. data/spec/helper/stub_network.rb +43 -0
  16. data/spec/{functional → integration}/core/apt_spec.rb +0 -0
  17. data/spec/{functional → integration}/core/archive_spec.rb +0 -0
  18. data/spec/{functional → integration}/core/disk_spec.rb +1 -1
  19. data/spec/{functional → integration}/core/dmi_spec.rb +0 -0
  20. data/spec/{functional → integration}/core/file_spec.rb +8 -5
  21. data/spec/{functional → integration}/core/find_spec.rb +0 -0
  22. data/spec/{functional → integration}/core/group_spec.rb +0 -0
  23. data/spec/{functional → integration}/core/ip_spec.rb +0 -0
  24. data/spec/integration/core/path_spec.rb +93 -0
  25. data/spec/{functional → integration}/core/socket_spec.rb +0 -0
  26. data/spec/integration/core/stat_spec.rb +98 -0
  27. data/spec/integration/core/stream_spec.rb +117 -0
  28. data/spec/{functional → integration}/core/system_spec.rb +0 -0
  29. data/spec/integration/core/transfer_spec.rb +108 -0
  30. data/spec/{functional → integration}/core/user_spec.rb +0 -0
  31. data/spec/{functional → integration}/core/yum_spec.rb +0 -0
  32. data/spec/{functional → integration}/core/zypper_spec.rb +0 -0
  33. data/spec/{functional → integration}/remote/cluster_spec.rb +4 -4
  34. data/spec/{functional → integration}/remote/cpu_spec.rb +0 -0
  35. data/spec/{functional → integration}/remote/env_spec.rb +0 -0
  36. data/spec/{functional → integration}/remote/fstab_spec.rb +0 -0
  37. data/spec/{functional → integration}/remote/host_spec.rb +0 -0
  38. data/spec/{functional → integration}/remote/memory_spec.rb +0 -0
  39. data/spec/{functional → integration}/remote/os_spec.rb +0 -0
  40. data/spec/{functional → integration}/remote/remote_file_spec.rb +0 -0
  41. data/spec/spec_helper.rb +3 -0
  42. metadata +29 -23
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2465d4419a5fa15bc4ec736c6064e48386be6e130d4a934404b8a1b0f7eaaa0
4
- data.tar.gz: 5441c0ae297aad2fdc7f08686eca97585793f747aaf92b32339da66c4343f3cf
3
+ metadata.gz: 3fddbe577acc9083ead480c1c69dad8e74c3b00c6a66cd770655b626bf022cb7
4
+ data.tar.gz: dac3e1bfc3ddcb59eff30b620e080210f23e0a2586ab0b38031db01920504c90
5
5
  SHA512:
6
- metadata.gz: 328fdfb44f1d0b18f4bd1fb49ab54779fb464e3f8948a8600f2d2e5cdddfe8ac351fa4499ee0f981a8f12fd262bf1d7757f71d721dafbf447834c8d6ff17ac6f
7
- data.tar.gz: 20c59fd7d9e2e57e356beecf55809c3cbb009fe5d0e8b5692088731ed6bac3665e1e88f6e162d6cda1b7874e8a9a30e30ef52a6c5572cdfbd33f4328ee402eda
6
+ metadata.gz: 43537168eee374dbe372259ea263a139dd9999ad242666e1f036adecee96df6d1040e1a03cc083ca9e1ba6704c61d29c6146e97356951564927278f61e14762a
7
+ data.tar.gz: 45184c4eeafd9447b4e46f323a65d545f666eaeac33bd3e1e19f1d308fc1555ff6042850eecad47368ce5927fa8065b55e6cb141ca09731b3dd190f79fe0134a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## Kanrisuru 0.8.17 (October 16 2021)
2
+ * Add functional test cases for `transfer` module
3
+ * Update wget command to accept hash for `headers` opt.
4
+
5
+ ## Kanrisuru 0.8.16 (October 14, 2021)
6
+ * Add functional test cases for `stream` and `path` modules
7
+ * Create `expect_command` helper for quick testing on raw command result
8
+
9
+ ## Kanrisuru 0.8.15 (October 12, 20201)
10
+ * Move functional specs to integration. Anything that performs an actual network request will be under the integrations test.
11
+ * Create a `StubNetwork` to quickly monkey patch the `Kanrisuru::Remote::Host` to simulate a `Net::SSH` channel request. Will add additional functionality for different simulations later on.
12
+ * Start with testing the `stat` command as a functional test.
13
+
14
+ ## Kanrisuru 0.8.14 (October 8, 20201)
15
+ * Update `Kanrisuru::Remote::Cluster` instantiation method to use array splat instead of passing array directly.
16
+
1
17
  ## Kanrisuru 0.8.13 (October 4, 20201)
2
18
  * Fix `wc` command. Ensure result parsing is cast to integer values.
3
19
 
data/README.md CHANGED
@@ -48,7 +48,7 @@ result.path # => /home/ubuntu
48
48
 
49
49
  ### Cluster
50
50
  ```ruby
51
- cluster = Kanrisuru::Remote::Cluster.new([{
51
+ cluster = Kanrisuru::Remote::Cluster.new({
52
52
  host: 'host1', username: 'ubuntu', keys: ['~/.ssh/id_rsa']
53
53
  }, {
54
54
  host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']
@@ -72,7 +72,7 @@ host.execute(command)
72
72
  command.success? #=> true
73
73
  command.to_s #=> Linux
74
74
 
75
- cluster = Kanrisuru::Remote::Cluster.new([host, {host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']}])
75
+ cluster = Kanrisuru::Remote::Cluster.new(host, {host: 'host2', username: 'alice', keys: ['~/.ssh/id_rsa']})
76
76
 
77
77
  cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', result: 'Linux'}
78
78
  ```
@@ -23,7 +23,7 @@ module Kanrisuru
23
23
  :name, :label, :uuid, :type, :uuid_sub, :label_fatboot, :version, :usage,
24
24
  :part_uuid, :part_entry_scheme, :part_entry_uuid, :part_entry_type,
25
25
  :part_entry_number, :part_entry_offset, :part_entry_size, :part_entry_disk,
26
- :minimum_io_size, :physical_sector_size, :logical_sector_size,
26
+ :minimum_io_size, :physical_sector_size, :logical_sector_size
27
27
  )
28
28
 
29
29
  def du(opts = {})
@@ -66,10 +66,8 @@ module Kanrisuru
66
66
  end
67
67
 
68
68
  def stat(path, opts = {})
69
- follow = opts[:follow]
70
-
71
69
  command = Kanrisuru::Command.new('stat')
72
- command.append_flag('-L', follow)
70
+ command.append_flag('-L', opts[:follow])
73
71
  command.append_arg('-c', '%A,%b,%D,%F,%g,%G,%h,%i,%n,%s,%u,%U,%x,%y,%z')
74
72
  command << path
75
73
 
@@ -124,7 +124,6 @@ module Kanrisuru
124
124
  command.append_flag('--no-cookies', opts[:no_cookies])
125
125
  command.append_flag('--keep-session-cookies', opts[:keep_session_cookies])
126
126
  command.append_flag('--ignore-length', opts[:ignore_length])
127
- command.append_arg('--header', opts[:header])
128
127
  command.append_arg('--max-redirect', opts[:max_redirect])
129
128
  command.append_arg('--proxy-user', opts[:proxy_user])
130
129
  command.append_arg('--proxy-password', opts[:proxy_password])
@@ -132,6 +131,18 @@ module Kanrisuru
132
131
  command.append_flag('--save-headers', opts[:save_headers])
133
132
  command.append_arg('--user-agent', opts[:user_agent])
134
133
 
134
+ headers = opts[:headers]
135
+ if Kanrisuru::Util.present?(headers)
136
+ if headers.instance_of?(Hash)
137
+ headers.each do |key, value|
138
+ header = "'#{key}: #{value}'"
139
+ command.append_arg('--header', header)
140
+ end
141
+ elsif headers.instance_of?(String)
142
+ command.append_arg('--header', headers)
143
+ end
144
+ end
145
+
135
146
  post_data = opts[:post_data]
136
147
 
137
148
  if Kanrisuru::Util.present?(post_data)
@@ -6,7 +6,7 @@ module Kanrisuru
6
6
  extend OsPackage::Collection
7
7
  include Enumerable
8
8
 
9
- def initialize(hosts)
9
+ def initialize(*hosts)
10
10
  @hosts = {}
11
11
  hosts.each do |host_opts|
12
12
  add_host(host_opts)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.13'
4
+ VERSION = '0.8.17'
5
5
  end
@@ -2,92 +2,44 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Path do
6
- TestHosts.each_os do |os_name|
7
- context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
- let(:host) do
10
- Kanrisuru::Remote::Host.new(
11
- host: host_json['hostname'],
12
- username: host_json['username'],
13
- keys: [host_json['ssh_key']]
14
- )
15
- end
16
-
17
- after do
18
- host.disconnect
19
- end
20
-
21
- it 'lists files and directories' do
22
- result = host.ls(all: true)
23
- expect(result.data).to be_instance_of(Array)
24
-
25
- dir = result.find { |file| file.path == '.' }
26
- expect(dir.path).to eq('.')
5
+ StubNetwork.stub!
27
6
 
28
- result = host.ls(path: host_json['home'], id: true, all: true)
29
- expect(result.data).to be_instance_of(Array)
30
-
31
- file = result.find { |f| f.path == '.bashrc' }
32
- expect(file.owner).to eq(1000)
33
-
34
- case os_name
35
- when 'opensuse', 'sles'
36
- expect(file.group).to eq(100)
37
- else
38
- expect(file.group).to eq(1000)
39
- end
40
- end
7
+ RSpec.describe Kanrisuru::Core::Path do
8
+ let(:host) do
9
+ Kanrisuru::Remote::Host.new(
10
+ host: 'localhost',
11
+ username: 'ubuntu',
12
+ keys: ['id_rsa']
13
+ )
14
+ end
41
15
 
42
- it 'gets whoami' do
43
- expect(host.whoami.user).to eq(host_json['username'])
44
- end
16
+ it 'prepares ls command' do
17
+ expect_command(host.ls(path: '/etc'), 'ls -i -l /etc')
18
+ expect_command(host.ls(path: '/var/log', all: true, id: true), 'ls -i -l -a -n /var/log')
19
+ end
45
20
 
46
- it 'gets pwd' do
47
- expect(host.pwd.path).to eq(host_json['home'])
48
- end
21
+ it 'prepares pwd command' do
22
+ expect_command(host.pwd, 'pwd')
23
+ end
49
24
 
50
- it 'uses which to get path for bash' do
51
- result = host.which('bash', all: true)
52
- paths = result.map(&:path)
25
+ it 'prepares whoami command' do
26
+ expect_command(host.whoami, 'whoami')
27
+ end
53
28
 
54
- case os_name
55
- when 'ubuntu'
56
- if host.os.version <= 18.04
57
- expect(paths).to include('/bin/bash')
58
- else
59
- expect(paths).to include('/usr/bin/bash', '/bin/bash')
60
- end
61
- when 'opensuse'
62
- ## Ignore for local testing
63
- when 'sles'
64
- expect(paths).to include('/bin/bash')
65
- else
66
- expect(paths).to include('/usr/bin/bash', '/bin/bash')
67
- end
68
- end
29
+ it 'prepares which command' do
30
+ expect_command(host.which('which'), 'which which')
31
+ expect_command(host.which('pwd', all: true), 'which -a pwd')
32
+ end
69
33
 
70
- it 'gets realpath for dir' do
71
- case os_name
72
- when 'sles'
73
- expect(host.realpath('/var/run').path).to eq('/run')
74
- when 'rhel'
75
- expect(host.realpath('/bin').path).to eq('/usr/bin')
76
- else
77
- expect(host.realpath('/etc/os-release').path).to eq('/usr/lib/os-release')
78
- end
79
- end
34
+ it 'prepares realpath command' do
35
+ expect_command(host.realpath('/etc/os-release'), 'realpath /etc/os-release')
36
+ expect_command(host.realpath('/etc/os-release', strip: true), 'realpath /etc/os-release -s')
37
+ end
80
38
 
81
- it 'gets full path for dir with readlink' do
82
- case os_name
83
- when 'sles'
84
- expect(host.readlink('/var/run', canonicalize: true).path).to eq('/run')
85
- when 'rhel'
86
- expect(host.readlink('/bin', canonicalize: true).path).to eq('/usr/bin')
87
- else
88
- expect(host.readlink('/etc/os-release', canonicalize: true).path).to eq('/usr/lib/os-release')
89
- end
90
- end
91
- end
39
+ it 'prepares readlink command' do
40
+ expect_command(host.readlink('/etc/os-release'), 'readlink /etc/os-release')
41
+ expect_command(host.readlink('/etc/os-release', canonicalize: true), 'readlink -f /etc/os-release')
42
+ expect_command(host.readlink('/etc/os-release', canonicalize_existing: true), 'readlink -e /etc/os-release')
43
+ expect_command(host.readlink('/etc/os-release', canonicalize_missing: true), 'readlink -m /etc/os-release')
92
44
  end
93
45
  end
@@ -2,97 +2,22 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Stat do
6
- TestHosts.each_os do |os_name|
7
- context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
- let(:host) do
10
- Kanrisuru::Remote::Host.new(
11
- host: host_json['hostname'],
12
- username: host_json['username'],
13
- keys: [host_json['ssh_key']]
14
- )
15
- end
16
-
17
- after do
18
- host.disconnect
19
- end
20
-
21
- it 'checks file type correctly' do
22
- expect(host.dir?('/')).to eq(true)
23
- expect(host.file?('/etc/hosts')).to eq(true)
24
-
25
- case os_name
26
- when 'sles'
27
- expect(host.block_device?('/dev/xvda')).to eq(true)
28
- else
29
- expect(host.block_device?('/dev/vda')).to eq(true)
30
- end
31
-
32
- expect(host.char_device?('/dev/tty')).to eq(true)
33
- expect(host.symlink?('/etc/mtab')).to eq(true)
34
- expect(host.inode?('/proc/uptime')).to eq(true)
35
- end
36
-
37
- it 'gets file stat' do
38
- result = host.stat(host_json['home'])
39
-
40
- expect(result.mode).to be_instance_of(Kanrisuru::Mode)
41
- expect(result.mode.directory?).to eq(true)
42
-
43
- case os_name
44
- when 'centos', 'rhel', 'fedora'
45
- expect(result.mode.numeric).to eq('700')
46
- expect(result.mode.to_i).to eq(0o700)
47
-
48
- expect(result.mode.group.read?).to eq(false)
49
- expect(result.mode.group.write?).to eq(false)
50
- expect(result.mode.group.execute?).to eq(false)
51
-
52
- expect(result.mode.other.read?).to eq(false)
53
- expect(result.mode.other.write?).to eq(false)
54
- expect(result.mode.other.execute?).to eq(false)
5
+ StubNetwork.stub!
55
6
 
56
- expect(result.mode.owner.read?).to eq(true)
57
- expect(result.mode.owner.write?).to eq(true)
58
- expect(result.mode.owner.execute?).to eq(true)
59
-
60
- expect(result.mode.symbolic).to eq('drwx------')
61
- else
62
- expect(result.mode.numeric).to eq('755')
63
- expect(result.mode.to_i).to eq(0o755)
64
-
65
- expect(result.mode.group.read?).to eq(true)
66
- expect(result.mode.group.write?).to eq(false)
67
- expect(result.mode.group.execute?).to eq(true)
68
-
69
- expect(result.mode.other.read?).to eq(true)
70
- expect(result.mode.other.write?).to eq(false)
71
- expect(result.mode.other.execute?).to eq(true)
72
-
73
- expect(result.mode.owner.read?).to eq(true)
74
- expect(result.mode.owner.write?).to eq(true)
75
- expect(result.mode.owner.execute?).to eq(true)
76
-
77
- expect(result.mode.symbolic).to eq('drwxr-xr-x')
78
- end
79
-
80
- expect(result.file_type).to eq('directory')
81
-
82
- case os_name
83
- when 'opensuse', 'sles'
84
- expect(result.gid).to eq(100)
85
- expect(result.group).to eq('users')
86
- else
87
- expect(result.gid).to eq(1000)
88
- expect(result.group).to eq(host_json['username'])
89
- end
7
+ RSpec.describe Kanrisuru::Core::Stat do
8
+ let(:host) do
9
+ Kanrisuru::Remote::Host.new(
10
+ host: 'localhost',
11
+ username: 'ubuntu',
12
+ keys: ['id_rsa']
13
+ )
14
+ end
90
15
 
91
- expect(result.uid).to eq(1000)
92
- expect(result.user).to eq(host_json['username'])
16
+ it 'prepares stat command' do
17
+ expect_command(host.stat('~/file1.txt'),
18
+ 'stat -c %A,%b,%D,%F,%g,%G,%h,%i,%n,%s,%u,%U,%x,%y,%z ~/file1.txt')
93
19
 
94
- expect(result.fsize).to be >= 0
95
- end
96
- end
20
+ expect_command(host.stat('~/file2.txt', follow: true),
21
+ 'stat -L -c %A,%b,%D,%F,%g,%G,%h,%i,%n,%s,%u,%U,%x,%y,%z ~/file2.txt')
97
22
  end
98
23
  end
@@ -1,117 +1,108 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spec_helper'
4
+
5
+ StubNetwork.stub!
6
+
3
7
  RSpec.describe Kanrisuru::Core::Stream do
4
- TestHosts.each_os do |os_name|
5
- context "with #{os_name}" do
6
- before(:all) do
7
- host_json = TestHosts.host(os_name)
8
- host = Kanrisuru::Remote::Host.new(
9
- host: host_json['hostname'],
10
- username: host_json['username'],
11
- keys: [host_json['ssh_key']]
12
- )
13
-
14
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
- host.disconnect
16
- end
17
-
18
- let(:host_json) { TestHosts.host(os_name) }
19
- let(:host) do
20
- Kanrisuru::Remote::Host.new(
21
- host: host_json['hostname'],
22
- username: host_json['username'],
23
- keys: [host_json['ssh_key']]
24
- )
25
- end
26
-
27
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
28
-
29
- after do
30
- host.disconnect
31
- end
32
-
33
- after(:all) do
34
- host_json = TestHosts.host(os_name)
35
- host = Kanrisuru::Remote::Host.new(
36
- host: host_json['hostname'],
37
- username: host_json['username'],
38
- keys: [host_json['ssh_key']]
39
- )
40
-
41
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
42
- host.disconnect
43
- end
44
-
45
- it 'outputs beginning of a file' do
46
- file = host.file("#{spec_dir}/test-file.txt")
47
- file.touch
48
- file.append do |f|
49
- f << 'This'
50
- f << 'is'
51
- f << 'a'
52
- f << 'file!'
53
- end
54
-
55
- result = host.head("#{spec_dir}/test-file.txt", lines: 2)
56
- expect(result).to be_success
57
- expect(result.data.length).to eq(2)
58
- expect(result.data).to eq(%w[This is])
59
- end
60
-
61
- it 'outputs end of a file' do
62
- file = host.file("#{spec_dir}/test-file.txt")
63
- file.touch
64
- file.append do |f|
65
- f << 'This'
66
- f << 'is'
67
- f << 'a'
68
- f << 'file!'
69
- end
70
-
71
- result = host.tail("#{spec_dir}/test-file.txt", lines: 2)
72
- expect(result).to be_success
73
- expect(result.data.length).to eq(2)
74
- expect(result.data).to eq(['a', 'file!'])
75
- end
76
-
77
- it 'reads a chunk of text from a file' do
78
- file = host.file("#{spec_dir}/test-file-chunk.txt")
79
- file.touch
80
- file.append do |f|
81
- f << 'This'
82
- f << 'is'
83
- f << 'is'
84
- f << 'a'
85
- f << 'file'
86
- f << 'forever...'
87
- end
88
-
89
- result = host.read_file_chunk("#{spec_dir}/test-file-chunk.txt", 2, 4)
90
- expect(result).to be_success
91
- expect(result.data.length).to eq(3)
92
- expect(result.data).to eq(%w[is is a])
93
- end
94
-
95
- it 'cats a file' do
96
- result = host.cat('/etc/group')
97
- expect(result.success?).to eq(true)
98
- expect(result.data.include?('root:x:0:')).to eq(true)
99
- end
100
-
101
- it 'echoes to stdout' do
102
- result = host.echo('Hello world')
103
- expect(result.data).to eq('Hello world')
104
- end
105
-
106
- it 'seds file to stdout' do
107
- path = "#{spec_dir}/test-file.txt"
108
- result = host.echo("Hello world, this is a Cat test file.\nCat\nCat\nDog", new_file: path, mode: 'write')
109
- expect(result).to be_success
110
-
111
- result = host.sed(path, 'Cat', 'Dog')
112
- expect(result).to be_success
113
- expect(result.data).to eq("Hello world, this is a Dog test file.\nDog\nDog\nDog")
114
- end
115
- end
8
+ let(:host) do
9
+ Kanrisuru::Remote::Host.new(
10
+ host: 'localhost',
11
+ username: 'ubuntu',
12
+ keys: ['id_rsa']
13
+ )
14
+ end
15
+
16
+ it 'prepares head command' do
17
+ result = host.head('/var/log/syslog')
18
+ expect_command(result, 'head /var/log/syslog')
19
+
20
+ result = host.head('/var/log/syslog', bytes: 1024)
21
+ expect_command(result, 'head -c 1024 /var/log/syslog')
22
+
23
+ result = host.head('/var/log/syslog', lines: 50)
24
+ expect_command(result, 'head -n 50 /var/log/syslog')
25
+ end
26
+
27
+ it 'prepares tail command' do
28
+ result = host.tail('/var/log/syslog')
29
+ expect_command(result, 'tail /var/log/syslog')
30
+
31
+ result = host.tail('/var/log/syslog', bytes: 1024)
32
+ expect_command(result, 'tail -c 1024 /var/log/syslog')
33
+
34
+ result = host.tail('/var/log/syslog', lines: 50)
35
+ expect_command(result, 'tail -n 50 /var/log/syslog')
36
+ end
37
+
38
+ it 'prepares read_file_chunk command' do
39
+ result = host.read_file_chunk('/var/log/apache2/access.log', 10, 20)
40
+ expect_command(result, 'tail -n +10 /var/log/apache2/access.log | head -n 11')
41
+
42
+ result = host.read_file_chunk('/var/log/apache2/access.log', 0, 0)
43
+ expect_command(result, 'tail -n +0 /var/log/apache2/access.log | head -n 1')
44
+
45
+ expect do
46
+ host.read_file_chunk('file.log', 10, '20')
47
+ end.to raise_error(ArgumentError)
48
+
49
+ expect do
50
+ host.read_file_chunk('file.log', '10', 20)
51
+ end.to raise_error(ArgumentError)
52
+
53
+ expect do
54
+ host.read_file_chunk('file.log', 10, 9)
55
+ end.to raise_error(ArgumentError)
56
+
57
+ expect do
58
+ host.read_file_chunk('file.log', -1, 1)
59
+ end.to raise_error(ArgumentError)
60
+
61
+ expect do
62
+ host.read_file_chunk('file.log', 10, -2)
63
+ end.to raise_error(ArgumentError)
64
+ end
65
+
66
+ it 'prepares sed command' do
67
+ result = host.sed('~/file.txt', 'Cat', 'Dog')
68
+ expect_command(result, "sed 's/Cat/Dog/g' '~/file.txt'")
69
+
70
+ result = host.sed('~/file.txt', 'Cat', 'Doggz', in_place: true, new_file: '~/file2.txt', mode: 'write')
71
+ expect_command(result, "sed -i 's/Cat/Doggz/g' '~/file.txt' > ~/file2.txt")
72
+
73
+ result = host.sed('~/file.txt', 'Cat', 'Dogo', regexp_extended: true, new_file: '~/file2.txt', mode: 'append')
74
+ expect_command(result, "sed -r 's/Cat/Dogo/g' '~/file.txt' >> ~/file2.txt")
75
+ end
76
+
77
+ it 'prepares echo command' do
78
+ expect_command(host.echo('Hello world'), "echo 'Hello world'")
79
+ expect_command(host.echo('Hello\\n world', backslash: true), "echo -e 'Hello\\n world'")
80
+
81
+ expect_command(host.echo('Hello world', new_file: '~/file1.txt', mode: 'write'),
82
+ "echo 'Hello world' > ~/file1.txt")
83
+
84
+ expect_command(host.echo('Goodbye', new_file: '~/file1.txt', mode: 'append'),
85
+ "echo 'Goodbye' >> ~/file1.txt")
86
+ end
87
+
88
+ it 'prepares cat command' do
89
+ expect_command(host.cat('/etc/group'), 'cat /etc/group')
90
+ expect_command(host.cat('/etc/group', show_all: true), 'cat -A /etc/group')
91
+ expect_command(host.cat('/etc/group',
92
+ show_tabs: true,
93
+ number: true,
94
+ squeeze_blank: true,
95
+ show_nonprinting: true,
96
+ show_ends: true,
97
+ number_nonblank: true), 'cat -T -n -s -v -E -b /etc/group')
98
+
99
+ expect_command(host.cat(['~/file1.txt', '~/file2.txt', '~/file3.txt']),
100
+ 'cat ~/file1.txt ~/file2.txt ~/file3.txt')
101
+
102
+ expect_command(host.cat(['~/file1.txt', '~/file2.txt', '~/file3.txt'], mode: 'write', new_file: 'combined.txt'),
103
+ 'cat ~/file1.txt ~/file2.txt ~/file3.txt > combined.txt')
104
+
105
+ expect_command(host.cat(['~/file1.txt', '~/file2.txt', '~/file3.txt'], mode: 'append', new_file: 'combined.txt'),
106
+ 'cat ~/file1.txt ~/file2.txt ~/file3.txt >> combined.txt')
116
107
  end
117
108
  end