kanrisuru 0.8.13 → 0.8.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -0
  3. data/README.md +2 -2
  4. data/lib/kanrisuru/core/disk.rb +1 -1
  5. data/lib/kanrisuru/core/stat.rb +1 -3
  6. data/lib/kanrisuru/core/transfer.rb +12 -1
  7. data/lib/kanrisuru/remote/cluster.rb +1 -1
  8. data/lib/kanrisuru/version.rb +1 -1
  9. data/spec/functional/core/path_spec.rb +32 -80
  10. data/spec/functional/core/stat_spec.rb +14 -89
  11. data/spec/functional/core/stream_spec.rb +103 -112
  12. data/spec/functional/core/transfer_spec.rb +175 -102
  13. data/spec/functional/os_package_spec.rb +3 -3
  14. data/spec/helper/expect_helpers.rb +8 -0
  15. data/spec/helper/stub_network.rb +43 -0
  16. data/spec/{functional → integration}/core/apt_spec.rb +0 -0
  17. data/spec/{functional → integration}/core/archive_spec.rb +0 -0
  18. data/spec/{functional → integration}/core/disk_spec.rb +1 -1
  19. data/spec/{functional → integration}/core/dmi_spec.rb +0 -0
  20. data/spec/{functional → integration}/core/file_spec.rb +8 -5
  21. data/spec/{functional → integration}/core/find_spec.rb +0 -0
  22. data/spec/{functional → integration}/core/group_spec.rb +0 -0
  23. data/spec/{functional → integration}/core/ip_spec.rb +0 -0
  24. data/spec/integration/core/path_spec.rb +93 -0
  25. data/spec/{functional → integration}/core/socket_spec.rb +0 -0
  26. data/spec/integration/core/stat_spec.rb +98 -0
  27. data/spec/integration/core/stream_spec.rb +117 -0
  28. data/spec/{functional → integration}/core/system_spec.rb +0 -0
  29. data/spec/integration/core/transfer_spec.rb +108 -0
  30. data/spec/{functional → integration}/core/user_spec.rb +0 -0
  31. data/spec/{functional → integration}/core/yum_spec.rb +0 -0
  32. data/spec/{functional → integration}/core/zypper_spec.rb +0 -0
  33. data/spec/{functional → integration}/remote/cluster_spec.rb +4 -4
  34. data/spec/{functional → integration}/remote/cpu_spec.rb +0 -0
  35. data/spec/{functional → integration}/remote/env_spec.rb +0 -0
  36. data/spec/{functional → integration}/remote/fstab_spec.rb +0 -0
  37. data/spec/{functional → integration}/remote/host_spec.rb +0 -0
  38. data/spec/{functional → integration}/remote/memory_spec.rb +0 -0
  39. data/spec/{functional → integration}/remote/os_spec.rb +0 -0
  40. data/spec/{functional → integration}/remote/remote_file_spec.rb +0 -0
  41. data/spec/spec_helper.rb +3 -0
  42. metadata +29 -23
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Kanrisuru::Core::Stream do
4
+ TestHosts.each_os do |os_name|
5
+ context "with #{os_name}" do
6
+ before(:all) do
7
+ host_json = TestHosts.host(os_name)
8
+ host = Kanrisuru::Remote::Host.new(
9
+ host: host_json['hostname'],
10
+ username: host_json['username'],
11
+ keys: [host_json['ssh_key']]
12
+ )
13
+
14
+ host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.disconnect
16
+ end
17
+
18
+ let(:host_json) { TestHosts.host(os_name) }
19
+ let(:host) do
20
+ Kanrisuru::Remote::Host.new(
21
+ host: host_json['hostname'],
22
+ username: host_json['username'],
23
+ keys: [host_json['ssh_key']]
24
+ )
25
+ end
26
+
27
+ let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
28
+
29
+ after do
30
+ host.disconnect
31
+ end
32
+
33
+ after(:all) do
34
+ host_json = TestHosts.host(os_name)
35
+ host = Kanrisuru::Remote::Host.new(
36
+ host: host_json['hostname'],
37
+ username: host_json['username'],
38
+ keys: [host_json['ssh_key']]
39
+ )
40
+
41
+ host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
42
+ host.disconnect
43
+ end
44
+
45
+ it 'outputs beginning of a file' do
46
+ file = host.file("#{spec_dir}/test-file.txt")
47
+ file.touch
48
+ file.append do |f|
49
+ f << 'This'
50
+ f << 'is'
51
+ f << 'a'
52
+ f << 'file!'
53
+ end
54
+
55
+ result = host.head("#{spec_dir}/test-file.txt", lines: 2)
56
+ expect(result).to be_success
57
+ expect(result.data.length).to eq(2)
58
+ expect(result.data).to eq(%w[This is])
59
+ end
60
+
61
+ it 'outputs end of a file' do
62
+ file = host.file("#{spec_dir}/test-file.txt")
63
+ file.touch
64
+ file.append do |f|
65
+ f << 'This'
66
+ f << 'is'
67
+ f << 'a'
68
+ f << 'file!'
69
+ end
70
+
71
+ result = host.tail("#{spec_dir}/test-file.txt", lines: 2)
72
+ expect(result).to be_success
73
+ expect(result.data.length).to eq(2)
74
+ expect(result.data).to eq(['a', 'file!'])
75
+ end
76
+
77
+ it 'reads a chunk of text from a file' do
78
+ file = host.file("#{spec_dir}/test-file-chunk.txt")
79
+ file.touch
80
+ file.append do |f|
81
+ f << 'This'
82
+ f << 'is'
83
+ f << 'is'
84
+ f << 'a'
85
+ f << 'file'
86
+ f << 'forever...'
87
+ end
88
+
89
+ result = host.read_file_chunk("#{spec_dir}/test-file-chunk.txt", 2, 4)
90
+ expect(result).to be_success
91
+ expect(result.data.length).to eq(3)
92
+ expect(result.data).to eq(%w[is is a])
93
+ end
94
+
95
+ it 'cats a file' do
96
+ result = host.cat('/etc/group')
97
+ expect(result.success?).to eq(true)
98
+ expect(result.data.include?('root:x:0:')).to eq(true)
99
+ end
100
+
101
+ it 'echoes to stdout' do
102
+ result = host.echo('Hello world')
103
+ expect(result.data).to eq('Hello world')
104
+ end
105
+
106
+ it 'seds file to stdout' do
107
+ path = "#{spec_dir}/test-file.txt"
108
+ result = host.echo("Hello world, this is a Cat test file.\nCat\nCat\nDog", new_file: path, mode: 'write')
109
+ expect(result).to be_success
110
+
111
+ result = host.sed(path, 'Cat', 'Dog')
112
+ expect(result).to be_success
113
+ expect(result.data).to eq("Hello world, this is a Dog test file.\nDog\nDog\nDog")
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::File do
6
+ TestHosts.each_os do |os_name|
7
+ context "with #{os_name}" do
8
+ before(:all) do
9
+ host_json = TestHosts.host(os_name)
10
+ host = Kanrisuru::Remote::Host.new(
11
+ host: host_json['hostname'],
12
+ username: host_json['username'],
13
+ keys: [host_json['ssh_key']]
14
+ )
15
+
16
+ host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
17
+ host.disconnect
18
+ end
19
+
20
+ let(:host_json) { TestHosts.host(os_name) }
21
+ let(:host) do
22
+ Kanrisuru::Remote::Host.new(
23
+ host: host_json['hostname'],
24
+ username: host_json['username'],
25
+ keys: [host_json['ssh_key']]
26
+ )
27
+ end
28
+
29
+ let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
+
31
+ after do
32
+ host.disconnect
33
+ end
34
+
35
+ after(:all) do
36
+ host_json = TestHosts.host(os_name)
37
+ host = Kanrisuru::Remote::Host.new(
38
+ host: host_json['hostname'],
39
+ username: host_json['username'],
40
+ keys: [host_json['ssh_key']]
41
+ )
42
+
43
+ host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
44
+ host.disconnect
45
+ end
46
+
47
+ it 'uploads a template file' do
48
+ path = '../templates/test.conf.erb'
49
+ dest_path = "#{spec_dir}/test.conf"
50
+
51
+ template = Kanrisuru::Template.new(path, array: %w[this is an array])
52
+ result = host.upload(template.read, dest_path)
53
+
54
+ expect(result).to be_success
55
+ expect(result.mode.numeric).to eq('640')
56
+ expect(result.user).to eq(host_json['username'])
57
+
58
+ case os_name
59
+ when 'sles', 'opensuse'
60
+ expect(result.gid).to eq(100)
61
+ expect(result.group).to eq('users')
62
+ else
63
+ expect(result.gid).to eq(1000)
64
+ expect(result.group).to eq(host_json['username'])
65
+ end
66
+
67
+ expect(host.cat(dest_path).to_a).to eq([
68
+ '<h1>Hello World</h1>',
69
+ 'this',
70
+ 'is',
71
+ 'an',
72
+ 'array'
73
+ ])
74
+ end
75
+
76
+ it 'uploads a dir' do
77
+ path = '../meta/'
78
+ dest_path = "#{spec_dir}/meta"
79
+
80
+ result = host.upload(path, dest_path, recursive: true)
81
+ expect(result).to be_success
82
+ end
83
+
84
+ it 'downloads a file to local fs' do
85
+ path = '../hosts-file'
86
+ src_path = '/etc/hosts'
87
+
88
+ result = host.download(src_path, path)
89
+ expect(result).to eq(path)
90
+ FileUtils.rm(path)
91
+ end
92
+
93
+ it 'downloads a file directly' do
94
+ src_path = '/etc/hosts'
95
+
96
+ result = host.download(src_path)
97
+ expect(result).to be_instance_of(String)
98
+ lines = result.split("\n")
99
+ expect(lines.length).to be >= 1
100
+ end
101
+
102
+ it 'wgets url' do
103
+ result = host.wget('https://example.com', directory_prefix: spec_dir)
104
+ expect(result).to be_success
105
+ end
106
+ end
107
+ end
108
+ end
File without changes
File without changes
@@ -5,7 +5,7 @@ require 'spec_helper'
5
5
  RSpec.describe Kanrisuru::Remote::Cluster do
6
6
  context 'with ubuntu' do
7
7
  it 'gets hostname for cluster' do
8
- cluster = described_class.new([{
8
+ cluster = described_class.new({
9
9
  host: 'localhost',
10
10
  username: 'ubuntu',
11
11
  keys: ['~/.ssh/id_rsa']
@@ -13,7 +13,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
13
13
  host: '127.0.0.1',
14
14
  username: 'ubuntu',
15
15
  keys: ['~/.ssh/id_rsa']
16
- }])
16
+ })
17
17
 
18
18
  expect(cluster.hostname).to match([
19
19
  { host: 'localhost', result: 'ubuntu' },
@@ -24,7 +24,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
24
24
  end
25
25
 
26
26
  it 'can ping host cluster' do
27
- cluster = described_class.new([{
27
+ cluster = described_class.new({
28
28
  host: 'localhost',
29
29
  username: 'ubuntu',
30
30
  keys: ['~/.ssh/id_rsa']
@@ -32,7 +32,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
32
32
  host: '127.0.0.1',
33
33
  username: 'ubuntu',
34
34
  keys: ['~/.ssh/id_rsa']
35
- }])
35
+ })
36
36
 
37
37
  expect(cluster.ping?).to match([
38
38
  { host: 'localhost', result: true },
File without changes
File without changes
File without changes
data/spec/spec_helper.rb CHANGED
@@ -4,7 +4,10 @@ require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
6
  require 'kanrisuru'
7
+
7
8
  require_relative 'helper/test_hosts'
9
+ require_relative 'helper/stub_network'
10
+ require_relative 'helper/expect_helpers'
8
11
 
9
12
  Kanrisuru.logger.level = Logger::WARN
10
13
 
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.13
4
+ version: 0.8.17
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-04 00:00:00.000000000 Z
11
+ date: 2021-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -173,34 +173,40 @@ 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
176
  - spec/functional/core/path_spec.rb
185
- - spec/functional/core/socket_spec.rb
186
177
  - spec/functional/core/stat_spec.rb
187
178
  - spec/functional/core/stream_spec.rb
188
- - spec/functional/core/system_spec.rb
189
179
  - 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
180
  - 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
181
+ - spec/helper/expect_helpers.rb
182
+ - spec/helper/stub_network.rb
202
183
  - spec/helper/test_hosts.rb
203
184
  - spec/hosts.json
185
+ - spec/integration/core/apt_spec.rb
186
+ - spec/integration/core/archive_spec.rb
187
+ - spec/integration/core/disk_spec.rb
188
+ - spec/integration/core/dmi_spec.rb
189
+ - spec/integration/core/file_spec.rb
190
+ - spec/integration/core/find_spec.rb
191
+ - spec/integration/core/group_spec.rb
192
+ - spec/integration/core/ip_spec.rb
193
+ - spec/integration/core/path_spec.rb
194
+ - spec/integration/core/socket_spec.rb
195
+ - spec/integration/core/stat_spec.rb
196
+ - spec/integration/core/stream_spec.rb
197
+ - spec/integration/core/system_spec.rb
198
+ - spec/integration/core/transfer_spec.rb
199
+ - spec/integration/core/user_spec.rb
200
+ - spec/integration/core/yum_spec.rb
201
+ - spec/integration/core/zypper_spec.rb
202
+ - spec/integration/remote/cluster_spec.rb
203
+ - spec/integration/remote/cpu_spec.rb
204
+ - spec/integration/remote/env_spec.rb
205
+ - spec/integration/remote/fstab_spec.rb
206
+ - spec/integration/remote/host_spec.rb
207
+ - spec/integration/remote/memory_spec.rb
208
+ - spec/integration/remote/os_spec.rb
209
+ - spec/integration/remote/remote_file_spec.rb
204
210
  - spec/spec_helper.rb
205
211
  - spec/unit/core/apt_spec.rb
206
212
  - spec/unit/core/archive_spec.rb