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
@@ -2,107 +2,180 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
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
|
-
|
5
|
+
StubNetwork.stub!
|
6
|
+
|
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
|
15
|
+
|
16
|
+
it 'prepares wget command' do
|
17
|
+
url = 'https://rubygems.org'
|
18
|
+
|
19
|
+
expect_command(host.wget(url),
|
20
|
+
"wget #{url}"
|
21
|
+
)
|
22
|
+
|
23
|
+
## Output options
|
24
|
+
expect_command(host.wget(url,
|
25
|
+
quiet: true, verbose: false, log_file: '/var/log/wget.log'),
|
26
|
+
"wget --quiet --no-verbose --output-file /var/log/wget.log #{url}"
|
27
|
+
)
|
28
|
+
|
29
|
+
expect_command(host.wget(url,
|
30
|
+
verbose: true, append_log_file: '/var/log/wget.log'),
|
31
|
+
"wget --verbose --append-output /var/log/wget.log #{url}"
|
32
|
+
)
|
33
|
+
|
34
|
+
## Download options
|
35
|
+
expect_command(host.wget(url,
|
36
|
+
bind_address: '0.0.0.0',
|
37
|
+
retries: 3,
|
38
|
+
output_document: '/home/ubuntu/index.html',
|
39
|
+
no_clobber: true,
|
40
|
+
timeout: 30,
|
41
|
+
dns_timeout: 60,
|
42
|
+
connect_timeout: 60,
|
43
|
+
read_timeout: 15,
|
44
|
+
limit_rate: '120k',
|
45
|
+
wait: 5,
|
46
|
+
waitretry: 15,
|
47
|
+
random_wait: true,
|
48
|
+
no_proxy: true,
|
49
|
+
no_dns_cache: true
|
50
|
+
),
|
51
|
+
"wget --bind-address 0.0.0.0 --tries 3 --output-document /home/ubuntu/index.html --no-clobber --timeout 30 --dns-timeout 60 --connect-timeout 60 --read-timeout 15 --limit-rate 120k --wait 5 --waitretry 15 --random-wait --no-proxy --no-dns-cache https://rubygems.org"
|
52
|
+
)
|
53
|
+
|
54
|
+
## Other Options
|
55
|
+
expect_command(host.wget(url,
|
56
|
+
quota: 'inf',
|
57
|
+
family: 'inet',
|
58
|
+
restrict_file_names: ['unix', 'ascii', 'lowercase', 'uppercase'],
|
59
|
+
retry_connrefused: true,
|
60
|
+
user: 'admin',
|
61
|
+
password: 'admin',
|
62
|
+
no_iri: true,
|
63
|
+
),
|
64
|
+
"wget --quota inf --restrict-file-names unix,ascii,lowercase,uppercase --inet4-only --retry-connrefused --user admin --password admin --no-iri #{url}"
|
65
|
+
)
|
66
|
+
|
67
|
+
## Directories
|
68
|
+
expect_command(host.wget(url,
|
69
|
+
no_directories: true,
|
70
|
+
no_host_directories: true,
|
71
|
+
cut_dirs: 3,
|
72
|
+
directory_prefix: '~/downloads/'
|
73
|
+
),
|
74
|
+
"wget --no-directories --no-host-directories --cut-dirs 3 --directory-prefix ~/downloads/ #{url}"
|
75
|
+
)
|
76
|
+
|
77
|
+
## HTTP
|
78
|
+
expect_command(host.wget(url,
|
79
|
+
default_page: 'index.html',
|
80
|
+
adjust_extension: true,
|
81
|
+
http_user: 'admin',
|
82
|
+
http_password: 'admin',
|
83
|
+
load_cookies: '~/cookies.txt',
|
84
|
+
save_cookies: '~/cookies.txt',
|
85
|
+
no_cache: true,
|
86
|
+
keep_session_cookies: true,
|
87
|
+
ignore_length: true,
|
88
|
+
headers: {
|
89
|
+
'Accept-Language' => 'hr',
|
90
|
+
'Authorization' => 'Bearer 1234'
|
91
|
+
},
|
92
|
+
max_redirect: 5,
|
93
|
+
proxy_user: 'admin',
|
94
|
+
proxy_password: '12345678'
|
95
|
+
),
|
96
|
+
"wget --default-page index.html --adjust-extension --http-user admin --http-password admin --load-cookies ~/cookies.txt --save-cookies ~/cookies.txt --no-cache --keep-session-cookies --ignore-length --max-redirect 5 --proxy-user admin --proxy-password 12345678 --header 'Accept-Language: hr' --header 'Authorization: Bearer 1234' #{url}"
|
97
|
+
)
|
98
|
+
|
99
|
+
expect_command(host.wget(url,
|
100
|
+
post_data: {
|
101
|
+
url: "https://example.com?param=123"
|
102
|
+
},
|
103
|
+
content_disposition: true,
|
104
|
+
secure_protocol: 'SSLv3',
|
105
|
+
no_check_certificate: true,
|
106
|
+
),
|
107
|
+
"wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --secure-protocol SSLv3 --no-check-certificate #{url}"
|
108
|
+
)
|
109
|
+
|
110
|
+
expect {
|
111
|
+
host.wget(url, secure_protocol: 'SSL')
|
112
|
+
}.to raise_error(ArgumentError)
|
113
|
+
|
114
|
+
expect_command(host.wget(url,
|
115
|
+
certificate: '~/cert.pem',
|
116
|
+
certificate_type: 'PEM',
|
117
|
+
private_key: '~/key.pem',
|
118
|
+
private_key_type: 'PEM',
|
119
|
+
ca_certificate: '~/ca.pem',
|
120
|
+
random_file: '~/random'
|
121
|
+
),
|
122
|
+
"wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}"
|
123
|
+
)
|
124
|
+
|
125
|
+
expect_command(host.wget(url,
|
126
|
+
certificate: '~/cert.pem',
|
127
|
+
certificate_type: 'PEM',
|
128
|
+
private_key: '~/key.pem',
|
129
|
+
private_key_type: 'PEM',
|
130
|
+
ca_certificate: '~/ca.pem',
|
131
|
+
random_file: '~/random'
|
132
|
+
),
|
133
|
+
"wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}"
|
134
|
+
)
|
135
|
+
|
136
|
+
## FTP
|
137
|
+
expect_command(host.wget(url,
|
138
|
+
ftp_user: 'admin',
|
139
|
+
ftp_password: '12345678',
|
140
|
+
no_remove_listing: true,
|
141
|
+
no_glob: true,
|
142
|
+
no_passive_ftp: true,
|
143
|
+
retr_symlinks: true
|
144
|
+
),
|
145
|
+
"wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks #{url}"
|
146
|
+
)
|
147
|
+
|
148
|
+
## Recursive Retrieval
|
149
|
+
expect_command(host.wget(url,
|
150
|
+
recursive: true,
|
151
|
+
depth: 10,
|
152
|
+
delete_after: true,
|
153
|
+
convert_links: true,
|
154
|
+
backup_converted: true,
|
155
|
+
mirror: true,
|
156
|
+
page_requisites: true,
|
157
|
+
strict_comments: true
|
158
|
+
),
|
159
|
+
"wget --recursive --level 10 --delete-after --convert-links --backup-converted --mirror --page-requisites --strict-comments #{url}"
|
160
|
+
)
|
161
|
+
|
162
|
+
## Recursive Accept/Reject
|
163
|
+
expect_command(host.wget(url,
|
164
|
+
accept_list: ['.txt', '.html'],
|
165
|
+
reject_list: ['.csv'],
|
166
|
+
domain_list: ['example.com'],
|
167
|
+
exclude_domain_list: ['hackernews.com'],
|
168
|
+
follow_tags: ['a', 'div', 'span'],
|
169
|
+
ignore_tags: ['area', 'link'],
|
170
|
+
include_directories: ['/gems'],
|
171
|
+
exclude_directories: ['/releases'],
|
172
|
+
follow_ftp: true,
|
173
|
+
ignore_case: true,
|
174
|
+
span_hosts: true,
|
175
|
+
relative: true,
|
176
|
+
no_parent: true
|
177
|
+
),
|
178
|
+
"wget --accept .txt,.html --reject .csv --domains example.com --exclude-domains hackernews.com --follow-tags a,div,span --ignore-tags area,link --include-directories /gems --exclude-directories /releases --follow-ftp --ignore-case --span-hosts --relative --no-parent #{url}"
|
179
|
+
)
|
107
180
|
end
|
108
181
|
end
|
@@ -111,7 +111,7 @@ RSpec.describe Kanrisuru::OsPackage do
|
|
111
111
|
host = Kanrisuru::Remote::Host.new(host: '127.0.0.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
|
112
112
|
host2 = Kanrisuru::Remote::Host.new(host: 'localhost', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
|
113
113
|
|
114
|
-
cluster = Kanrisuru::Remote::Cluster.new(
|
114
|
+
cluster = Kanrisuru::Remote::Cluster.new(host, host2)
|
115
115
|
|
116
116
|
expect(host).to respond_to(:tester)
|
117
117
|
expect(host.tester).to eq('hello ubuntu')
|
@@ -125,7 +125,7 @@ RSpec.describe Kanrisuru::OsPackage do
|
|
125
125
|
host = Kanrisuru::Remote::Host.new(host: '127.0.0.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
|
126
126
|
host2 = Kanrisuru::Remote::Host.new(host: 'localhost', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
|
127
127
|
|
128
|
-
cluster = Kanrisuru::Remote::Cluster.new(
|
128
|
+
cluster = Kanrisuru::Remote::Cluster.new(host, host2)
|
129
129
|
|
130
130
|
expect(host).to respond_to(:asdf)
|
131
131
|
expect(host.asdf).to respond_to(:tester)
|
@@ -151,7 +151,7 @@ RSpec.describe Kanrisuru::OsPackage do
|
|
151
151
|
host2 = Kanrisuru::Remote::Host.new(host: 'centos-host', username: 'centos', keys: ['~/.ssh/id_rsa'])
|
152
152
|
host3 = Kanrisuru::Remote::Host.new(host: 'opensuse-host', username: 'opensuse', keys: ['~/.ssh/id_rsa'])
|
153
153
|
|
154
|
-
cluster = Kanrisuru::Remote::Cluster.new(
|
154
|
+
cluster = Kanrisuru::Remote::Cluster.new(host1, host2, host3)
|
155
155
|
|
156
156
|
expect(host1).to respond_to(:output)
|
157
157
|
expect(host2).to respond_to(:output)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class StubNetwork
|
4
|
+
class << self
|
5
|
+
def stub!
|
6
|
+
## Stub out the execute_with_retries method to
|
7
|
+
## test functionality of host commands
|
8
|
+
Kanrisuru::Remote::Host.class_eval do
|
9
|
+
private
|
10
|
+
|
11
|
+
def execute_with_retries(command)
|
12
|
+
command.handle_status(0)
|
13
|
+
command.handle_data(nil)
|
14
|
+
|
15
|
+
command
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Kanrisuru::Remote::Os.class_eval do
|
20
|
+
def initialize(host)
|
21
|
+
@host = host
|
22
|
+
|
23
|
+
@kernel_name = 'Linux'
|
24
|
+
@kernel_version = '#91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021'
|
25
|
+
@operating_system = 'GNU/Linux'
|
26
|
+
@hardware_platform = 'x86_64'
|
27
|
+
@processor = 'x86_64'
|
28
|
+
@release = 'ubuntu'
|
29
|
+
@version = 20.0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
Kanrisuru::Result.class_eval do
|
34
|
+
def initialize(command)
|
35
|
+
@command = command
|
36
|
+
@data = nil
|
37
|
+
|
38
|
+
@error = @command.to_a if @command.failure?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
File without changes
|
File without changes
|
@@ -41,7 +41,7 @@ RSpec.describe Kanrisuru::Core::Disk do
|
|
41
41
|
:name, :label, :uuid, :type, :uuid_sub, :label_fatboot, :version, :usage,
|
42
42
|
:part_uuid, :part_entry_scheme, :part_entry_uuid, :part_entry_type,
|
43
43
|
:part_entry_number, :part_entry_offset, :part_entry_size, :part_entry_disk,
|
44
|
-
:minimum_io_size, :physical_sector_size, :logical_sector_size
|
44
|
+
:minimum_io_size, :physical_sector_size, :logical_sector_size
|
45
45
|
)
|
46
46
|
end
|
47
47
|
|
File without changes
|
@@ -41,7 +41,10 @@ RSpec.describe Kanrisuru::Core::File do
|
|
41
41
|
)
|
42
42
|
|
43
43
|
host.rm("#{host_json['home']}/.kanrisuru_spec_files", force: true, recursive: true)
|
44
|
-
|
44
|
+
if host.dir?("#{host_json['home']}/extract-tar-files")
|
45
|
+
host.rm("#{host_json['home']}/extract-tar-files", force: true,
|
46
|
+
recursive: true)
|
47
|
+
end
|
45
48
|
host.disconnect
|
46
49
|
end
|
47
50
|
|
@@ -68,9 +71,9 @@ RSpec.describe Kanrisuru::Core::File do
|
|
68
71
|
expect(mode.symbolic).to eq('-rwxr--r--')
|
69
72
|
expect(mode.to_i).to eq(0o744)
|
70
73
|
|
71
|
-
expect
|
74
|
+
expect do
|
72
75
|
host.chmod(path, 600)
|
73
|
-
|
76
|
+
end.to raise_error(ArgumentError)
|
74
77
|
end
|
75
78
|
|
76
79
|
it 'changes file owner and group' do
|
@@ -338,7 +341,7 @@ RSpec.describe Kanrisuru::Core::File do
|
|
338
341
|
## Can't delete non empty dir
|
339
342
|
result = host.rmdir("#{spec_dir}/directory")
|
340
343
|
expect(result).to be_failure
|
341
|
-
|
344
|
+
|
342
345
|
result = host.rmdir("#{spec_dir}/directory/3")
|
343
346
|
expect(result).to be_success
|
344
347
|
end
|
@@ -355,7 +358,7 @@ RSpec.describe Kanrisuru::Core::File do
|
|
355
358
|
|
356
359
|
lines = doc.length
|
357
360
|
words = doc.map(&:split).flatten
|
358
|
-
chars = doc.map(&:length).flatten
|
361
|
+
chars = doc.map(&:length).flatten
|
359
362
|
|
360
363
|
expect(result.lines).to eq(doc.length)
|
361
364
|
expect(result.words).to eq(words.length)
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
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('.')
|
27
|
+
|
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
|
41
|
+
|
42
|
+
it 'gets whoami' do
|
43
|
+
expect(host.whoami.user).to eq(host_json['username'])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'gets pwd' do
|
47
|
+
expect(host.pwd.path).to eq(host_json['home'])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'uses which to get path for bash' do
|
51
|
+
result = host.which('bash', all: true)
|
52
|
+
paths = result.map(&:path)
|
53
|
+
|
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
|
69
|
+
|
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
|
80
|
+
|
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
|
92
|
+
end
|
93
|
+
end
|
File without changes
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
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)
|
55
|
+
|
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
|
90
|
+
|
91
|
+
expect(result.uid).to eq(1000)
|
92
|
+
expect(result.user).to eq(host_json['username'])
|
93
|
+
|
94
|
+
expect(result.fsize).to be >= 0
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|