kanrisuru 0.9.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) 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/.rspec +1 -1
  5. data/CHANGELOG.md +125 -96
  6. data/CODE_OF_CONDUCT.md +10 -10
  7. data/README.md +19 -90
  8. data/kanrisuru.gemspec +2 -1
  9. data/lib/kanrisuru/command.rb +7 -0
  10. data/lib/kanrisuru/core/archive.rb +13 -36
  11. data/lib/kanrisuru/core/disk.rb +0 -3
  12. data/lib/kanrisuru/core/dmi.rb +1 -1
  13. data/lib/kanrisuru/core/file.rb +4 -11
  14. data/lib/kanrisuru/core/find.rb +6 -11
  15. data/lib/kanrisuru/core/mount.rb +14 -15
  16. data/lib/kanrisuru/core/socket.rb +2 -1
  17. data/lib/kanrisuru/core/stream.rb +1 -2
  18. data/lib/kanrisuru/core/zypper.rb +6 -23
  19. data/lib/kanrisuru/os_package/collection.rb +58 -0
  20. data/lib/kanrisuru/os_package/define.rb +34 -0
  21. data/lib/kanrisuru/os_package/include.rb +163 -0
  22. data/lib/kanrisuru/os_package.rb +3 -245
  23. data/lib/kanrisuru/remote/cpu.rb +5 -1
  24. data/lib/kanrisuru/remote/env.rb +8 -0
  25. data/lib/kanrisuru/remote/fstab.rb +5 -5
  26. data/lib/kanrisuru/result.rb +5 -4
  27. data/lib/kanrisuru/util.rb +1 -1
  28. data/lib/kanrisuru/version.rb +1 -1
  29. data/spec/functional/core/apt_spec.rb +22 -30
  30. data/spec/functional/core/archive_spec.rb +170 -0
  31. data/spec/functional/core/find_spec.rb +94 -113
  32. data/spec/functional/core/mount_spec.rb +121 -0
  33. data/spec/functional/core/socket_spec.rb +23 -28
  34. data/spec/functional/core/stream_spec.rb +12 -12
  35. data/spec/functional/core/transfer_spec.rb +108 -131
  36. data/spec/functional/core/yum_spec.rb +58 -83
  37. data/spec/functional/remote/cluster_spec.rb +11 -2
  38. data/spec/functional/remote/cpu_spec.rb +104 -0
  39. data/spec/functional/remote/env_spec.rb +48 -0
  40. data/spec/helper/stub_network.rb +49 -14
  41. data/spec/helper/test_hosts.rb +11 -1
  42. data/spec/integration/core/apt_spec.rb +2 -3
  43. data/spec/integration/core/archive_spec.rb +8 -13
  44. data/spec/integration/core/disk_spec.rb +2 -3
  45. data/spec/integration/core/dmi_spec.rb +2 -3
  46. data/spec/integration/core/file_spec.rb +4 -14
  47. data/spec/integration/core/find_spec.rb +3 -3
  48. data/spec/integration/core/group_spec.rb +2 -3
  49. data/spec/integration/core/ip_spec.rb +2 -3
  50. data/spec/integration/core/path_spec.rb +2 -3
  51. data/spec/integration/core/socket_spec.rb +2 -4
  52. data/spec/integration/core/stat_spec.rb +2 -3
  53. data/spec/integration/core/stream_spec.rb +6 -9
  54. data/spec/integration/core/system_spec.rb +2 -4
  55. data/spec/integration/core/transfer_spec.rb +4 -9
  56. data/spec/integration/core/user_spec.rb +2 -4
  57. data/spec/integration/core/yum_spec.rb +2 -3
  58. data/spec/integration/core/zypper_spec.rb +5 -6
  59. data/spec/{functional → integration}/os_package_spec.rb +0 -0
  60. data/spec/integration/remote/cpu_spec.rb +2 -3
  61. data/spec/integration/remote/env_spec.rb +2 -3
  62. data/spec/integration/remote/fstab_spec.rb +2 -3
  63. data/spec/integration/remote/host_spec.rb +2 -3
  64. data/spec/integration/remote/memory_spec.rb +2 -2
  65. data/spec/integration/remote/os_spec.rb +2 -3
  66. data/spec/integration/remote/remote_file_spec.rb +9 -15
  67. data/spec/spec_helper.rb +12 -3
  68. data/spec/unit/command_spec.rb +49 -0
  69. data/spec/unit/core/find_spec.rb +1 -1
  70. data/spec/unit/core/yum_spec.rb +1 -1
  71. data/spec/unit/mode_spec.rb +33 -2
  72. data/spec/unit/remote/cluster_spec.rb +3 -1
  73. data/spec/unit/remote/cpu_spec.rb +1 -2
  74. data/spec/unit/remote/env_spec.rb +17 -0
  75. data/spec/unit/util_spec.rb +13 -0
  76. metadata +28 -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
 
@@ -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)
41
36
 
42
- @error = @command.to_a if @command.failure?
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)
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
 
@@ -90,13 +127,11 @@ class StubNetwork
90
127
  hardware_platform: 'x86_64',
91
128
  processor: 'x86_64',
92
129
  release: 'opensuse-leap',
93
- version:15.2
130
+ version: 15.2
94
131
  }
95
132
  }
96
133
 
97
- defaults[name].key?(property) ?
98
- defaults[name][property] : nil
134
+ defaults[name][property] if defaults[name].key?(property)
99
135
  end
100
-
101
136
  end
102
137
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'securerandom'
4
+
3
5
  class TestHosts
4
6
  class << self
5
7
  def each_os(opts = {}, &block)
@@ -7,7 +9,10 @@ class TestHosts
7
9
  next unless test?(os_name)
8
10
  next if opts[:only] && !only?(opts, os_name)
9
11
 
10
- block.call(os_name)
12
+ host_json = TestHosts.host(os_name)
13
+ spec_dir = spec_dir(os_name, host_json)
14
+
15
+ block.call(os_name, host_json, spec_dir)
11
16
  end
12
17
  end
13
18
 
@@ -15,6 +20,11 @@ class TestHosts
15
20
  hosts(name)
16
21
  end
17
22
 
23
+ def spec_dir(os_name, host_json)
24
+ random_string = SecureRandom.hex
25
+ "#{host_json['home']}/.kanrisuru_spec_files_#{random_string[0..5]}"
26
+ end
27
+
18
28
  def only?(opts, name)
19
29
  ((opts[:only].instance_of?(Array) && opts[:only].include?(name)) ||
20
30
  (opts[:only].instance_of?(String) && opts[:only] == name))
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Apt do
6
- TestHosts.each_os(only: %w[debian ubuntu]) do |os_name|
5
+ TestHosts.each_os(only: %w[debian ubuntu]) do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Apt do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,22 +2,20 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Archive do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::Archive do
7
7
  context "with #{os_name}" do
8
8
  before(:all) do
9
- host_json = TestHosts.host(os_name)
10
9
  host = Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
12
11
  username: host_json['username'],
13
12
  keys: [host_json['ssh_key']]
14
13
  )
15
14
 
16
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
17
16
  host.disconnect
18
17
  end
19
18
 
20
- let(:host_json) { TestHosts.host(os_name) }
21
19
  let(:host) do
22
20
  Kanrisuru::Remote::Host.new(
23
21
  host: host_json['hostname'],
@@ -26,22 +24,19 @@ RSpec.describe Kanrisuru::Core::Archive do
26
24
  )
27
25
  end
28
26
 
29
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
-
31
27
  after do
32
28
  host.disconnect
33
29
  end
34
30
 
35
31
  after(:all) do
36
- host_json = TestHosts.host(os_name)
37
32
  host = Kanrisuru::Remote::Host.new(
38
33
  host: host_json['hostname'],
39
34
  username: host_json['username'],
40
35
  keys: [host_json['ssh_key']]
41
36
  )
42
37
 
43
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
44
- host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
38
+ host.rmdir(spec_dir)
39
+ host.rmdir("#{spec_dir}/extract-tar-files") if host.dir?("#{spec_dir}/extract-tar-files")
45
40
  host.disconnect
46
41
  end
47
42
 
@@ -126,10 +121,10 @@ RSpec.describe Kanrisuru::Core::Archive do
126
121
  paths = result.map(&:path)
127
122
  expect(paths.include?('test2.config')).to eq(false)
128
123
 
129
- host.mkdir("#{host_json['home']}/extract-tar-files", silent: true)
130
- host.tar('extract', 'archive.tar', directory: "#{host_json['home']}/extract-tar-files")
124
+ host.mkdir("#{spec_dir}/extract-tar-files", silent: true)
125
+ host.tar('extract', 'archive.tar', directory: "#{spec_dir}/extract-tar-files")
131
126
 
132
- result = host.ls(path: "#{host_json['home']}/extract-tar-files")
127
+ result = host.ls(path: "#{spec_dir}/extract-tar-files")
133
128
  paths = result.map(&:path)
134
129
 
135
130
  expect(paths.include?('test1.config')).to eq(true)
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Disk do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Disk do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Dmi do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Dmi do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,22 +2,20 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::File do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::File do
7
7
  context "with #{os_name}" do
8
8
  before(:all) do
9
- host_json = TestHosts.host(os_name)
10
9
  host = Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
12
11
  username: host_json['username'],
13
12
  keys: [host_json['ssh_key']]
14
13
  )
15
14
 
16
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
17
16
  host.disconnect
18
17
  end
19
18
 
20
- let(:host_json) { TestHosts.host(os_name) }
21
19
  let(:host) do
22
20
  Kanrisuru::Remote::Host.new(
23
21
  host: host_json['hostname'],
@@ -26,25 +24,18 @@ RSpec.describe Kanrisuru::Core::File do
26
24
  )
27
25
  end
28
26
 
29
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
-
31
27
  after do
32
28
  host.disconnect
33
29
  end
34
30
 
35
31
  after(:all) do
36
- host_json = TestHosts.host(os_name)
37
32
  host = Kanrisuru::Remote::Host.new(
38
33
  host: host_json['hostname'],
39
34
  username: host_json['username'],
40
35
  keys: [host_json['ssh_key']]
41
36
  )
42
37
 
43
- host.rm("#{host_json['home']}/.kanrisuru_spec_files", force: true, recursive: true)
44
- if host.dir?("#{host_json['home']}/extract-tar-files")
45
- host.rm("#{host_json['home']}/extract-tar-files", force: true,
46
- recursive: true)
47
- end
38
+ host.rm(spec_dir, force: true, recursive: true)
48
39
  host.disconnect
49
40
  end
50
41
 
@@ -356,7 +347,6 @@ RSpec.describe Kanrisuru::Core::File do
356
347
  data = host.cat('/etc/hosts').command.raw_result
357
348
  doc = data.map(&:lines).flatten
358
349
 
359
- lines = doc.length
360
350
  words = doc.map(&:split).flatten
361
351
  chars = doc.map(&:length).flatten
362
352
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Find do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Find do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -19,6 +18,7 @@ RSpec.describe Kanrisuru::Core::Find do
19
18
  end
20
19
 
21
20
  it 'finds home directory' do
21
+ host.su('root')
22
22
  result = host.find(paths: '/home')
23
23
  home = result.find { |item| item.path == host_json['home'] }
24
24
  expect(home.path).to eq(host_json['home'])
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Group do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Group do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::IP do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::IP do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Path do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Path do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,11 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Socket do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Socket do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
-
10
8
  let(:host) do
11
9
  Kanrisuru::Remote::Host.new(
12
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Stat do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Stat do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -1,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Kanrisuru::Core::Stream do
4
- TestHosts.each_os do |os_name|
3
+ require 'spec_helper'
4
+
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::Stream do
5
7
  context "with #{os_name}" do
6
8
  before(:all) do
7
- host_json = TestHosts.host(os_name)
8
9
  host = Kanrisuru::Remote::Host.new(
9
10
  host: host_json['hostname'],
10
11
  username: host_json['username'],
11
12
  keys: [host_json['ssh_key']]
12
13
  )
13
14
 
14
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
15
16
  host.disconnect
16
17
  end
17
18
 
18
- let(:host_json) { TestHosts.host(os_name) }
19
19
  let(:host) do
20
20
  Kanrisuru::Remote::Host.new(
21
21
  host: host_json['hostname'],
@@ -24,21 +24,18 @@ RSpec.describe Kanrisuru::Core::Stream do
24
24
  )
25
25
  end
26
26
 
27
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
28
-
29
27
  after do
30
28
  host.disconnect
31
29
  end
32
30
 
33
31
  after(:all) do
34
- host_json = TestHosts.host(os_name)
35
32
  host = Kanrisuru::Remote::Host.new(
36
33
  host: host_json['hostname'],
37
34
  username: host_json['username'],
38
35
  keys: [host_json['ssh_key']]
39
36
  )
40
37
 
41
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
38
+ host.rmdir(spec_dir)
42
39
  host.disconnect
43
40
  end
44
41
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::System do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::System do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -107,7 +106,6 @@ RSpec.describe Kanrisuru::Core::System do
107
106
  host.su('root')
108
107
 
109
108
  result = host.last(failed_attempts: true)
110
- puts result.data
111
109
  expect(result).to be_success
112
110
  end
113
111
 
@@ -2,22 +2,20 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::File do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::File do
7
7
  context "with #{os_name}" do
8
8
  before(:all) do
9
- host_json = TestHosts.host(os_name)
10
9
  host = Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
12
11
  username: host_json['username'],
13
12
  keys: [host_json['ssh_key']]
14
13
  )
15
14
 
16
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
17
16
  host.disconnect
18
17
  end
19
18
 
20
- let(:host_json) { TestHosts.host(os_name) }
21
19
  let(:host) do
22
20
  Kanrisuru::Remote::Host.new(
23
21
  host: host_json['hostname'],
@@ -26,21 +24,18 @@ RSpec.describe Kanrisuru::Core::File do
26
24
  )
27
25
  end
28
26
 
29
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
-
31
27
  after do
32
28
  host.disconnect
33
29
  end
34
30
 
35
31
  after(:all) do
36
- host_json = TestHosts.host(os_name)
37
32
  host = Kanrisuru::Remote::Host.new(
38
33
  host: host_json['hostname'],
39
34
  username: host_json['username'],
40
35
  keys: [host_json['ssh_key']]
41
36
  )
42
37
 
43
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
38
+ host.rmdir(spec_dir)
44
39
  host.disconnect
45
40
  end
46
41
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::User do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::User do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -19,7 +18,6 @@ RSpec.describe Kanrisuru::Core::User do
19
18
  end
20
19
 
21
20
  after(:all) do
22
- host_json = TestHosts.host(os_name)
23
21
  host = Kanrisuru::Remote::Host.new(
24
22
  host: host_json['hostname'],
25
23
  username: host_json['username'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Yum do
6
- TestHosts.each_os(only: %w[fedora rhel centos]) do |os_name|
5
+ TestHosts.each_os(only: %w[fedora rhel centos]) do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Yum do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Zypper do
6
- TestHosts.each_os(only: %w[sles opensuse]) do |os_name|
5
+ TestHosts.each_os(only: %w[sles opensuse]) do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Zypper do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -30,19 +29,19 @@ RSpec.describe Kanrisuru::Core::Zypper do
30
29
 
31
30
  it 'installs a package' do
32
31
  host.su('root')
33
- result = host.zypper('install', packages: 'ffmpeg')
32
+ result = host.zypper('install', packages: 'nginx')
34
33
  expect(result).to be_success
35
34
  end
36
35
 
37
36
  it 'installs multiple packages' do
38
37
  host.su('root')
39
- result = host.zypper('install', packages: %w[curl ffmpeg])
38
+ result = host.zypper('install', packages: %w[curl nginx])
40
39
  expect(result).to be_success
41
40
  end
42
41
 
43
42
  it 'removes a package' do
44
43
  host.su('root')
45
- result = host.zypper('remove', packages: ['ffmpeg'])
44
+ result = host.zypper('remove', packages: ['nginx'])
46
45
  expect(result).to be_success
47
46
  end
48
47
 
File without changes
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Cpu do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Remote::Cpu do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Env do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Remote::Env do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],