kanrisuru 0.9.1 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +9 -9
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +7 -8
  4. data/.gitignore +3 -1
  5. data/CHANGELOG.md +151 -130
  6. data/CODE_OF_CONDUCT.md +10 -10
  7. data/README.md +8 -3
  8. data/kanrisuru.gemspec +2 -1
  9. data/lib/kanrisuru/core/archive.rb +6 -5
  10. data/lib/kanrisuru/core/disk.rb +0 -3
  11. data/lib/kanrisuru/core/dmi.rb +1 -1
  12. data/lib/kanrisuru/core/file.rb +2 -2
  13. data/lib/kanrisuru/core/find.rb +4 -5
  14. data/lib/kanrisuru/core/socket.rb +2 -1
  15. data/lib/kanrisuru/core/stream.rb +1 -1
  16. data/lib/kanrisuru/core/zypper.rb +3 -3
  17. data/lib/kanrisuru/remote/cpu.rb +5 -1
  18. data/lib/kanrisuru/remote/env.rb +8 -0
  19. data/lib/kanrisuru/remote/fstab.rb +4 -4
  20. data/lib/kanrisuru/util.rb +1 -1
  21. data/lib/kanrisuru/version.rb +1 -1
  22. data/spec/functional/core/apt_spec.rb +22 -30
  23. data/spec/functional/core/archive_spec.rb +169 -0
  24. data/spec/functional/core/find_spec.rb +94 -113
  25. data/spec/functional/core/socket_spec.rb +23 -28
  26. data/spec/functional/core/stream_spec.rb +12 -12
  27. data/spec/functional/core/transfer_spec.rb +108 -131
  28. data/spec/functional/core/yum_spec.rb +58 -83
  29. data/spec/functional/remote/cluster_spec.rb +12 -3
  30. data/spec/functional/remote/cpu_spec.rb +104 -0
  31. data/spec/functional/remote/env_spec.rb +48 -0
  32. data/spec/helper/stub_network.rb +57 -14
  33. data/spec/integration/core/file_spec.rb +0 -1
  34. data/spec/integration/core/find_spec.rb +1 -0
  35. data/spec/integration/core/system_spec.rb +0 -1
  36. data/spec/integration/core/zypper_spec.rb +3 -3
  37. data/spec/{functional → integration}/os_package_spec.rb +0 -0
  38. data/spec/spec_helper.rb +3 -0
  39. data/spec/unit/command_spec.rb +31 -0
  40. data/spec/unit/core/apt_spec.rb +20 -0
  41. data/spec/unit/core/archive_spec.rb +20 -0
  42. data/spec/unit/core/disk_spec.rb +23 -0
  43. data/spec/unit/core/dmi_spec.rb +20 -0
  44. data/spec/unit/core/file_spec.rb +35 -0
  45. data/spec/unit/core/find_spec.rb +21 -1
  46. data/spec/unit/core/group_spec.rb +24 -0
  47. data/spec/unit/core/ip_spec.rb +20 -0
  48. data/spec/unit/core/path_spec.rb +25 -0
  49. data/spec/unit/core/socket_spec.rb +20 -0
  50. data/spec/unit/core/stat_spec.rb +27 -0
  51. data/spec/unit/core/system_spec.rb +35 -0
  52. data/spec/unit/core/transfer_spec.rb +22 -0
  53. data/spec/unit/core/user_spec.rb +25 -0
  54. data/spec/unit/core/yum_spec.rb +20 -0
  55. data/spec/unit/core/zypper_spec.rb +20 -0
  56. data/spec/unit/mode_spec.rb +33 -2
  57. data/spec/unit/remote/cluster_spec.rb +36 -0
  58. data/spec/unit/remote/cpu_spec.rb +3 -4
  59. data/spec/unit/remote/env_spec.rb +17 -0
  60. data/spec/unit/{fstab_spec.rb → remote/fstab_spec.rb} +0 -0
  61. data/spec/unit/util_spec.rb +13 -0
  62. metadata +26 -5
@@ -23,45 +23,40 @@ RSpec.describe Kanrisuru::Core::Socket do
23
23
  expect_command(host.ss, 'ss -a -m')
24
24
 
25
25
  expect_command(host.ss(
26
- numeric: true,
27
- tcp: true,
28
- udp: true,
29
- unix: true,
30
- raw: true
31
- ),
32
- 'ss -a -m -n -t -u -x -w'
33
- )
26
+ numeric: true,
27
+ tcp: true,
28
+ udp: true,
29
+ unix: true,
30
+ raw: true
31
+ ),
32
+ 'ss -a -m -n -t -u -x -w')
34
33
 
35
34
  expect_command(host.ss(
36
- family: 'inet'
37
- ),
38
- 'ss -a -m -f inet'
39
- )
35
+ family: 'inet'
36
+ ),
37
+ 'ss -a -m -f inet')
40
38
 
41
- expect {
39
+ expect do
42
40
  host.ss(family: 'inet5')
43
- }.to raise_error(ArgumentError)
41
+ end.to raise_error(ArgumentError)
44
42
 
45
43
  expect_command(host.ss(
46
- state: 'established'
47
- ),
48
- 'ss -a -m state established'
49
- )
44
+ state: 'established'
45
+ ),
46
+ 'ss -a -m state established')
50
47
 
51
48
  expect_command(host.ss(
52
- state: 'connected'
53
- ),
54
- 'ss -a -m state connected'
55
- )
49
+ state: 'connected'
50
+ ),
51
+ 'ss -a -m state connected')
56
52
 
57
- expect {
53
+ expect do
58
54
  host.ss(state: 'test')
59
- }.to raise_error(ArgumentError)
55
+ end.to raise_error(ArgumentError)
60
56
 
61
57
  expect_command(host.ss(
62
- expression: "'( dport = :ssh or sport = :ssh )'"
63
- ),
64
- "ss -a -m '( dport = :ssh or sport = :ssh )'"
65
- )
58
+ expression: "'( dport = :ssh or sport = :ssh )'"
59
+ ),
60
+ "ss -a -m '( dport = :ssh or sport = :ssh )'")
66
61
  end
67
62
  end
@@ -85,30 +85,30 @@ RSpec.describe Kanrisuru::Core::Stream do
85
85
  expect_command(host.echo('Hello\\n world', backslash: true), "echo -e 'Hello\\n world'")
86
86
 
87
87
  expect_command(host.echo('Hello world', new_file: '~/file1.txt', mode: 'write'),
88
- "echo 'Hello world' > ~/file1.txt")
89
-
88
+ "echo 'Hello world' > ~/file1.txt")
89
+
90
90
  expect_command(host.echo('Goodbye', new_file: '~/file1.txt', mode: 'append'),
91
- "echo 'Goodbye' >> ~/file1.txt")
91
+ "echo 'Goodbye' >> ~/file1.txt")
92
92
  end
93
93
 
94
94
  it 'prepares cat command' do
95
95
  expect_command(host.cat('/etc/group'), 'cat /etc/group')
96
96
  expect_command(host.cat('/etc/group', show_all: true), 'cat -A /etc/group')
97
97
  expect_command(host.cat('/etc/group',
98
- show_tabs: true,
99
- number: true,
100
- squeeze_blank: true,
101
- show_nonprinting: true,
102
- show_ends: true,
103
- number_nonblank: true), 'cat -T -n -s -v -E -b /etc/group')
98
+ show_tabs: true,
99
+ number: true,
100
+ squeeze_blank: true,
101
+ show_nonprinting: true,
102
+ show_ends: true,
103
+ number_nonblank: true), 'cat -T -n -s -v -E -b /etc/group')
104
104
 
105
105
  expect_command(host.cat(['~/file1.txt', '~/file2.txt', '~/file3.txt']),
106
- 'cat ~/file1.txt ~/file2.txt ~/file3.txt')
106
+ 'cat ~/file1.txt ~/file2.txt ~/file3.txt')
107
107
 
108
108
  expect_command(host.cat(['~/file1.txt', '~/file2.txt', '~/file3.txt'], mode: 'write', new_file: 'combined.txt'),
109
- 'cat ~/file1.txt ~/file2.txt ~/file3.txt > combined.txt')
109
+ 'cat ~/file1.txt ~/file2.txt ~/file3.txt > combined.txt')
110
110
 
111
111
  expect_command(host.cat(['~/file1.txt', '~/file2.txt', '~/file3.txt'], mode: 'append', new_file: 'combined.txt'),
112
- 'cat ~/file1.txt ~/file2.txt ~/file3.txt >> combined.txt')
112
+ 'cat ~/file1.txt ~/file2.txt ~/file3.txt >> combined.txt')
113
113
  end
114
114
  end
@@ -14,7 +14,7 @@ RSpec.describe Kanrisuru::Core::Stat do
14
14
  let(:host) do
15
15
  Kanrisuru::Remote::Host.new(
16
16
  host: 'localhost',
17
- username: 'ubuntu',
17
+ username: 'ubuntu',
18
18
  keys: ['id_rsa']
19
19
  )
20
20
  end
@@ -23,165 +23,142 @@ RSpec.describe Kanrisuru::Core::Stat do
23
23
  url = 'https://rubygems.org'
24
24
 
25
25
  expect_command(host.wget(url),
26
- "wget #{url}"
27
- )
26
+ "wget #{url}")
28
27
 
29
28
  ## Output options
30
- expect_command(host.wget(url,
31
- quiet: true, verbose: false, log_file: '/var/log/wget.log'),
32
- "wget --quiet --no-verbose --output-file /var/log/wget.log #{url}"
33
- )
29
+ expect_command(host.wget(url,
30
+ quiet: true, verbose: false, log_file: '/var/log/wget.log'),
31
+ "wget --quiet --no-verbose --output-file /var/log/wget.log #{url}")
34
32
 
35
- expect_command(host.wget(url,
36
- verbose: true, append_log_file: '/var/log/wget.log'),
37
- "wget --verbose --append-output /var/log/wget.log #{url}"
38
- )
33
+ expect_command(host.wget(url,
34
+ verbose: true, append_log_file: '/var/log/wget.log'),
35
+ "wget --verbose --append-output /var/log/wget.log #{url}")
39
36
 
40
37
  ## Download options
41
38
  expect_command(host.wget(url,
42
- bind_address: '0.0.0.0',
43
- retries: 3,
44
- output_document: '/home/ubuntu/index.html',
45
- no_clobber: true,
46
- timeout: 30,
47
- dns_timeout: 60,
48
- connect_timeout: 60,
49
- read_timeout: 15,
50
- limit_rate: '120k',
51
- wait: 5,
52
- waitretry: 15,
53
- random_wait: true,
54
- no_proxy: true,
55
- no_dns_cache: true
56
- ),
57
- "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"
58
- )
39
+ bind_address: '0.0.0.0',
40
+ retries: 3,
41
+ output_document: '/home/ubuntu/index.html',
42
+ no_clobber: true,
43
+ timeout: 30,
44
+ dns_timeout: 60,
45
+ connect_timeout: 60,
46
+ read_timeout: 15,
47
+ limit_rate: '120k',
48
+ wait: 5,
49
+ waitretry: 15,
50
+ random_wait: true,
51
+ no_proxy: true,
52
+ no_dns_cache: true),
53
+ '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')
59
54
 
60
55
  ## Other Options
61
56
  expect_command(host.wget(url,
62
- quota: 'inf',
63
- family: 'inet',
64
- restrict_file_names: ['unix', 'ascii', 'lowercase', 'uppercase'],
65
- retry_connrefused: true,
66
- user: 'admin',
67
- password: 'admin',
68
- no_iri: true,
69
- ),
70
- "wget --quota inf --restrict-file-names unix,ascii,lowercase,uppercase --inet4-only --retry-connrefused --user admin --password admin --no-iri #{url}"
71
- )
57
+ quota: 'inf',
58
+ family: 'inet',
59
+ restrict_file_names: %w[unix ascii lowercase uppercase],
60
+ retry_connrefused: true,
61
+ user: 'admin',
62
+ password: 'admin',
63
+ no_iri: true),
64
+ "wget --quota inf --restrict-file-names unix,ascii,lowercase,uppercase --inet4-only --retry-connrefused --user admin --password admin --no-iri #{url}")
72
65
 
73
66
  ## Directories
74
67
  expect_command(host.wget(url,
75
- no_directories: true,
76
- no_host_directories: true,
77
- cut_dirs: 3,
78
- directory_prefix: '~/downloads/'
79
- ),
80
- "wget --no-directories --no-host-directories --cut-dirs 3 --directory-prefix ~/downloads/ #{url}"
81
- )
68
+ no_directories: true,
69
+ no_host_directories: true,
70
+ cut_dirs: 3,
71
+ directory_prefix: '~/downloads/'),
72
+ "wget --no-directories --no-host-directories --cut-dirs 3 --directory-prefix ~/downloads/ #{url}")
82
73
 
83
74
  ## HTTP
84
75
  expect_command(host.wget(url,
85
- default_page: 'index.html',
86
- adjust_extension: true,
87
- http_user: 'admin',
88
- http_password: 'admin',
89
- load_cookies: '~/cookies.txt',
90
- save_cookies: '~/cookies.txt',
91
- no_cache: true,
92
- keep_session_cookies: true,
93
- ignore_length: true,
94
- headers: {
95
- 'Accept-Language' => 'hr',
96
- 'Authorization' => 'Bearer 1234'
97
- },
98
- max_redirect: 5,
99
- proxy_user: 'admin',
100
- proxy_password: '12345678'
101
- ),
102
- "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}"
103
- )
76
+ default_page: 'index.html',
77
+ adjust_extension: true,
78
+ http_user: 'admin',
79
+ http_password: 'admin',
80
+ load_cookies: '~/cookies.txt',
81
+ save_cookies: '~/cookies.txt',
82
+ no_cache: true,
83
+ keep_session_cookies: true,
84
+ ignore_length: true,
85
+ headers: {
86
+ 'Accept-Language' => 'hr',
87
+ 'Authorization' => 'Bearer 1234'
88
+ },
89
+ max_redirect: 5,
90
+ proxy_user: 'admin',
91
+ proxy_password: '12345678'),
92
+ "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}")
104
93
 
105
94
  expect_command(host.wget(url,
106
- post_data: {
107
- url: "https://example.com?param=123"
108
- },
109
- content_disposition: true,
110
- secure_protocol: 'SSLv3',
111
- no_check_certificate: true,
112
- ),
113
- "wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --secure-protocol SSLv3 --no-check-certificate #{url}"
114
- )
115
-
116
- expect {
95
+ post_data: {
96
+ url: 'https://example.com?param=123'
97
+ },
98
+ content_disposition: true,
99
+ secure_protocol: 'SSLv3',
100
+ no_check_certificate: true),
101
+ "wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --secure-protocol SSLv3 --no-check-certificate #{url}")
102
+
103
+ expect do
117
104
  host.wget(url, secure_protocol: 'SSL')
118
- }.to raise_error(ArgumentError)
105
+ end.to raise_error(ArgumentError)
119
106
 
120
107
  expect_command(host.wget(url,
121
- certificate: '~/cert.pem',
122
- certificate_type: 'PEM',
123
- private_key: '~/key.pem',
124
- private_key_type: 'PEM',
125
- ca_certificate: '~/ca.pem',
126
- random_file: '~/random'
127
- ),
128
- "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}"
129
- )
108
+ certificate: '~/cert.pem',
109
+ certificate_type: 'PEM',
110
+ private_key: '~/key.pem',
111
+ private_key_type: 'PEM',
112
+ ca_certificate: '~/ca.pem',
113
+ random_file: '~/random'),
114
+ "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}")
130
115
 
131
116
  expect_command(host.wget(url,
132
- certificate: '~/cert.pem',
133
- certificate_type: 'PEM',
134
- private_key: '~/key.pem',
135
- private_key_type: 'PEM',
136
- ca_certificate: '~/ca.pem',
137
- random_file: '~/random'
138
- ),
139
- "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}"
140
- )
117
+ certificate: '~/cert.pem',
118
+ certificate_type: 'PEM',
119
+ private_key: '~/key.pem',
120
+ private_key_type: 'PEM',
121
+ ca_certificate: '~/ca.pem',
122
+ random_file: '~/random'),
123
+ "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}")
141
124
 
142
125
  ## FTP
143
- expect_command(host.wget(url,
144
- ftp_user: 'admin',
145
- ftp_password: '12345678',
146
- no_remove_listing: true,
147
- no_glob: true,
148
- no_passive_ftp: true,
149
- retr_symlinks: true
150
- ),
151
- "wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks #{url}"
152
- )
126
+ expect_command(host.wget(url,
127
+ ftp_user: 'admin',
128
+ ftp_password: '12345678',
129
+ no_remove_listing: true,
130
+ no_glob: true,
131
+ no_passive_ftp: true,
132
+ retr_symlinks: true),
133
+ "wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks #{url}")
153
134
 
154
135
  ## Recursive Retrieval
155
136
  expect_command(host.wget(url,
156
- recursive: true,
157
- depth: 10,
158
- delete_after: true,
159
- convert_links: true,
160
- backup_converted: true,
161
- mirror: true,
162
- page_requisites: true,
163
- strict_comments: true
164
- ),
165
- "wget --recursive --level 10 --delete-after --convert-links --backup-converted --mirror --page-requisites --strict-comments #{url}"
166
- )
137
+ recursive: true,
138
+ depth: 10,
139
+ delete_after: true,
140
+ convert_links: true,
141
+ backup_converted: true,
142
+ mirror: true,
143
+ page_requisites: true,
144
+ strict_comments: true),
145
+ "wget --recursive --level 10 --delete-after --convert-links --backup-converted --mirror --page-requisites --strict-comments #{url}")
167
146
 
168
147
  ## Recursive Accept/Reject
169
148
  expect_command(host.wget(url,
170
- accept_list: ['.txt', '.html'],
171
- reject_list: ['.csv'],
172
- domain_list: ['example.com'],
173
- exclude_domain_list: ['hackernews.com'],
174
- follow_tags: ['a', 'div', 'span'],
175
- ignore_tags: ['area', 'link'],
176
- include_directories: ['/gems'],
177
- exclude_directories: ['/releases'],
178
- follow_ftp: true,
179
- ignore_case: true,
180
- span_hosts: true,
181
- relative: true,
182
- no_parent: true
183
- ),
184
- "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}"
185
- )
149
+ accept_list: ['.txt', '.html'],
150
+ reject_list: ['.csv'],
151
+ domain_list: ['example.com'],
152
+ exclude_domain_list: ['hackernews.com'],
153
+ follow_tags: %w[a div span],
154
+ ignore_tags: %w[area link],
155
+ include_directories: ['/gems'],
156
+ exclude_directories: ['/releases'],
157
+ follow_ftp: true,
158
+ ignore_case: true,
159
+ span_hosts: true,
160
+ relative: true,
161
+ no_parent: true),
162
+ "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}")
186
163
  end
187
164
  end
@@ -20,117 +20,94 @@ RSpec.describe Kanrisuru::Core::Yum do
20
20
  end
21
21
 
22
22
  it 'prepares yum install command' do
23
- expect_command(host.yum('install', packages: 'nginx'),
24
- 'yum install -y nginx'
25
- )
23
+ expect_command(host.yum('install', packages: 'nginx'),
24
+ 'yum install -y nginx')
26
25
 
27
- expect_command(host.yum('install', packages: ['nginx', 'apache2']),
28
- 'yum install -y nginx apache2'
29
- )
26
+ expect_command(host.yum('install', packages: %w[nginx apache2]),
27
+ 'yum install -y nginx apache2')
30
28
  end
31
29
 
32
30
  it 'prepares yum localinstall command' do
33
- expect_command(host.yum('localinstall', repos: 'foo.rpm'),
34
- 'yum localinstall -y foo.rpm'
35
- )
31
+ expect_command(host.yum('localinstall', repos: 'foo.rpm'),
32
+ 'yum localinstall -y foo.rpm')
36
33
 
37
- expect_command(host.yum('localinstall',
38
- repos: ['foo.rpm', 'bar.rpm', 'baz.rpm'],
39
- disable_repo: '*'
40
- ),
41
- 'yum localinstall --disablerepo=* -y foo.rpm bar.rpm baz.rpm'
42
- )
34
+ expect_command(host.yum('localinstall',
35
+ repos: ['foo.rpm', 'bar.rpm', 'baz.rpm'],
36
+ disable_repo: '*'),
37
+ 'yum localinstall --disablerepo=* -y foo.rpm bar.rpm baz.rpm')
43
38
  end
44
39
 
45
40
  it 'prepares yum list command' do
46
- expect_command(host.yum('list'),
47
- "yum list | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
48
- )
41
+ expect_command(host.yum('list'),
42
+ "yum list | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
49
43
 
50
44
  expect_command(host.yum('list', all: true, query: 'ruby*'),
51
- "yum list all ruby* | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
52
- )
53
-
54
- expect_command(host.yum('list',
55
- available: true,
56
- updates: true,
57
- installed: true,
58
- extras: true,
59
- obsoletes: true,
60
- disable_repo: '*'
61
- ),
62
- "yum list --disablerepo=* available updates installed extras obsoletes | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
63
- )
45
+ "yum list all ruby* | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
46
+
47
+ expect_command(host.yum('list',
48
+ available: true,
49
+ updates: true,
50
+ installed: true,
51
+ extras: true,
52
+ obsoletes: true,
53
+ disable_repo: '*'),
54
+ "yum list --disablerepo=* available updates installed extras obsoletes | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
64
55
  end
65
56
 
66
57
  it 'prepares yum search command' do
67
- expect_command(host.yum('search',
68
- packages: 'redis'
69
- ),
70
- "yum search redis | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
71
- )
58
+ expect_command(host.yum('search',
59
+ packages: 'redis'),
60
+ "yum search redis | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
72
61
 
73
62
  expect_command(host.yum('search',
74
- packages: ['package1', 'package2', 'package3'],
75
- all: true
76
- ),
77
- "yum search all package1 package2 package3 | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
78
- )
63
+ packages: %w[package1 package2 package3],
64
+ all: true),
65
+ "yum search all package1 package2 package3 | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
79
66
  end
80
67
 
81
68
  it 'prepares yum info command' do
82
- expect_command(host.yum('info',
83
- packages: 'redis'
84
- ),
85
- "yum info --quiet redis"
86
- )
87
-
88
- expect_command(host.yum('info',
89
- packages: ['package1', 'package2', 'package3'],
90
- installed: true
91
- ),
92
- "yum info --quiet installed package1 package2 package3"
93
- )
69
+ expect_command(host.yum('info',
70
+ packages: 'redis'),
71
+ 'yum info --quiet redis')
72
+
73
+ expect_command(host.yum('info',
74
+ packages: %w[package1 package2 package3],
75
+ installed: true),
76
+ 'yum info --quiet installed package1 package2 package3')
94
77
  end
95
78
 
96
79
  it 'prepares yum repolist command' do
97
80
  expect_command(host.yum('repolist'),
98
- "yum repolist --verbose"
99
- )
81
+ 'yum repolist --verbose')
100
82
 
101
83
  expect_command(host.yum('repolist', repos: 'repo1'),
102
- "yum repolist --verbose repo1"
103
- )
84
+ 'yum repolist --verbose repo1')
104
85
 
105
- expect_command(host.yum('repolist', repos: ['repo1', 'repo2', 'repo3']),
106
- "yum repolist --verbose repo1 repo2 repo3"
107
- )
86
+ expect_command(host.yum('repolist', repos: %w[repo1 repo2 repo3]),
87
+ 'yum repolist --verbose repo1 repo2 repo3')
108
88
  end
109
89
 
110
90
  it 'prepares yum clean command' do
111
91
  expect_command(host.yum('clean'), 'yum clean')
112
92
  expect_command(host.yum('clean', all: true), 'yum clean all')
113
- expect_command(host.yum('clean',
114
- dbcache: true,
115
- expire_cache: true,
116
- metadata: true,
117
- packages: true,
118
- headers: true,
119
- rpmdb: true
120
- ),
121
- "yum clean dbcache expire-cache metadata packages headers rpmdb"
122
- )
123
- end
93
+ expect_command(host.yum('clean',
94
+ dbcache: true,
95
+ expire_cache: true,
96
+ metadata: true,
97
+ packages: true,
98
+ headers: true,
99
+ rpmdb: true),
100
+ 'yum clean dbcache expire-cache metadata packages headers rpmdb')
101
+ end
124
102
 
125
103
  it 'prepares yum remove command' do
126
- expect_command(host.yum('remove', packages: 'gcc'), 'yum remove -y gcc')
127
- expect_command(host.yum('remove', packages: ['p1', 'p2', 'p3']),
128
- 'yum remove -y p1 p2 p3'
129
- )
104
+ expect_command(host.yum('remove', packages: 'gcc'), 'yum remove -y gcc')
105
+ expect_command(host.yum('remove', packages: %w[p1 p2 p3]),
106
+ 'yum remove -y p1 p2 p3')
130
107
 
131
- expect {
108
+ expect do
132
109
  host.yum('remove', packages: 'yum')
133
- }.to raise_error(ArgumentError)
110
+ end.to raise_error(ArgumentError)
134
111
  end
135
112
 
136
113
  it 'prepares yum autoremove command' do
@@ -139,13 +116,12 @@ RSpec.describe Kanrisuru::Core::Yum do
139
116
 
140
117
  it 'prepares yum erase command' do
141
118
  expect_command(host.yum('erase', packages: 'gcc'), 'yum erase -y gcc')
142
- expect_command(host.yum('erase', packages: ['p1', 'p2', 'p3']),
143
- 'yum erase -y p1 p2 p3'
144
- )
119
+ expect_command(host.yum('erase', packages: %w[p1 p2 p3]),
120
+ 'yum erase -y p1 p2 p3')
145
121
 
146
- expect {
122
+ expect do
147
123
  host.yum('erase', packages: 'yum')
148
- }.to raise_error(ArgumentError)
124
+ end.to raise_error(ArgumentError)
149
125
  end
150
126
 
151
127
  it 'prepares yum update command' do
@@ -155,5 +131,4 @@ RSpec.describe Kanrisuru::Core::Yum do
155
131
  it 'prepares yum upgrade command' do
156
132
  expect_command(host.yum('upgrade'), 'yum upgrade -y')
157
133
  end
158
-
159
134
  end
@@ -28,7 +28,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
28
28
  end
29
29
 
30
30
  it 'adds host to a cluster' do
31
- cluster = Kanrisuru::Remote::Cluster.new(host1)
31
+ cluster = described_class.new(host1)
32
32
  expect(cluster.hosts.length).to eq(1)
33
33
  expect(cluster.count).to eq(1)
34
34
  expect(cluster[host1.host]).to eq(host1)
@@ -42,8 +42,17 @@ RSpec.describe Kanrisuru::Remote::Cluster do
42
42
  expect(cluster.hosts).to include(host2)
43
43
  end
44
44
 
45
+ it 'fails to add host to a cluster' do
46
+ cluster = described_class.new
47
+ expect { cluster << 1 }.to raise_error(ArgumentError)
48
+ expect { cluster << 'hello' }.to raise_error(ArgumentError)
49
+ expect { cluster << ['host'] }.to raise_error(ArgumentError)
50
+
51
+ expect(cluster.count).to eq(0)
52
+ end
53
+
45
54
  it 'removes a host from a cluster' do
46
- cluster = Kanrisuru::Remote::Cluster.new(host1, host2)
55
+ cluster = described_class.new(host1, host2)
47
56
  expect(cluster.count).to eq(2)
48
57
 
49
58
  cluster.delete(host2)
@@ -54,4 +63,4 @@ RSpec.describe Kanrisuru::Remote::Cluster do
54
63
  expect(cluster.count).to eq(0)
55
64
  expect(cluster.hosts).not_to include(host1)
56
65
  end
57
- end
66
+ end