kanrisuru 0.8.13 → 0.8.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +2 -2
- data/lib/kanrisuru/core/disk.rb +1 -1
- data/lib/kanrisuru/core/stat.rb +1 -3
- data/lib/kanrisuru/core/transfer.rb +12 -1
- data/lib/kanrisuru/remote/cluster.rb +1 -1
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/path_spec.rb +32 -80
- data/spec/functional/core/stat_spec.rb +14 -89
- data/spec/functional/core/stream_spec.rb +103 -112
- data/spec/functional/core/transfer_spec.rb +175 -102
- data/spec/functional/os_package_spec.rb +3 -3
- data/spec/helper/expect_helpers.rb +8 -0
- data/spec/helper/stub_network.rb +43 -0
- data/spec/{functional → integration}/core/apt_spec.rb +0 -0
- data/spec/{functional → integration}/core/archive_spec.rb +0 -0
- data/spec/{functional → integration}/core/disk_spec.rb +1 -1
- data/spec/{functional → integration}/core/dmi_spec.rb +0 -0
- data/spec/{functional → integration}/core/file_spec.rb +8 -5
- data/spec/{functional → integration}/core/find_spec.rb +0 -0
- data/spec/{functional → integration}/core/group_spec.rb +0 -0
- data/spec/{functional → integration}/core/ip_spec.rb +0 -0
- data/spec/integration/core/path_spec.rb +93 -0
- data/spec/{functional → integration}/core/socket_spec.rb +0 -0
- data/spec/integration/core/stat_spec.rb +98 -0
- data/spec/integration/core/stream_spec.rb +117 -0
- data/spec/{functional → integration}/core/system_spec.rb +0 -0
- data/spec/integration/core/transfer_spec.rb +108 -0
- data/spec/{functional → integration}/core/user_spec.rb +0 -0
- data/spec/{functional → integration}/core/yum_spec.rb +0 -0
- data/spec/{functional → integration}/core/zypper_spec.rb +0 -0
- data/spec/{functional → integration}/remote/cluster_spec.rb +4 -4
- data/spec/{functional → integration}/remote/cpu_spec.rb +0 -0
- data/spec/{functional → integration}/remote/env_spec.rb +0 -0
- data/spec/{functional → integration}/remote/fstab_spec.rb +0 -0
- data/spec/{functional → integration}/remote/host_spec.rb +0 -0
- data/spec/{functional → integration}/remote/memory_spec.rb +0 -0
- data/spec/{functional → integration}/remote/os_spec.rb +0 -0
- data/spec/{functional → integration}/remote/remote_file_spec.rb +0 -0
- data/spec/spec_helper.rb +3 -0
- metadata +29 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fddbe577acc9083ead480c1c69dad8e74c3b00c6a66cd770655b626bf022cb7
|
4
|
+
data.tar.gz: dac3e1bfc3ddcb59eff30b620e080210f23e0a2586ab0b38031db01920504c90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
```
|
data/lib/kanrisuru/core/disk.rb
CHANGED
@@ -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 = {})
|
data/lib/kanrisuru/core/stat.rb
CHANGED
@@ -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)
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -2,92 +2,44 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
21
|
+
it 'prepares pwd command' do
|
22
|
+
expect_command(host.pwd, 'pwd')
|
23
|
+
end
|
49
24
|
|
50
|
-
|
51
|
-
|
52
|
-
|
25
|
+
it 'prepares whoami command' do
|
26
|
+
expect_command(host.whoami, 'whoami')
|
27
|
+
end
|
53
28
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
92
|
-
|
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
|
-
|
95
|
-
|
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
|
-
|
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
|
-
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
|