kanrisuru 0.9.1 → 0.11.1

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 (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
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Cpu do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ context 'with metal' do
15
+ let(:host) do
16
+ Kanrisuru::Remote::Host.new(
17
+ host: 'metal-host',
18
+ username: 'ubuntu',
19
+ keys: ['id_rsa']
20
+ )
21
+ end
22
+
23
+ before do
24
+ StubNetwork.stub_command!(:lscpu) do |_args|
25
+ struct = Kanrisuru::Core::System::CPUArchitecture.new
26
+ struct.architecture = 'x86_64'
27
+ struct.cores = 48
28
+ struct.byte_order = 'Little Endian'
29
+ struct.address_sizes = ['46 bits physical', '48 bits virtual']
30
+ struct.operation_modes = %w[32-bit 64-bit]
31
+ struct.online_cpus = 0
32
+ struct.threads_per_core = 2
33
+ struct.cores_per_socket = 12
34
+ struct.sockets = 2
35
+ struct.numa_mode = nil
36
+ struct.vendor_id = 'GenuineIntel'
37
+ struct.cpu_family = 6
38
+ struct.model = 63
39
+ struct.model_name = 'Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz'
40
+ struct.stepping = 2
41
+ struct.cpu_mhz = 1200.16
42
+ struct.cpu_max_mhz = 3300.0
43
+ struct.cpu_min_mhz = 1200.0
44
+ struct.bogo_mips = nil
45
+ struct.virtualization = 'VT-x'
46
+ struct.hypervisor_vendor = nil
47
+ struct.virtualization_type = nil
48
+ struct.l1d_cache = '768 KiB'
49
+ struct.l1i_cache = '768 KiB'
50
+ struct.l2_cache = '6 MiB'
51
+ struct.l3_cache = '60 MiB'
52
+ struct.numa_nodes = 2
53
+ struct.vulnerabilities = [
54
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Itlb multihit',
55
+ 'KVM: Mitigation: Split huge pages'),
56
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('L1tf',
57
+ 'Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable'),
58
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Mds',
59
+ 'Mitigation; Clear CPU buffers; SMT vulnerable'),
60
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Meltdown', 'Mitigation; PTI'),
61
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spec store bypass',
62
+ 'Mitigation; Speculative Store Bypass disabled via prctl and seccomp'),
63
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spectre v1',
64
+ 'Mitigation; usercopy/swapgs barriers and __user pointer sanitization'),
65
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spectre v2',
66
+ 'Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling'),
67
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Srbds', 'Not affected'),
68
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Tsx async abort', 'Not affected')
69
+ ]
70
+ struct.flags = %w[fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
71
+ mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts md_clear flush_l1d]
72
+ struct
73
+ end
74
+ end
75
+
76
+ after do
77
+ StubNetwork.unstub_command!(:lscpu)
78
+ end
79
+
80
+ it 'gets host cpu attributes' do
81
+ expect(host.cpu.architecture).to eq('x86_64')
82
+ expect(host.cpu.cores).to eq(48)
83
+ expect(host.cpu.byte_order).to eq('Little Endian')
84
+ expect(host.cpu.address_sizes).to eq(['46 bits physical', '48 bits virtual'])
85
+ expect(host.cpu.threads_per_core).to eq(2)
86
+ expect(host.cpu.cores_per_socket).to eq(12)
87
+ expect(host.cpu.sockets).to eq(2)
88
+ expect(host.cpu.vendor_id).to eq('GenuineIntel')
89
+ expect(host.cpu.cpu_family).to eq(6)
90
+ expect(host.cpu.model).to eq(63)
91
+ expect(host.cpu.model_name).to eq('Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz')
92
+ expect(host.cpu.cpu_mhz).to eq(1200.16)
93
+ expect(host.cpu.cpu_max_mhz).to eq(3300.0)
94
+ expect(host.cpu.cpu_min_mhz).to eq(1200.0)
95
+ expect(host.cpu.hypervisor).to be_nil
96
+ expect(host.cpu.virtualization_type).to be_nil
97
+ # expect(host.cpu.l1d_cache).to eq("768 KiB")
98
+ # expect(host.cpu.l1i_cache).to eq("768 KiB")
99
+ # expect(host.cpu.l2_cache).to eq("6 MiB")
100
+ # expect(host.cpu.l3_cache).to eq("60 MiB")
101
+ expect(host.cpu.numa_nodes).to eq(2)
102
+ end
103
+ end
104
+ end
@@ -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
 
@@ -32,30 +32,67 @@ class StubNetwork
32
32
  end
33
33
  end
34
34
 
35
- unless Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
36
- Kanrisuru::Result.class_eval do
37
- alias_method :initialize_alias, :initialize
38
- def initialize(command)
39
- @command = command
40
- @data = nil
35
+ return if Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
36
+
37
+ Kanrisuru::Result.class_eval do
38
+ alias_method :initialize_alias, :initialize
39
+ def initialize(command, parse_result = false, &block)
40
+ @command = command
41
+ @data = nil
42
+
43
+ @data = block.call(@command) if @command.success? && block_given? && parse_result
44
+ @error = @command.to_a if @command.failure?
45
+
46
+ ## Define getter methods on result that maps to
47
+ ## the same methods of a data struct.
48
+ return unless @command.success? && Kanrisuru::Util.present?(@data) && @data.class.ancestors.include?(Struct)
49
+
50
+ method_names = @data.members
51
+ self.class.class_eval do
52
+ method_names.each do |method_name|
53
+ define_method method_name do
54
+ @data[method_name]
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)
41
71
 
42
- @error = @command.to_a if @command.failure?
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,