kanrisuru 0.8.14 → 0.8.15

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/lib/kanrisuru/core/stat.rb +1 -3
  4. data/lib/kanrisuru/version.rb +1 -1
  5. data/spec/functional/core/stat_spec.rb +19 -89
  6. data/spec/helper/stub_network.rb +45 -0
  7. data/spec/{functional → integration}/core/apt_spec.rb +0 -0
  8. data/spec/{functional → integration}/core/archive_spec.rb +0 -0
  9. data/spec/{functional → integration}/core/disk_spec.rb +0 -0
  10. data/spec/{functional → integration}/core/dmi_spec.rb +0 -0
  11. data/spec/{functional → integration}/core/file_spec.rb +0 -0
  12. data/spec/{functional → integration}/core/find_spec.rb +0 -0
  13. data/spec/{functional → integration}/core/group_spec.rb +0 -0
  14. data/spec/{functional → integration}/core/ip_spec.rb +0 -0
  15. data/spec/{functional → integration}/core/path_spec.rb +0 -0
  16. data/spec/{functional → integration}/core/socket_spec.rb +0 -0
  17. data/spec/integration/core/stat_spec.rb +98 -0
  18. data/spec/{functional → integration}/core/stream_spec.rb +0 -0
  19. data/spec/{functional → integration}/core/system_spec.rb +0 -0
  20. data/spec/{functional → integration}/core/transfer_spec.rb +0 -0
  21. data/spec/{functional → integration}/core/user_spec.rb +0 -0
  22. data/spec/{functional → integration}/core/yum_spec.rb +0 -0
  23. data/spec/{functional → integration}/core/zypper_spec.rb +0 -0
  24. data/spec/{functional → integration}/remote/cluster_spec.rb +0 -0
  25. data/spec/{functional → integration}/remote/cpu_spec.rb +0 -0
  26. data/spec/{functional → integration}/remote/env_spec.rb +0 -0
  27. data/spec/{functional → integration}/remote/fstab_spec.rb +0 -0
  28. data/spec/{functional → integration}/remote/host_spec.rb +0 -0
  29. data/spec/{functional → integration}/remote/memory_spec.rb +0 -0
  30. data/spec/{functional → integration}/remote/os_spec.rb +0 -0
  31. data/spec/{functional → integration}/remote/remote_file_spec.rb +0 -0
  32. data/spec/spec_helper.rb +1 -0
  33. metadata +28 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1537cdde3ded7563e59018ddb94f1c05bb17ff486c87f6113eaa1800b6f7c338
4
- data.tar.gz: 571b0fef3b4d780d3fac4f485f7f1b1dd14bd3c73253a7b5649ae7e86975fd81
3
+ metadata.gz: 522ae1903fe51ff350abc0fafa252d1b66f970710d4bed41748be03cc25ead3d
4
+ data.tar.gz: 501c4b568aeed1bca4e22658291ebab44e9cb9ebb84c23f5154dc4c97e5daf08
5
5
  SHA512:
6
- metadata.gz: 2351ae7e335b61a1362c15a08540977c5d366ae2c441882f4feff32bc7939da71312dc5f380fa707a6c3cb187e81d413d558ae55e31e395d069e1a3c5e3f2a08
7
- data.tar.gz: 2fbb6a9649eb2a67c46bc0a617cd22965738dfcbb092b4b99da588ae70518b4a0dfc79aa2da55c58d53f760170a5c33c844a86aae97f56eeed4628c735a65546
6
+ metadata.gz: 59fbae207747c7b7c93461a48f12cd959d8dcd2b2853619cb15624627534bca2a84fdf88c068285ef2cbb7a1ac48c74d592f784374847e3f89b35faa85de5366
7
+ data.tar.gz: 8981e523f2373b7eb4740e1c6b1af2318cb45ba960a92e620f368d502a5359f68402fa23c2607f449e563c451b6b5d0efce9cba8ef45ffa4252b4158bd9a09a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## Kanrisuru 0.8.15 (October 12, 20201)
2
+ * Move functional specs to integration. Anything that performs an actual network request will be under the integrations test.
3
+ * 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.
4
+ * Start with testing the `stat` command as a functional test.
5
+
1
6
  ## Kanrisuru 0.8.14 (October 8, 20201)
2
7
  * Update `Kanrisuru::Remote::Cluster` instantiation method to use array splat instead of passing array directly.
3
8
 
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.14'
4
+ VERSION = '0.8.15'
5
5
  end
@@ -2,97 +2,27 @@
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
+ result = host.stat('~/file1.txt')
18
+ expect(result.command.raw_command).to eq(
19
+ 'stat -c %A,%b,%D,%F,%g,%G,%h,%i,%n,%s,%u,%U,%x,%y,%z ~/file1.txt'
20
+ )
93
21
 
94
- expect(result.fsize).to be >= 0
95
- end
96
- end
22
+ result = host.stat('~/file2.txt', follow: true)
23
+ expect(result.command.raw_command).to eq(
24
+ 'stat -L -c %A,%b,%D,%F,%g,%G,%h,%i,%n,%s,%u,%U,%x,%y,%z ~/file1.txt'
25
+ )
97
26
  end
27
+
98
28
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StubNetwork
4
+ class << self
5
+
6
+ def stub!
7
+ ## Stub out the execute_with_retries method to
8
+ ## test functionality of host commands
9
+ Kanrisuru::Remote::Host.class_eval do
10
+ private
11
+
12
+ def execute_with_retries(command)
13
+ command.handle_status(0)
14
+ command.handle_data(nil)
15
+
16
+ command
17
+ end
18
+ end
19
+
20
+ Kanrisuru::Remote::Os.class_eval do
21
+ def initialize(host)
22
+ @host = host
23
+
24
+ @kernel_name = 'Linux'
25
+ @kernel_version = '#91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021'
26
+ @operating_system = 'GNU/Linux'
27
+ @hardware_platform = "x86_64"
28
+ @processor = "x86_64"
29
+ @release = "ubuntu"
30
+ @version = 20.0
31
+ end
32
+ end
33
+
34
+ Kanrisuru::Result.class_eval do
35
+ def initialize(command, &block)
36
+ @command = command
37
+ @data = nil
38
+
39
+ @error = @command.to_a if @command.failure?
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
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
File without changes
File without changes
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,7 @@ SimpleCov.start
5
5
 
6
6
  require 'kanrisuru'
7
7
  require_relative 'helper/test_hosts'
8
+ require_relative 'helper/stub_network'
8
9
 
9
10
  Kanrisuru.logger.level = Logger::WARN
10
11
 
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.8.14
4
+ version: 0.8.15
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-10-09 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -173,34 +173,36 @@ files:
173
173
  - lib/kanrisuru/util/os_family.rb
174
174
  - lib/kanrisuru/util/signal.rb
175
175
  - lib/kanrisuru/version.rb
176
- - spec/functional/core/apt_spec.rb
177
- - spec/functional/core/archive_spec.rb
178
- - spec/functional/core/disk_spec.rb
179
- - spec/functional/core/dmi_spec.rb
180
- - spec/functional/core/file_spec.rb
181
- - spec/functional/core/find_spec.rb
182
- - spec/functional/core/group_spec.rb
183
- - spec/functional/core/ip_spec.rb
184
- - spec/functional/core/path_spec.rb
185
- - spec/functional/core/socket_spec.rb
186
176
  - spec/functional/core/stat_spec.rb
187
- - spec/functional/core/stream_spec.rb
188
- - spec/functional/core/system_spec.rb
189
- - spec/functional/core/transfer_spec.rb
190
- - spec/functional/core/user_spec.rb
191
- - spec/functional/core/yum_spec.rb
192
- - spec/functional/core/zypper_spec.rb
193
177
  - spec/functional/os_package_spec.rb
194
- - spec/functional/remote/cluster_spec.rb
195
- - spec/functional/remote/cpu_spec.rb
196
- - spec/functional/remote/env_spec.rb
197
- - spec/functional/remote/fstab_spec.rb
198
- - spec/functional/remote/host_spec.rb
199
- - spec/functional/remote/memory_spec.rb
200
- - spec/functional/remote/os_spec.rb
201
- - spec/functional/remote/remote_file_spec.rb
178
+ - spec/helper/stub_network.rb
202
179
  - spec/helper/test_hosts.rb
203
180
  - spec/hosts.json
181
+ - spec/integration/core/apt_spec.rb
182
+ - spec/integration/core/archive_spec.rb
183
+ - spec/integration/core/disk_spec.rb
184
+ - spec/integration/core/dmi_spec.rb
185
+ - spec/integration/core/file_spec.rb
186
+ - spec/integration/core/find_spec.rb
187
+ - spec/integration/core/group_spec.rb
188
+ - spec/integration/core/ip_spec.rb
189
+ - spec/integration/core/path_spec.rb
190
+ - spec/integration/core/socket_spec.rb
191
+ - spec/integration/core/stat_spec.rb
192
+ - spec/integration/core/stream_spec.rb
193
+ - spec/integration/core/system_spec.rb
194
+ - spec/integration/core/transfer_spec.rb
195
+ - spec/integration/core/user_spec.rb
196
+ - spec/integration/core/yum_spec.rb
197
+ - spec/integration/core/zypper_spec.rb
198
+ - spec/integration/remote/cluster_spec.rb
199
+ - spec/integration/remote/cpu_spec.rb
200
+ - spec/integration/remote/env_spec.rb
201
+ - spec/integration/remote/fstab_spec.rb
202
+ - spec/integration/remote/host_spec.rb
203
+ - spec/integration/remote/memory_spec.rb
204
+ - spec/integration/remote/os_spec.rb
205
+ - spec/integration/remote/remote_file_spec.rb
204
206
  - spec/spec_helper.rb
205
207
  - spec/unit/core/apt_spec.rb
206
208
  - spec/unit/core/archive_spec.rb