kanrisuru 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +17 -0
  3. data/.rubocop.yml +47 -0
  4. data/.rubocop_todo.yml +0 -0
  5. data/CHANGELOG.md +0 -0
  6. data/Gemfile +2 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +143 -7
  9. data/Rakefile +5 -3
  10. data/bin/console +4 -3
  11. data/kanrisuru.gemspec +21 -12
  12. data/lib/kanrisuru.rb +41 -2
  13. data/lib/kanrisuru/command.rb +99 -0
  14. data/lib/kanrisuru/core.rb +53 -0
  15. data/lib/kanrisuru/core/archive.rb +154 -0
  16. data/lib/kanrisuru/core/disk.rb +302 -0
  17. data/lib/kanrisuru/core/file.rb +332 -0
  18. data/lib/kanrisuru/core/find.rb +108 -0
  19. data/lib/kanrisuru/core/group.rb +97 -0
  20. data/lib/kanrisuru/core/ip.rb +1032 -0
  21. data/lib/kanrisuru/core/mount.rb +138 -0
  22. data/lib/kanrisuru/core/path.rb +140 -0
  23. data/lib/kanrisuru/core/socket.rb +168 -0
  24. data/lib/kanrisuru/core/stat.rb +104 -0
  25. data/lib/kanrisuru/core/stream.rb +121 -0
  26. data/lib/kanrisuru/core/system.rb +348 -0
  27. data/lib/kanrisuru/core/transfer.rb +203 -0
  28. data/lib/kanrisuru/core/user.rb +198 -0
  29. data/lib/kanrisuru/logger.rb +8 -0
  30. data/lib/kanrisuru/mode.rb +277 -0
  31. data/lib/kanrisuru/os_package.rb +235 -0
  32. data/lib/kanrisuru/remote.rb +10 -0
  33. data/lib/kanrisuru/remote/cluster.rb +95 -0
  34. data/lib/kanrisuru/remote/cpu.rb +68 -0
  35. data/lib/kanrisuru/remote/env.rb +33 -0
  36. data/lib/kanrisuru/remote/file.rb +354 -0
  37. data/lib/kanrisuru/remote/fstab.rb +412 -0
  38. data/lib/kanrisuru/remote/host.rb +191 -0
  39. data/lib/kanrisuru/remote/memory.rb +19 -0
  40. data/lib/kanrisuru/remote/os.rb +87 -0
  41. data/lib/kanrisuru/result.rb +78 -0
  42. data/lib/kanrisuru/template.rb +32 -0
  43. data/lib/kanrisuru/util.rb +40 -0
  44. data/lib/kanrisuru/util/bits.rb +203 -0
  45. data/lib/kanrisuru/util/fs_mount_opts.rb +655 -0
  46. data/lib/kanrisuru/util/os_family.rb +213 -0
  47. data/lib/kanrisuru/util/signal.rb +161 -0
  48. data/lib/kanrisuru/version.rb +3 -1
  49. data/spec/functional/core/archive_spec.rb +228 -0
  50. data/spec/functional/core/disk_spec.rb +80 -0
  51. data/spec/functional/core/file_spec.rb +341 -0
  52. data/spec/functional/core/find_spec.rb +52 -0
  53. data/spec/functional/core/group_spec.rb +65 -0
  54. data/spec/functional/core/ip_spec.rb +71 -0
  55. data/spec/functional/core/path_spec.rb +93 -0
  56. data/spec/functional/core/socket_spec.rb +31 -0
  57. data/spec/functional/core/stat_spec.rb +98 -0
  58. data/spec/functional/core/stream_spec.rb +99 -0
  59. data/spec/functional/core/system_spec.rb +96 -0
  60. data/spec/functional/core/transfer_spec.rb +108 -0
  61. data/spec/functional/core/user_spec.rb +76 -0
  62. data/spec/functional/os_package_spec.rb +75 -0
  63. data/spec/functional/remote/cluster_spec.rb +45 -0
  64. data/spec/functional/remote/cpu_spec.rb +41 -0
  65. data/spec/functional/remote/env_spec.rb +36 -0
  66. data/spec/functional/remote/fstab_spec.rb +76 -0
  67. data/spec/functional/remote/host_spec.rb +68 -0
  68. data/spec/functional/remote/memory_spec.rb +29 -0
  69. data/spec/functional/remote/os_spec.rb +63 -0
  70. data/spec/functional/remote/remote_file_spec.rb +180 -0
  71. data/spec/helper/test_hosts.rb +68 -0
  72. data/spec/hosts.json +92 -0
  73. data/spec/spec_helper.rb +11 -3
  74. data/spec/unit/fstab_spec.rb +22 -0
  75. data/spec/unit/kanrisuru_spec.rb +9 -0
  76. data/spec/unit/mode_spec.rb +183 -0
  77. data/spec/unit/template_spec.rb +13 -0
  78. data/spec/unit/util_spec.rb +177 -0
  79. data/spec/zz_reboot_spec.rb +46 -0
  80. metadata +136 -13
  81. data/spec/kanrisuru_spec.rb +0 -9
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ class TestHosts
4
+ class << self
5
+ def each_os(&block)
6
+ %w[debian ubuntu fedora centos rhel opensuse sles].each do |os_name|
7
+ next unless test?(os_name)
8
+
9
+ block.call(os_name)
10
+ end
11
+ end
12
+
13
+ def host(name)
14
+ hosts(name)
15
+ end
16
+
17
+ def test?(name)
18
+ return false if host(name).nil?
19
+
20
+ if testable_hosts.nil? && excludable_hosts.nil?
21
+ true
22
+ elsif testable_hosts.nil? && !excludable_hosts.nil?
23
+ hosts_exclude_array = excludable_hosts.split(',')
24
+
25
+ !hosts_exclude_array.include?(name)
26
+ elsif !testable_hosts.nil? && excludable_hosts.nil?
27
+ hosts_include_array = testable_hosts.split(',')
28
+
29
+ hosts_include_array.include?(name)
30
+ else
31
+ hosts_include_array = testable_hosts.split(',')
32
+ hosts_exclude_array = excludable_hosts.split(',')
33
+
34
+ hosts_include_array.include?(name) && !hosts_exclude_array.include?(name)
35
+ end
36
+ end
37
+
38
+ def hosts(name)
39
+ @hosts ||= begin
40
+ result = {}
41
+
42
+ hosts_list.each do |host_item|
43
+ result[host_item['name']] = host_item
44
+ end
45
+
46
+ result
47
+ end
48
+
49
+ @hosts[name]
50
+ end
51
+
52
+ def hosts_list
53
+ json_config_path = File.join('spec', 'hosts.json')
54
+ hosts_data = File.open(json_config_path).read
55
+ JSON.parse(hosts_data)
56
+ end
57
+
58
+ private
59
+
60
+ def excludable_hosts
61
+ ENV['EXCLUDE'] || ENV['IGNORE']
62
+ end
63
+
64
+ def testable_hosts
65
+ ENV['HOSTS']
66
+ end
67
+ end
68
+ end
data/spec/hosts.json ADDED
@@ -0,0 +1,92 @@
1
+ [
2
+ {
3
+ "name": "localhost",
4
+ "port": 22,
5
+ "username": "ubuntu",
6
+ "ssh_key": "~/.ssh/id_rsa",
7
+ "hostname": "localhost",
8
+ "kernel": "Linux",
9
+ "home": "/home/ubuntu"
10
+ },
11
+ {
12
+ "name": "ubuntu",
13
+ "port": 22,
14
+ "username": "ubuntu",
15
+ "ssh_key": "~/.ssh/id_rsa",
16
+ "hostname": "ubuntu-host",
17
+ "kernel": "Linux",
18
+ "home": "/home/ubuntu"
19
+ },
20
+ {
21
+ "name": "debian",
22
+ "port": 22,
23
+ "username": "debian",
24
+ "ssh_key": "~/.ssh/id_rsa",
25
+ "hostname": "debian-host",
26
+ "kernel": "Linux",
27
+ "home": "/home/debian"
28
+ },
29
+ {
30
+ "name": "fedora",
31
+ "port": 22,
32
+ "username": "fedora",
33
+ "ssh_key": "~/.ssh/id_rsa",
34
+ "hostname": "fedora-host",
35
+ "kernel": "Linux",
36
+ "home": "/home/fedora"
37
+ },
38
+ {
39
+ "name": "centos",
40
+ "port": 22,
41
+ "username": "centos",
42
+ "ssh_key": "~/.ssh/id_rsa",
43
+ "hostname": "centos-host",
44
+ "kernel": "Linux",
45
+ "home": "/home/centos"
46
+ },
47
+ {
48
+ "name": "rhel",
49
+ "port": 22,
50
+ "username": "cloud-user",
51
+ "ssh_key": "~/.ssh/id_rsa",
52
+ "hostname": "rhel-host",
53
+ "kernel": "Linux",
54
+ "home": "/home/cloud-user"
55
+ },
56
+ {
57
+ "name": "opensuse",
58
+ "port": 22,
59
+ "username": "opensuse",
60
+ "ssh_key": "~/.ssh/id_rsa",
61
+ "hostname": "opensuse-host",
62
+ "kernel": "Linux",
63
+ "home": "/home/opensuse"
64
+ },
65
+ {
66
+ "name": "sles",
67
+ "port": 22,
68
+ "username": "ec2-user",
69
+ "ssh_key": "~/.ssh/id_rsa",
70
+ "hostname": "sles-host",
71
+ "kernel": "Linux",
72
+ "home": "/home/ec2-user"
73
+ },
74
+ {
75
+ "name": "arch",
76
+ "port": 22,
77
+ "username": "arch",
78
+ "ssh_key": "~/.ssh/id_rsa",
79
+ "hostname": "arch-host",
80
+ "kernel": "Linux",
81
+ "home": "/home/arch"
82
+ },
83
+ {
84
+ "name": "freebsd",
85
+ "port": 22,
86
+ "username": "freebsd",
87
+ "ssh_key": "~/.ssh/id_rsa",
88
+ "hostname": "freebsd-host",
89
+ "kernel": "FreeBSD",
90
+ "home": "/usr/home/freebsd"
91
+ }
92
+ ]
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,17 @@
1
- require "bundler/setup"
2
- require "kanrisuru"
1
+ # frozen_string_literal: true
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'kanrisuru'
7
+
8
+ require_relative 'helper/test_hosts'
9
+
10
+ Kanrisuru.logger.level = Logger::WARN
3
11
 
4
12
  RSpec.configure do |config|
5
13
  # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
14
+ config.example_status_persistence_file_path = '.rspec_status'
7
15
 
8
16
  # Disable RSpec exposing methods globally on `Module` and `main`
9
17
  config.disable_monkey_patching!
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Kanrisuru::Remote::Fstab do
4
+ it 'creates fstab options' do
5
+ options = Kanrisuru::Remote::Fstab::Options.new('ext4', 'user,defaults,resgid=1000,resuid=1000')
6
+
7
+ expect(options.class).to eq(Kanrisuru::Remote::Fstab::Options)
8
+ expect(options.to_s).to eq('user,defaults,resgid=1000,resuid=1000')
9
+
10
+ options = Kanrisuru::Remote::Fstab::Options.new('fat', user: true, defaults: true, uid: 1000, gid: 1000)
11
+
12
+ expect(options.class).to eq(Kanrisuru::Remote::Fstab::Options)
13
+ expect(options.to_s).to eq('user,defaults,uid=1000,gid=1000')
14
+
15
+ options['user'] = false
16
+ options['fat'] = 16
17
+ options[:uid] = 0
18
+ options[:gid] = 0
19
+
20
+ expect(options.to_s).to eq('defaults,uid=0,gid=0,fat=16')
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru do
6
+ it 'has a version number' do
7
+ expect(Kanrisuru::VERSION).not_to be nil
8
+ end
9
+ end
@@ -0,0 +1,183 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Mode do
6
+ it 'parses int mode' do
7
+ mode = described_class.new('644')
8
+ expect(mode.directory?).to eq(false)
9
+
10
+ expect(mode.owner.read?).to eq(true)
11
+ expect(mode.owner.write?).to eq(true)
12
+ expect(mode.owner.execute?).to eq(false)
13
+ expect(mode.owner.all?).to eq(false)
14
+ expect(mode.owner.to_i).to eq(6)
15
+ expect(mode.owner.symbolic).to eq('rw-')
16
+
17
+ expect(mode.group.read?).to eq(true)
18
+ expect(mode.group.write?).to eq(false)
19
+ expect(mode.group.execute?).to eq(false)
20
+ expect(mode.group.all?).to eq(false)
21
+ expect(mode.group.to_i).to eq(4)
22
+ expect(mode.group.symbolic).to eq('r--')
23
+
24
+ expect(mode.other.read?).to eq(true)
25
+ expect(mode.other.write?).to eq(false)
26
+ expect(mode.other.execute?).to eq(false)
27
+ expect(mode.other.all?).to eq(false)
28
+ expect(mode.other.to_i).to eq(4)
29
+ expect(mode.other.symbolic).to eq('r--')
30
+ end
31
+
32
+ it 'parses int mode octal' do
33
+ mode = described_class.new(0o644)
34
+ expect(mode.directory?).to eq(false)
35
+
36
+ expect(mode.owner.read?).to eq(true)
37
+ expect(mode.owner.write?).to eq(true)
38
+ expect(mode.owner.execute?).to eq(false)
39
+ expect(mode.owner.all?).to eq(false)
40
+ expect(mode.owner.to_i).to eq(6)
41
+ expect(mode.owner.symbolic).to eq('rw-')
42
+
43
+ expect(mode.group.read?).to eq(true)
44
+ expect(mode.group.write?).to eq(false)
45
+ expect(mode.group.execute?).to eq(false)
46
+ expect(mode.group.all?).to eq(false)
47
+ expect(mode.group.to_i).to eq(4)
48
+ expect(mode.group.symbolic).to eq('r--')
49
+
50
+ expect(mode.other.read?).to eq(true)
51
+ expect(mode.other.write?).to eq(false)
52
+ expect(mode.other.execute?).to eq(false)
53
+ expect(mode.other.all?).to eq(false)
54
+ expect(mode.other.to_i).to eq(4)
55
+ expect(mode.other.symbolic).to eq('r--')
56
+ end
57
+
58
+ it 'parses ref mode' do
59
+ mode = described_class.new('drwxrwxrwx')
60
+ expect(mode.directory?).to eq(true)
61
+
62
+ expect(mode.owner.read?).to eq(true)
63
+ expect(mode.owner.write?).to eq(true)
64
+ expect(mode.owner.execute?).to eq(true)
65
+ expect(mode.owner.all?).to eq(true)
66
+ expect(mode.owner.to_i).to eq(7)
67
+ expect(mode.owner.symbolic).to eq('rwx')
68
+
69
+ expect(mode.group.read?).to eq(true)
70
+ expect(mode.group.write?).to eq(true)
71
+ expect(mode.group.execute?).to eq(true)
72
+ expect(mode.group.all?).to eq(true)
73
+ expect(mode.group.to_i).to eq(7)
74
+ expect(mode.group.symbolic).to eq('rwx')
75
+
76
+ expect(mode.other.read?).to eq(true)
77
+ expect(mode.other.write?).to eq(true)
78
+ expect(mode.other.execute?).to eq(true)
79
+ expect(mode.other.all?).to eq(true)
80
+ expect(mode.other.to_i).to eq(7)
81
+ expect(mode.other.symbolic).to eq('rwx')
82
+ end
83
+
84
+ it 'changes mode numerically globally' do
85
+ mode = described_class.new(0o600)
86
+
87
+ expect(mode.owner.read?).to eq(true)
88
+ expect(mode.group.read?).to eq(false)
89
+ expect(mode.other.read?).to eq(false)
90
+ expect(mode.symbolic).to eq('-rw-------')
91
+
92
+ mode.numeric = 0o644
93
+
94
+ expect(mode.owner.read?).to eq(true)
95
+ expect(mode.group.read?).to eq(true)
96
+ expect(mode.other.read?).to eq(true)
97
+
98
+ expect(mode.symbolic).to eq('-rw-r--r--')
99
+ expect(mode.to_s).to eq('-rw-r--r--')
100
+ expect(mode.numeric).to eq('644')
101
+ expect(mode.to_i).to eq(0o644)
102
+ end
103
+
104
+ it 'changes mode symbolically globally' do
105
+ mode = described_class.new(0o600)
106
+
107
+ expect(mode.owner.read?).to eq(true)
108
+ expect(mode.group.read?).to eq(false)
109
+ expect(mode.other.read?).to eq(false)
110
+ expect(mode.symbolic).to eq('-rw-------')
111
+
112
+ mode.symbolic = '-rw-r--r--'
113
+
114
+ expect(mode.owner.read?).to eq(true)
115
+ expect(mode.group.read?).to eq(true)
116
+ expect(mode.other.read?).to eq(true)
117
+
118
+ expect(mode.symbolic).to eq('-rw-r--r--')
119
+ expect(mode.to_s).to eq('-rw-r--r--')
120
+ expect(mode.numeric).to eq('644')
121
+ expect(mode.to_i).to eq(0o644)
122
+ end
123
+
124
+ it 'changes mode numerically each permission level boolean' do
125
+ mode = described_class.new(0o600)
126
+
127
+ expect(mode.other.read?).to eq(false)
128
+ expect(mode.group.read?).to eq(false)
129
+
130
+ mode.group.read = true
131
+ mode.other.read = true
132
+
133
+ expect(mode.group.read?).to eq(true)
134
+ expect(mode.other.read?).to eq(true)
135
+
136
+ expect(mode.symbolic).to eq('-rw-r--r--')
137
+ expect(mode.to_s).to eq('-rw-r--r--')
138
+ expect(mode.numeric).to eq('644')
139
+ expect(mode.to_i).to eq(0o644)
140
+ end
141
+
142
+ it 'changes mode on each permission level symbolic' do
143
+ mode = described_class.new(0o600)
144
+
145
+ expect(mode.other.read?).to eq(false)
146
+ expect(mode.group.read?).to eq(false)
147
+
148
+ mode.group.symbolic = 'rw-'
149
+ mode.other.symbolic = 'r--'
150
+
151
+ expect(mode.group.read?).to eq(true)
152
+ expect(mode.group.write?).to eq(true)
153
+ expect(mode.other.read?).to eq(true)
154
+
155
+ expect(mode.symbolic).to eq('-rw-rw-r--')
156
+ expect(mode.to_s).to eq('-rw-rw-r--')
157
+ expect(mode.numeric).to eq('664')
158
+ expect(mode.to_i).to eq(0o664)
159
+ end
160
+
161
+ it 'changes mode globally using symoblic operator' do
162
+ mode = described_class.new(0o601)
163
+
164
+ expect(mode.other.read?).to eq(false)
165
+ expect(mode.group.read?).to eq(false)
166
+ expect(mode.symbolic).to eq('-rw------x')
167
+
168
+ mode.symbolic = 'u=rwx,g+w,o-x'
169
+ expect(mode.numeric).to eq('720')
170
+ expect(mode.symbolic).to eq('-rwx-w----')
171
+
172
+ mode.symbolic = 'a=r'
173
+ expect(mode.symbolic).to eq('-r--r--r--')
174
+ expect(mode.to_i).to eq(0o444)
175
+
176
+ mode.symbolic = 'u-r,gu+x,a+w'
177
+ expect(mode.numeric).to eq('376')
178
+ expect(mode.symbolic).to eq('--wxrwxrw-')
179
+
180
+ mode.symbolic = '-w'
181
+ expect(mode.symbolic).to eq('---xr-xr--')
182
+ end
183
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Template do
6
+ it 'reads template file' do
7
+ path = '/home/ubuntu/kanrisuru/templates/test.conf.erb'
8
+ template = described_class.new(path, array: %w[hello world])
9
+ template.trim_mode = '-'
10
+
11
+ puts template.render
12
+ end
13
+ end
@@ -0,0 +1,177 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Util do
6
+ it 'gets present value' do
7
+ expect(described_class.present?(1)).to eq(true)
8
+ expect(described_class.present?(true)).to eq(true)
9
+ expect(described_class.present?('a')).to eq(true)
10
+ expect(described_class.present?(Class)).to eq(true)
11
+
12
+ expect(described_class.present?(false)).to eq(false)
13
+ expect(described_class.present?('')).to eq(false)
14
+ expect(described_class.present?([])).to eq(false)
15
+ expect(described_class.present?(nil)).to eq(false)
16
+ end
17
+
18
+ it 'camelizes strings' do
19
+ expect(described_class.camelize('hello_world')).to eq('HelloWorld')
20
+ expect(described_class.camelize('helloworld')).to eq('Helloworld')
21
+ expect(described_class.camelize('HelloWorld')).to eq('HelloWorld')
22
+ end
23
+
24
+ it 'gets os family' do
25
+ expect(Kanrisuru::Util::OsFamily['debian']).to match({
26
+ name: 'Debian',
27
+ os_family: 'linux',
28
+ upstream: 'linux',
29
+ model: 'open_source',
30
+ state: 'current',
31
+ type: 'distribution'
32
+ })
33
+ end
34
+
35
+ it 'detects family inclusion of distribution' do
36
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('linux', 'centos')).to eq(true)
37
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix_like', 'centos')).to eq(true)
38
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix', 'centos')).to eq(true)
39
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix_like', 'linux')).to eq(true)
40
+
41
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('linux', 'ubuntu')).to eq(true)
42
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('linux', 'debian')).to eq(true)
43
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('linux', 'linux_mint')).to eq(true)
44
+
45
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix', 'bsd')).to eq(true)
46
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix_like', 'open_bsd')).to eq(true)
47
+
48
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix_like', 'darwin')).to eq(true)
49
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('unix_like', 'pure_darwin')).to eq(true)
50
+
51
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('linux', 'redhat')).to eq(true)
52
+
53
+ expect(Kanrisuru::Util::OsFamily.family_include_distribution?('fedora', 'redhat')).to eq(false)
54
+ end
55
+
56
+ it 'detects upstream inclusion of distribution' do
57
+ expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('debian', 'ubuntu')).to eq(true)
58
+ expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('debian', 'linux_mint')).to eq(true)
59
+ expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('linux', 'linux_mint')).to eq(true)
60
+
61
+ expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('fedora', 'redhat')).to eq(true)
62
+ expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('fedora', 'centos')).to eq(true)
63
+
64
+ expect(Kanrisuru::Util::OsFamily.upstream_include_distribution?('unix_like', 'linux_mint')).to eq(false)
65
+ end
66
+
67
+ it 'converts from methods' do
68
+ expect(Kanrisuru::Util::Bits.convert_from_kb(1_000, :mb)).to eq(1)
69
+ expect(Kanrisuru::Util::Bits.convert_from_mb(1_000, :gb)).to eq(1)
70
+ expect(Kanrisuru::Util::Bits.convert_from_gb(1_000, :tb)).to eq(1)
71
+ expect(Kanrisuru::Util::Bits.convert_from_tb(1_000, :pb)).to eq(1)
72
+ expect(Kanrisuru::Util::Bits.convert_from_pb(1_000, :pb)).to eq(1_000)
73
+ end
74
+
75
+ it 'converts bytes and bits' do
76
+ expect(Kanrisuru::Util::Bits.convert_bytes(1_000, :kilobyte, :kilobyte)).to eq(1000)
77
+ expect(Kanrisuru::Util::Bits.convert_bytes(1_000, :kilobyte, :kb)).to eq(1000)
78
+ expect(Kanrisuru::Util::Bits.convert_bytes(100, :kilobit, :kilobit)).to eq(100)
79
+ expect(Kanrisuru::Util::Bits.convert_bytes(800, :kilobit, :kilobyte)).to eq(100)
80
+ expect(Kanrisuru::Util::Bits.convert_bytes(100, :kilobyte, :kilobit)).to eq(800)
81
+
82
+ expect { Kanrisuru::Util::Bits.convert_bytes(100, :kilobyte, :kilobitt) }.to raise_error(ArgumentError)
83
+ expect { Kanrisuru::Util::Bits.convert_bytes(100, :kilobytee, :kilobit) }.to raise_error(ArgumentError)
84
+ end
85
+
86
+ it 'converts power' do
87
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :deca)).to eq(0)
88
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :kilo)).to eq(-1)
89
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :mega)).to eq(-2)
90
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :giga)).to eq(-3)
91
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :tera)).to eq(-4)
92
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :peta)).to eq(-5)
93
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :exa)).to eq(-6)
94
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :zetta)).to eq(-7)
95
+ expect(Kanrisuru::Util::Bits.convert_power(:deca, :yotta)).to eq(-8)
96
+
97
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :deca)).to eq(1)
98
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :kilo)).to eq(0)
99
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :mega)).to eq(-1)
100
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :giga)).to eq(-2)
101
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :tera)).to eq(-3)
102
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :peta)).to eq(-4)
103
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :exa)).to eq(-5)
104
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :zetta)).to eq(-6)
105
+ expect(Kanrisuru::Util::Bits.convert_power(:kilo, :yotta)).to eq(-7)
106
+
107
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :deca)).to eq(2)
108
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :kilo)).to eq(1)
109
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :mega)).to eq(0)
110
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :giga)).to eq(-1)
111
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :tera)).to eq(-2)
112
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :peta)).to eq(-3)
113
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :exa)).to eq(-4)
114
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :zetta)).to eq(-5)
115
+ expect(Kanrisuru::Util::Bits.convert_power(:mega, :yotta)).to eq(-6)
116
+
117
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :deca)).to eq(3)
118
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :kilo)).to eq(2)
119
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :mega)).to eq(1)
120
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :giga)).to eq(0)
121
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :tera)).to eq(-1)
122
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :peta)).to eq(-2)
123
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :exa)).to eq(-3)
124
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :zetta)).to eq(-4)
125
+ expect(Kanrisuru::Util::Bits.convert_power(:giga, :yotta)).to eq(-5)
126
+
127
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :deca)).to eq(4)
128
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :kilo)).to eq(3)
129
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :mega)).to eq(2)
130
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :giga)).to eq(1)
131
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :tera)).to eq(0)
132
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :peta)).to eq(-1)
133
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :exa)).to eq(-2)
134
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :zetta)).to eq(-3)
135
+ expect(Kanrisuru::Util::Bits.convert_power(:tera, :yotta)).to eq(-4)
136
+
137
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :deca)).to eq(5)
138
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :kilo)).to eq(4)
139
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :mega)).to eq(3)
140
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :giga)).to eq(2)
141
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :tera)).to eq(1)
142
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :peta)).to eq(0)
143
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :exa)).to eq(-1)
144
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :zetta)).to eq(-2)
145
+ expect(Kanrisuru::Util::Bits.convert_power(:peta, :yotta)).to eq(-3)
146
+
147
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :deca)).to eq(6)
148
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :kilo)).to eq(5)
149
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :mega)).to eq(4)
150
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :giga)).to eq(3)
151
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :tera)).to eq(2)
152
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :peta)).to eq(1)
153
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :exa)).to eq(0)
154
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :zetta)).to eq(-1)
155
+ expect(Kanrisuru::Util::Bits.convert_power(:exa, :yotta)).to eq(-2)
156
+
157
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :deca)).to eq(7)
158
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :kilo)).to eq(6)
159
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :mega)).to eq(5)
160
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :giga)).to eq(4)
161
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :tera)).to eq(3)
162
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :peta)).to eq(2)
163
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :exa)).to eq(1)
164
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :zetta)).to eq(0)
165
+ expect(Kanrisuru::Util::Bits.convert_power(:zetta, :yotta)).to eq(-1)
166
+
167
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :deca)).to eq(8)
168
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :kilo)).to eq(7)
169
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :mega)).to eq(6)
170
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :giga)).to eq(5)
171
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :tera)).to eq(4)
172
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :peta)).to eq(3)
173
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :exa)).to eq(2)
174
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :zetta)).to eq(1)
175
+ expect(Kanrisuru::Util::Bits.convert_power(:yotta, :yotta)).to eq(0)
176
+ end
177
+ end