kanrisuru 0.9.2 → 0.10.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 584b31f227df31d0a5e45ae8abd18a4a8f87f73622b78cf7a59b66878ac79d4b
4
- data.tar.gz: c0917335ccd0955398574ad61756604e6f3516fd2e73958da733b711c16a152a
3
+ metadata.gz: 40303a0de6eed7d5c10708a31ebf33ee7aed8701a21b3118e9bad5cdc751376b
4
+ data.tar.gz: 9daec56c51d0a4d6929fbcbbb585744215a61d877993e67453899ccf2db81717
5
5
  SHA512:
6
- metadata.gz: f950255db2459f0ead9452c026059723da0deca9e8688dc0efae3c11bf00f3ddc3787f246d99f3ab9cc3893b12915309d91ce2f35c3bd22b8c905a9f5d387387
7
- data.tar.gz: 105d7d7193a037f357e14b31cc7af353a494810287b2dd557861077c27ec83cb64be3e64d2b9f49104438d0c5fe233d79374256c1a098bec8a50de335c3b20ba
6
+ metadata.gz: 11a75804f677a0b72c88ab944c475646eebe68ed64a1fed15acb349e423215f98ddfcdd626681867eee82bb9092cd349ead6f7a44da142937bf329f300a877b0
7
+ data.tar.gz: 2605bbf322b06ae28d49d25b7d65970d5e5632527b79e12c6c7d2988173602ed126eab6d263106d866bda146153513573f702e210a36b4a3ee0e812caae06c79
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## Kanrisuru 0.10.0 (December 03, 2021) ##
2
+ * Add `stub_command` and `unstub_command` to mock indvidual command results from a remote server.
3
+ * Add `count` and `delete` to `Kanrisuru::Remote::Env` class for managing environment variables.
4
+ * Add unit and functional test cases for `Kanrisuru::Remote::Env`.
5
+ * Add functional test cases for the `archive` command.
6
+ * Fix typo bugs in the `archive` command. Fix `--exclude` opt field in `archive` command.
7
+ * Add unit test cases for `Kanrisuru::Mode` class.
8
+
1
9
  ## Kanrisuru 0.9.2 (November 30, 2021) ##
2
10
  * Add unit test cases for all core commands.
3
11
  * Add unit test cases for `cluster` class.
@@ -50,7 +50,7 @@ module Kanrisuru
50
50
  command.append_flag('--same-owner', opts[:same_owners])
51
51
  command.append_flag('--multi-volume', opts[:multi_volume])
52
52
  command.append_flag('--label', opts[:label])
53
- command.append_flag('--one-file-system ', opts[:one_file_system])
53
+ command.append_flag('--one-file-system', opts[:one_file_system])
54
54
  command.append_flag('--keep-old-files', opts[:keep_old_files])
55
55
  command.append_flag('--skip-old-files', opts[:skip_old_files])
56
56
  command.append_flag('--overwrite', opts[:overwrite])
@@ -59,7 +59,7 @@ module Kanrisuru
59
59
  command.append_flag('--recursive-unlink', opts[:recursive_unlink])
60
60
 
61
61
  if Kanrisuru::Util.present?(paths)
62
- paths = paths.instance_of(String) ? [paths] : paths
62
+ paths = paths.instance_of?(String) ? [paths] : paths
63
63
  command << paths.join(' ')
64
64
  end
65
65
 
@@ -70,8 +70,10 @@ module Kanrisuru
70
70
  command.append_flag('--multi-volume', opts[:multi_volume])
71
71
 
72
72
  if Kanrisuru::Util.present?(exclude)
73
- exclude = exclude.instance_of?(String) ? [exclude] : exclude
74
- command.append_arg('--exclude', exclude.join(' '))
73
+ exclude_options = exclude.instance_of?(String) ? [exclude] : exclude
74
+ exclude_options.each do |exclude_option|
75
+ command << "--exclude=#{exclude_option}"
76
+ end
75
77
  end
76
78
 
77
79
  if Kanrisuru::Util.present?(paths)
@@ -80,7 +82,6 @@ module Kanrisuru
80
82
  end
81
83
 
82
84
  execute_shell(command)
83
-
84
85
  Kanrisuru::Result.new(command)
85
86
  when 'append', 'r'
86
87
  command.append_flag('-r')
@@ -25,6 +25,14 @@ module Kanrisuru
25
25
  string
26
26
  end
27
27
 
28
+ def count
29
+ @env.count
30
+ end
31
+
32
+ def delete(key)
33
+ @env.delete(key.to_s.upcase)
34
+ end
35
+
28
36
  def [](key)
29
37
  @env[key.to_s.upcase]
30
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.9.2'
4
+ VERSION = '0.10.0'
5
5
  end
@@ -0,0 +1,194 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Apt do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ StubNetwork.stub_command!(:realpath) do |args|
9
+ Kanrisuru::Core::Path::FilePath.new(directory)
10
+ end
11
+ end
12
+
13
+ after(:all) do
14
+ StubNetwork.unstub_command!(:realpath)
15
+ StubNetwork.unstub!
16
+ end
17
+
18
+ let(:host) do
19
+ Kanrisuru::Remote::Host.new(
20
+ host: 'localhost',
21
+ username: 'ubuntu',
22
+ keys: ['id_rsa']
23
+ )
24
+ end
25
+
26
+ let(:directory) { '/home/ubuntu/dir' }
27
+
28
+ it 'prepares tar list command' do
29
+ ['list', 't'].each do |action_variant|
30
+ expect_command(host.tar(action_variant, 'file.txt'),
31
+ 'tar --restrict -f file.txt -t'
32
+ )
33
+
34
+ expect_command(host.tar(action_variant, '~/file.txt',
35
+ compress: 'bzip2',
36
+ directory: directory,
37
+ occurrence: 1,
38
+ label: true,
39
+ multi_volume: true
40
+ ),
41
+ 'tar --restrict -C /home/ubuntu/dir -f ~/file.txt -j -t --occurrence 1 --label --multi-volume'
42
+ )
43
+ end
44
+ end
45
+
46
+ it 'prepares tar extract command' do
47
+ ['extract', 'get', 'x'].each do |action_variant|
48
+ expect_command(host.tar(action_variant, 'archive.tar'),
49
+ 'tar --restrict -f archive.tar -x'
50
+ )
51
+
52
+ expect_command(host.tar(action_variant, 'archive.tar',
53
+ compress: 'xz',
54
+ directory: directory,
55
+ occurrence: 2,
56
+ no_same_owner: true,
57
+ no_same_permissions: true,
58
+ no_selinux: true,
59
+ no_xattrs: true,
60
+ multi_volume: true,
61
+ label: true,
62
+ skip_old_files: true,
63
+ overwrite: true,
64
+ overwrite_dir: true,
65
+ unlink_first: true,
66
+ recursive_unlink: true,
67
+ paths: 'file.txt'
68
+ ),
69
+ 'tar --restrict -C /home/ubuntu/dir -f archive.tar -J -x --occurrence 2 --no-same-owner --no-same-permissions --no-selinux --no-xattrs --multi-volume --label --skip-old-files --overwrite --overwrite-dir --unlink-first --recursive-unlink file.txt'
70
+ )
71
+
72
+ expect_command(host.tar(action_variant, 'archive.tar',
73
+ preserve_permissions: true,
74
+ same_owners: true,
75
+ one_file_system: true,
76
+ keep_old_files: true,
77
+ paths: ['file1.txt', 'file2.txt']
78
+ ),
79
+ 'tar --restrict -f archive.tar -x --preserve-permissions --same-owner --one-file-system --keep-old-files file1.txt file2.txt'
80
+ )
81
+ end
82
+ end
83
+
84
+ it 'prepares tar create command' do
85
+ ['create', 'c'].each do |action_variant|
86
+ expect_command(host.tar(action_variant, 'archive.lzma', compress: 'lzma'), 'tar --restrict -f archive.lzma --lzma -c')
87
+ expect_command(host.tar(action_variant, 'archive.gz'), 'tar --restrict -f archive.gz -c')
88
+
89
+ expect_command(host.tar(action_variant, 'archive.gz',
90
+ directory: directory,
91
+ compress: 'gzip',
92
+ exclude: 'file2.txt',
93
+ paths: 'file1.txt'
94
+ ),
95
+ 'tar --restrict -C /home/ubuntu/dir -f archive.gz -z -c --exclude=file2.txt file1.txt'
96
+ )
97
+
98
+ expect_command(host.tar(action_variant, 'archive.gz',
99
+ compress: 'gzip',
100
+ exclude: ['file2.txt', 'file4.txt'],
101
+ paths: ['file1.txt', 'file3.txt']
102
+ ),
103
+ 'tar --restrict -f archive.gz -z -c --exclude=file2.txt --exclude=file4.txt file1.txt file3.txt'
104
+ )
105
+ end
106
+ end
107
+
108
+ it 'prepares tar append command' do
109
+ ['append', 'r'].each do |action_variant|
110
+ expect_command(host.tar(action_variant, 'archive.tar'), 'tar --restrict -f archive.tar -r')
111
+
112
+ expect_command(host.tar(action_variant, 'archive.tar',
113
+ directory: directory,
114
+ paths: 'main.conf'
115
+ ),
116
+ 'tar --restrict -C /home/ubuntu/dir -f archive.tar -r main.conf'
117
+ )
118
+
119
+ expect_command(host.tar(action_variant, 'archive.tar',
120
+ paths: ['main.conf', 'main2.conf']
121
+ ),
122
+ 'tar --restrict -f archive.tar -r main.conf main2.conf'
123
+ )
124
+ end
125
+ end
126
+
127
+ it 'prepares tar concat command' do
128
+ ['catenate', 'concat', 'A'].each do |action_variant|
129
+ expect_command(host.tar(action_variant, 'archive.tar'), 'tar --restrict -f archive.tar -A')
130
+ expect_command(host.tar(action_variant, 'archive.tar',
131
+ directory: directory,
132
+ paths: 'archive2.tar'
133
+ ),
134
+ 'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar'
135
+ )
136
+
137
+ expect_command(host.tar(action_variant, 'archive.tar',
138
+ directory: directory,
139
+ paths: ['archive2.tar', 'archive3.tar']
140
+ ),
141
+ 'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar archive3.tar'
142
+ )
143
+ end
144
+ end
145
+
146
+ it 'prepares tar update command' do
147
+ ['update', 'u'].each do |action_variant|
148
+ expect_command(host.tar(action_variant, 'archive',
149
+ paths: 'file1.txt'
150
+ ),
151
+ 'tar --restrict -f archive -u file1.txt'
152
+ )
153
+
154
+ expect_command(host.tar(action_variant, 'archive',
155
+ directory: directory,
156
+ paths: ['file1.txt', 'file2.txt']
157
+ ),
158
+ 'tar --restrict -C /home/ubuntu/dir -f archive -u file1.txt file2.txt'
159
+ )
160
+ end
161
+ end
162
+
163
+ it 'prepares tar diff command' do
164
+ ['diff', 'compare', 'd'].each do |action_variant|
165
+ expect_command(host.tar(action_variant, 'archive.tar', directory: directory), 'tar --restrict -C /home/ubuntu/dir -f archive.tar -d')
166
+ expect_command(host.tar(action_variant, 'archive.tar',
167
+ directory: directory,
168
+ occurrence: 4
169
+ ),
170
+ 'tar --restrict -C /home/ubuntu/dir -f archive.tar -d --occurrence 4'
171
+ )
172
+ end
173
+ end
174
+
175
+ it 'prepares tar delete command' do
176
+ expect_command(host.tar('delete', 'archive.tar', paths: 'file1.txt'), 'tar --restrict -f archive.tar --delete file1.txt')
177
+ expect_command(host.tar('delete', 'archive.tar',
178
+ paths: ['file1.txt', 'file2.txt'],
179
+ occurrence: 3
180
+ ),
181
+ 'tar --restrict -f archive.tar --delete --occurrence 3 file1.txt file2.txt'
182
+ )
183
+ end
184
+
185
+ it 'prepares invalid tar command' do
186
+ expect {
187
+ host.tar('abc', 'file1.txt')
188
+ }.to raise_error(ArgumentError)
189
+
190
+ expect {
191
+ host.tar('create', 'archive.tar', compress: 'xip')
192
+ }.to raise_error(ArgumentError)
193
+ end
194
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Env do
6
+
7
+ let (:env) { Kanrisuru::Remote::Env.new }
8
+
9
+ it 'adds a environment variable' do
10
+ env['VAR1'] = 'hello'
11
+ expect(env.count).to eq(1)
12
+ expect(env.to_h).to eq({'VAR1' => 'hello'})
13
+ expect(env.to_s).to eq('export VAR1=hello;')
14
+ expect(env['VAR1']).to eq('hello')
15
+ end
16
+
17
+ it 'adds multiple environment variables' do
18
+ env['var1'] = 'hello'
19
+ env['var2'] = 'world'
20
+
21
+ expect(env.count).to eq(2)
22
+ expect(env.to_h).to eq({'VAR1' => 'hello', 'VAR2' => 'world'})
23
+ expect(env.to_s).to eq('export VAR1=hello; export VAR2=world;')
24
+ expect(env['VAR1']).to eq('hello')
25
+ expect(env['VAR2']).to eq('world')
26
+ end
27
+
28
+ it 'deletes a variable' do
29
+ env[:var1] = 'foo'
30
+ expect(env.count).to eq(1)
31
+ expect(env[:var1]).to eq('foo')
32
+ env.delete(:var1)
33
+ expect(env.count).to eq(0)
34
+ expect(env.to_s).to eq('')
35
+ end
36
+
37
+ it 'clears the environment' do
38
+ env['VERSION'] = 1
39
+ env['SHELL'] = '/bin/zsh'
40
+ env['USER'] = 'ubuntu'
41
+ env['HOSTNAME'] = 'ubuntu'
42
+ expect(env.to_s).to eq('export VERSION=1; export SHELL=/bin/zsh; export USER=ubuntu; export HOSTNAME=ubuntu;')
43
+
44
+ expect(env.count).to eq(4)
45
+ env.clear
46
+
47
+ expect(env.count).to eq(0)
48
+ end
49
+
50
+ end
@@ -45,6 +45,22 @@ class StubNetwork
45
45
  end
46
46
  end
47
47
 
48
+ def stub_command!(method, &block)
49
+ Kanrisuru::Remote::Host.class_eval do
50
+ alias_method "#{method}_alias", method
51
+
52
+ define_method(method) do |*args|
53
+ block.call(args)
54
+ end
55
+ end
56
+ end
57
+
58
+ def unstub_command!(method)
59
+ Kanrisuru::Remote::Host.class_eval do
60
+ alias_method method, "#{method}_alias"
61
+ end
62
+ end
63
+
48
64
  def unstub!
49
65
  Kanrisuru::Remote::Host.class_eval do
50
66
  alias_method :execute_with_retries, :execute_with_retries_alias
File without changes
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Command do
6
+ it 'responds to methods' do
7
+ command = Kanrisuru::Command.new('ls')
8
+ expect(command).to respond_to(:exit_status)
9
+ expect(command).to respond_to(:raw_result)
10
+ expect(command).to respond_to(:program)
11
+ expect(command).to respond_to(:success?)
12
+ expect(command).to respond_to(:failure?)
13
+ expect(command).to respond_to(:to_i)
14
+ expect(command).to respond_to(:to_s)
15
+ expect(command).to respond_to(:to_a)
16
+ expect(command).to respond_to(:to_json)
17
+ expect(command).to respond_to(:prepared_command)
18
+ expect(command).to respond_to(:raw_command)
19
+ expect(command).to respond_to(:handle_status)
20
+ expect(command).to respond_to(:handle_data)
21
+ expect(command).to respond_to(:handle_signal)
22
+ expect(command).to respond_to(:+)
23
+ expect(command).to respond_to(:<<)
24
+ expect(command).to respond_to(:|)
25
+ expect(command).to respond_to(:pipe)
26
+ expect(command).to respond_to(:append_value)
27
+ expect(command).to respond_to(:append_arg)
28
+ expect(command).to respond_to(:append_flag)
29
+ expect(command).to respond_to(:append_valid_exit_code)
30
+ end
31
+ end
@@ -3,6 +3,18 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Mode do
6
+ it 'responds to methods' do
7
+ mode = described_class.new('644')
8
+ expect(mode).to respond_to(:directory?)
9
+ expect(mode).to respond_to(:symbolic)
10
+ expect(mode).to respond_to(:symbolic=)
11
+ expect(mode).to respond_to(:numeric)
12
+ expect(mode).to respond_to(:numeric=)
13
+ expect(mode).to respond_to(:inspect)
14
+ expect(mode).to respond_to(:to_s)
15
+ expect(mode).to respond_to(:to_i)
16
+ end
17
+
6
18
  it 'parses int mode' do
7
19
  mode = described_class.new('644')
8
20
  expect(mode.directory?).to eq(false)
@@ -205,4 +217,23 @@ RSpec.describe Kanrisuru::Mode do
205
217
  mode.symbolic = '-w'
206
218
  expect(mode.symbolic).to eq('---xr-xr--')
207
219
  end
220
+
221
+ context Kanrisuru::Mode::Permission do
222
+ it 'responds to methods' do
223
+ mode = Kanrisuru::Mode::Permission.new('644', 'rw-rw-r--')
224
+ expect(mode).to respond_to(:to_i)
225
+ expect(mode).to respond_to(:to_s)
226
+ expect(mode).to respond_to(:all?)
227
+ expect(mode).to respond_to(:numeric)
228
+ expect(mode).to respond_to(:numeric=)
229
+ expect(mode).to respond_to(:symbolic=)
230
+ expect(mode).to respond_to(:symbolic)
231
+ expect(mode).to respond_to(:read=)
232
+ expect(mode).to respond_to(:read?)
233
+ expect(mode).to respond_to(:write=)
234
+ expect(mode).to respond_to(:write?)
235
+ expect(mode).to respond_to(:execute=)
236
+ expect(mode).to respond_to(:execute?)
237
+ end
238
+ end
208
239
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Env do
6
+
7
+ it 'responds to methods' do
8
+ env = Kanrisuru::Remote::Env.new
9
+ expect(env).to respond_to(:to_h)
10
+ expect(env).to respond_to(:to_s)
11
+ expect(env).to respond_to(:clear)
12
+ expect(env).to respond_to(:count)
13
+ expect(env).to respond_to(:count)
14
+ expect(env).to respond_to(:delete)
15
+ expect(env).to respond_to(:[])
16
+ expect(env).to respond_to(:[]=)
17
+ end
18
+
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-01 00:00:00.000000000 Z
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -189,6 +189,7 @@ files:
189
189
  - lib/kanrisuru/util/signal.rb
190
190
  - lib/kanrisuru/version.rb
191
191
  - spec/functional/core/apt_spec.rb
192
+ - spec/functional/core/archive_spec.rb
192
193
  - spec/functional/core/find_spec.rb
193
194
  - spec/functional/core/path_spec.rb
194
195
  - spec/functional/core/socket_spec.rb
@@ -196,8 +197,8 @@ files:
196
197
  - spec/functional/core/stream_spec.rb
197
198
  - spec/functional/core/transfer_spec.rb
198
199
  - spec/functional/core/yum_spec.rb
199
- - spec/functional/os_package_spec.rb
200
200
  - spec/functional/remote/cluster_spec.rb
201
+ - spec/functional/remote/env_spec.rb
201
202
  - spec/helper/expect_helpers.rb
202
203
  - spec/helper/stub_network.rb
203
204
  - spec/helper/test_hosts.rb
@@ -219,6 +220,7 @@ files:
219
220
  - spec/integration/core/user_spec.rb
220
221
  - spec/integration/core/yum_spec.rb
221
222
  - spec/integration/core/zypper_spec.rb
223
+ - spec/integration/os_package_spec.rb
222
224
  - spec/integration/remote/cluster_spec.rb
223
225
  - spec/integration/remote/cpu_spec.rb
224
226
  - spec/integration/remote/env_spec.rb
@@ -228,6 +230,7 @@ files:
228
230
  - spec/integration/remote/os_spec.rb
229
231
  - spec/integration/remote/remote_file_spec.rb
230
232
  - spec/spec_helper.rb
233
+ - spec/unit/command_spec.rb
231
234
  - spec/unit/core/apt_spec.rb
232
235
  - spec/unit/core/archive_spec.rb
233
236
  - spec/unit/core/disk_spec.rb
@@ -248,6 +251,7 @@ files:
248
251
  - spec/unit/mode_spec.rb
249
252
  - spec/unit/remote/cluster_spec.rb
250
253
  - spec/unit/remote/cpu_spec.rb
254
+ - spec/unit/remote/env_spec.rb
251
255
  - spec/unit/remote/fstab_spec.rb
252
256
  - spec/unit/template_spec.rb
253
257
  - spec/unit/util_spec.rb