kanrisuru 0.9.0 → 0.11.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.
Files changed (58) 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 +147 -125
  6. data/CODE_OF_CONDUCT.md +10 -10
  7. data/README.md +2 -0
  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/find.rb +4 -5
  12. data/lib/kanrisuru/core/socket.rb +2 -1
  13. data/lib/kanrisuru/remote/cpu.rb +6 -2
  14. data/lib/kanrisuru/remote/env.rb +8 -0
  15. data/lib/kanrisuru/remote/fstab.rb +4 -4
  16. data/lib/kanrisuru/util.rb +1 -1
  17. data/lib/kanrisuru/version.rb +1 -1
  18. data/spec/functional/core/apt_spec.rb +22 -30
  19. data/spec/functional/core/archive_spec.rb +169 -0
  20. data/spec/functional/core/find_spec.rb +94 -113
  21. data/spec/functional/core/socket_spec.rb +23 -28
  22. data/spec/functional/core/stream_spec.rb +12 -12
  23. data/spec/functional/core/transfer_spec.rb +108 -131
  24. data/spec/functional/core/yum_spec.rb +58 -83
  25. data/spec/functional/remote/cluster_spec.rb +12 -3
  26. data/spec/functional/remote/cpu_spec.rb +104 -0
  27. data/spec/functional/remote/env_spec.rb +48 -0
  28. data/spec/helper/stub_network.rb +52 -9
  29. data/spec/integration/core/file_spec.rb +0 -1
  30. data/spec/integration/core/find_spec.rb +1 -0
  31. data/spec/integration/core/system_spec.rb +0 -1
  32. data/spec/integration/core/zypper_spec.rb +3 -3
  33. data/spec/{functional → integration}/os_package_spec.rb +0 -0
  34. data/spec/spec_helper.rb +3 -0
  35. data/spec/unit/command_spec.rb +31 -0
  36. data/spec/unit/core/apt_spec.rb +20 -0
  37. data/spec/unit/core/archive_spec.rb +20 -0
  38. data/spec/unit/core/disk_spec.rb +23 -0
  39. data/spec/unit/core/dmi_spec.rb +20 -0
  40. data/spec/unit/core/file_spec.rb +35 -0
  41. data/spec/unit/core/find_spec.rb +21 -1
  42. data/spec/unit/core/group_spec.rb +24 -0
  43. data/spec/unit/core/ip_spec.rb +20 -0
  44. data/spec/unit/core/path_spec.rb +25 -0
  45. data/spec/unit/core/socket_spec.rb +20 -0
  46. data/spec/unit/core/stat_spec.rb +27 -0
  47. data/spec/unit/core/system_spec.rb +35 -0
  48. data/spec/unit/core/transfer_spec.rb +22 -0
  49. data/spec/unit/core/user_spec.rb +25 -0
  50. data/spec/unit/core/yum_spec.rb +20 -0
  51. data/spec/unit/core/zypper_spec.rb +20 -0
  52. data/spec/unit/mode_spec.rb +33 -2
  53. data/spec/unit/remote/cluster_spec.rb +36 -0
  54. data/spec/unit/remote/cpu_spec.rb +49 -0
  55. data/spec/unit/remote/env_spec.rb +17 -0
  56. data/spec/unit/{fstab_spec.rb → remote/fstab_spec.rb} +0 -0
  57. data/spec/unit/util_spec.rb +13 -0
  58. metadata +27 -5
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Env do
6
+ let(:env) { described_class.new }
7
+
8
+ it 'adds a environment variable' do
9
+ env['VAR1'] = 'hello'
10
+ expect(env.count).to eq(1)
11
+ expect(env.to_h).to eq({ 'VAR1' => 'hello' })
12
+ expect(env.to_s).to eq('export VAR1=hello;')
13
+ expect(env['VAR1']).to eq('hello')
14
+ end
15
+
16
+ it 'adds multiple environment variables' do
17
+ env['var1'] = 'hello'
18
+ env['var2'] = 'world'
19
+
20
+ expect(env.count).to eq(2)
21
+ expect(env.to_h).to eq({ 'VAR1' => 'hello', 'VAR2' => 'world' })
22
+ expect(env.to_s).to eq('export VAR1=hello; export VAR2=world;')
23
+ expect(env['VAR1']).to eq('hello')
24
+ expect(env['VAR2']).to eq('world')
25
+ end
26
+
27
+ it 'deletes a variable' do
28
+ env[:var1] = 'foo'
29
+ expect(env.count).to eq(1)
30
+ expect(env[:var1]).to eq('foo')
31
+ env.delete(:var1)
32
+ expect(env.count).to eq(0)
33
+ expect(env.to_s).to eq('')
34
+ end
35
+
36
+ it 'clears the environment' do
37
+ env['VERSION'] = 1
38
+ env['SHELL'] = '/bin/zsh'
39
+ env['USER'] = 'ubuntu'
40
+ env['HOSTNAME'] = 'ubuntu'
41
+ expect(env.to_s).to eq('export VERSION=1; export SHELL=/bin/zsh; export USER=ubuntu; export HOSTNAME=ubuntu;')
42
+
43
+ expect(env.count).to eq(4)
44
+ env.clear
45
+
46
+ expect(env.count).to eq(0)
47
+ end
48
+ end
@@ -17,7 +17,7 @@ class StubNetwork
17
17
 
18
18
  unless Kanrisuru::Remote::Os.instance_methods(false).include?(:initialize_alias)
19
19
  Kanrisuru::Remote::Os.class_eval do
20
- alias_method :initialize_alias, :initialize
20
+ alias_method :initialize_alias, :initialize
21
21
  define_method :initialize do |host|
22
22
  @host = host
23
23
 
@@ -34,28 +34,65 @@ class StubNetwork
34
34
 
35
35
  unless Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
36
36
  Kanrisuru::Result.class_eval do
37
- alias_method :initialize_alias, :initialize
38
- def initialize(command)
37
+ alias_method :initialize_alias, :initialize
38
+ def initialize(command, parse_result = false, &block)
39
39
  @command = command
40
40
  @data = nil
41
41
 
42
+ @data = block.call(@command) if @command.success? && block_given? && parse_result
42
43
  @error = @command.to_a if @command.failure?
44
+
45
+ ## Define getter methods on result that maps to
46
+ ## the same methods of a data struct.
47
+ return unless @command.success? && Kanrisuru::Util.present?(@data) && @data.class.ancestors.include?(Struct)
48
+
49
+ method_names = @data.members
50
+ self.class.class_eval do
51
+ method_names.each do |method_name|
52
+ define_method method_name do
53
+ @data[method_name]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ def stub_command!(method, opts = {}, &block)
63
+ Kanrisuru::Remote::Host.class_eval do
64
+ alias_method "#{method}_alias", method
65
+
66
+ define_method(method) do |*args|
67
+ command = Kanrisuru::Command.new(method.to_s)
68
+
69
+ status = opts[:status] || 0
70
+ command.handle_status(status)
71
+
72
+ Kanrisuru::Result.new(command, true) do |_cmd|
73
+ block.call(args)
43
74
  end
44
75
  end
45
76
  end
46
77
  end
47
78
 
79
+ def unstub_command!(method)
80
+ Kanrisuru::Remote::Host.class_eval do
81
+ alias_method method, "#{method}_alias"
82
+ end
83
+ end
84
+
48
85
  def unstub!
49
86
  Kanrisuru::Remote::Host.class_eval do
50
87
  alias_method :execute_with_retries, :execute_with_retries_alias
51
88
  end
52
89
 
53
90
  Kanrisuru::Remote::Os.class_eval do
54
- alias_method :initialize, :initialize_alias
91
+ alias_method :initialize, :initialize_alias
55
92
  end
56
93
 
57
94
  Kanrisuru::Result.class_eval do
58
- alias_method :initialize, :initialize_alias
95
+ alias_method :initialize, :initialize_alias
59
96
  end
60
97
  end
61
98
 
@@ -82,13 +119,19 @@ class StubNetwork
82
119
  processor: 'x86_64',
83
120
  release: 'centos',
84
121
  version: 7.0
122
+ },
123
+ opensuse: {
124
+ kernel_name: 'Linux',
125
+ kernel_version: '"#1 SMP Tue Jul 20 23:04:11 UTC 2021"',
126
+ operating_system: 'GNU/Linux',
127
+ hardware_platform: 'x86_64',
128
+ processor: 'x86_64',
129
+ release: 'opensuse-leap',
130
+ version: 15.2
85
131
  }
86
132
  }
87
133
 
88
-
89
- defaults[name].key?(property) ?
90
- defaults[name][property] : nil
134
+ defaults[name][property] if defaults[name].key?(property)
91
135
  end
92
-
93
136
  end
94
137
  end
@@ -356,7 +356,6 @@ RSpec.describe Kanrisuru::Core::File do
356
356
  data = host.cat('/etc/hosts').command.raw_result
357
357
  doc = data.map(&:lines).flatten
358
358
 
359
- lines = doc.length
360
359
  words = doc.map(&:split).flatten
361
360
  chars = doc.map(&:length).flatten
362
361
 
@@ -19,6 +19,7 @@ RSpec.describe Kanrisuru::Core::Find do
19
19
  end
20
20
 
21
21
  it 'finds home directory' do
22
+ host.su('root')
22
23
  result = host.find(paths: '/home')
23
24
  home = result.find { |item| item.path == host_json['home'] }
24
25
  expect(home.path).to eq(host_json['home'])
@@ -107,7 +107,6 @@ RSpec.describe Kanrisuru::Core::System do
107
107
  host.su('root')
108
108
 
109
109
  result = host.last(failed_attempts: true)
110
- puts result.data
111
110
  expect(result).to be_success
112
111
  end
113
112
 
@@ -30,19 +30,19 @@ RSpec.describe Kanrisuru::Core::Zypper do
30
30
 
31
31
  it 'installs a package' do
32
32
  host.su('root')
33
- result = host.zypper('install', packages: 'ffmpeg')
33
+ result = host.zypper('install', packages: 'nginx')
34
34
  expect(result).to be_success
35
35
  end
36
36
 
37
37
  it 'installs multiple packages' do
38
38
  host.su('root')
39
- result = host.zypper('install', packages: %w[curl ffmpeg])
39
+ result = host.zypper('install', packages: %w[curl nginx])
40
40
  expect(result).to be_success
41
41
  end
42
42
 
43
43
  it 'removes a package' do
44
44
  host.su('root')
45
- result = host.zypper('remove', packages: ['ffmpeg'])
45
+ result = host.zypper('remove', packages: ['nginx'])
46
46
  expect(result).to be_success
47
47
  end
48
48
 
File without changes
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,9 @@
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
+ require 'simplecov-cobertura'
7
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
8
+
6
9
  require 'kanrisuru'
7
10
 
8
11
  require_relative 'helper/test_hosts'
@@ -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 = described_class.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,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Apt do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:apt)
24
+ end
25
+
6
26
  it 'responds to apt fields' do
7
27
  expect(Kanrisuru::Core::Apt::Source.new).to respond_to(
8
28
  :url, :dist, :architecture
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Archive do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:tar)
24
+ end
25
+
6
26
  it 'responds to archive fields' do
7
27
  expect(Kanrisuru::Core::Archive::FilePath.new).to respond_to(
8
28
  :path
@@ -3,6 +3,29 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Disk do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:df)
24
+ expect(host).to respond_to(:du)
25
+ expect(host).to respond_to(:blkid)
26
+ expect(host).to respond_to(:lsblk)
27
+ end
28
+
6
29
  it 'responds to disk fields' do
7
30
  expect(Kanrisuru::Core::Disk::DiskUsage.new).to respond_to(:fsize, :path)
8
31
  expect(Kanrisuru::Core::Disk::DiskFree.new).to respond_to(
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Dmi do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:dmi)
24
+ end
25
+
6
26
  it 'responds to dmi type fields' do
7
27
  expect(Kanrisuru::Core::Dmi::BIOS.new).to respond_to(
8
28
  :dmi_type, :dmi_handle, :dmi_size,
@@ -3,6 +3,41 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::File do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:touch)
24
+ expect(host).to respond_to(:cp)
25
+ expect(host).to respond_to(:copy)
26
+ expect(host).to respond_to(:mkdir)
27
+ expect(host).to respond_to(:mv)
28
+ expect(host).to respond_to(:move)
29
+ expect(host).to respond_to(:link)
30
+ expect(host).to respond_to(:symlink)
31
+ expect(host).to respond_to(:ln)
32
+ expect(host).to respond_to(:ln_s)
33
+ expect(host).to respond_to(:chmod)
34
+ expect(host).to respond_to(:chown)
35
+ expect(host).to respond_to(:unlink)
36
+ expect(host).to respond_to(:rm)
37
+ expect(host).to respond_to(:rmdir)
38
+ expect(host).to respond_to(:wc)
39
+ end
40
+
6
41
  it 'responds to file fields' do
7
42
  expect(Kanrisuru::Core::File::FileCount.new).to respond_to(:lines, :words, :characters)
8
43
  end
@@ -3,10 +3,30 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Find do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:find)
24
+ end
25
+
6
26
  it 'responds to find fields' do
7
27
  expect(Kanrisuru::Core::Find::FilePath.new).to respond_to(:path)
8
28
  expect(Kanrisuru::Core::Find::REGEX_TYPES).to(
9
- eq(['emacs', 'posix-awk', 'posix-basic', 'posix-egrep', 'posix-extended'])
29
+ eq(%w[emacs posix-awk posix-basic posix-egrep posix-extended])
10
30
  )
11
31
  end
12
32
  end
@@ -3,6 +3,30 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Group do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:group?)
24
+ expect(host).to respond_to(:get_gid)
25
+ expect(host).to respond_to(:create_group)
26
+ expect(host).to respond_to(:update_group)
27
+ expect(host).to respond_to(:delete_group)
28
+ end
29
+
6
30
  it 'responds to group fields' do
7
31
  expect(Kanrisuru::Core::Group::Group.new).to respond_to(:gid, :name, :users)
8
32
  expect(Kanrisuru::Core::Group::GroupUser.new).to respond_to(:uid, :name)
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::IP do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:ip)
24
+ end
25
+
6
26
  it 'responds to ip fields' do
7
27
  expect(Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION).to(
8
28
  eq(180_129)
@@ -3,6 +3,31 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Path do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:ls)
24
+ expect(host).to respond_to(:pwd)
25
+ expect(host).to respond_to(:realpath)
26
+ expect(host).to respond_to(:readlink)
27
+ expect(host).to respond_to(:whoami)
28
+ expect(host).to respond_to(:which)
29
+ end
30
+
6
31
  it 'responds to path fields' do
7
32
  expect(Kanrisuru::Core::Path::FilePath.new).to respond_to(:path)
8
33
  expect(Kanrisuru::Core::Path::FileInfoId.new).to respond_to(
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Socket do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:ss)
24
+ end
25
+
6
26
  it 'responds to socket fields' do
7
27
  expect(Kanrisuru::Core::Socket::Statistics.new).to respond_to(
8
28
  :netid, :state, :receive_queue, :send_queue,
@@ -3,6 +3,33 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Stat do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:dir?)
24
+ expect(host).to respond_to(:file?)
25
+ expect(host).to respond_to(:block_device?)
26
+ expect(host).to respond_to(:char_device?)
27
+ expect(host).to respond_to(:symlink?)
28
+ expect(host).to respond_to(:file_type?)
29
+ expect(host).to respond_to(:inode?)
30
+ expect(host).to respond_to(:stat)
31
+ end
32
+
6
33
  it 'responds to stat fields' do
7
34
  expect(Kanrisuru::Core::Stat::FileStat.new).to respond_to(
8
35
  :mode, :blocks, :device, :file_type,
@@ -3,6 +3,41 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::System do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:load_env)
24
+ expect(host).to respond_to(:cpu_info)
25
+ expect(host).to respond_to(:lscpu)
26
+ expect(host).to respond_to(:load_average)
27
+ expect(host).to respond_to(:free)
28
+ expect(host).to respond_to(:ps)
29
+ expect(host).to respond_to(:kill)
30
+ expect(host).to respond_to(:kernel_statistics)
31
+ expect(host).to respond_to(:kstat)
32
+ expect(host).to respond_to(:lsof)
33
+ expect(host).to respond_to(:last)
34
+ expect(host).to respond_to(:uptime)
35
+ expect(host).to respond_to(:w)
36
+ expect(host).to respond_to(:who)
37
+ expect(host).to respond_to(:reboot)
38
+ expect(host).to respond_to(:poweroff)
39
+ end
40
+
6
41
  it 'responds to system fields' do
7
42
  expect(Kanrisuru::Core::System::CPUArchitectureVulnerability.new).to respond_to(
8
43
  :name,
@@ -3,6 +3,28 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Transfer do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:download)
24
+ expect(host).to respond_to(:upload)
25
+ expect(host).to respond_to(:wget)
26
+ end
27
+
6
28
  it 'responds to transfer fields' do
7
29
  expect(Kanrisuru::Core::Transfer::WGET_FILENAME_MODES).to eq(
8
30
  %w[unix windows nocontrol ascii lowercase uppercase]
@@ -3,6 +3,31 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::User do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'localhost',
17
+ username: 'ubuntu',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:user?)
24
+ expect(host).to respond_to(:get_uid)
25
+ expect(host).to respond_to(:get_user)
26
+ expect(host).to respond_to(:create_user)
27
+ expect(host).to respond_to(:update_user)
28
+ expect(host).to respond_to(:delete_user)
29
+ end
30
+
6
31
  it 'responds to user fields' do
7
32
  expect(Kanrisuru::Core::User::User.new).to respond_to(:uid, :name, :home, :shell, :groups)
8
33
  expect(Kanrisuru::Core::User::UserGroup.new).to respond_to(:gid, :name)