kanrisuru 0.15.0 → 0.16.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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/kanrisuru.gemspec +7 -3
  4. data/lib/kanrisuru/command.rb +5 -1
  5. data/lib/kanrisuru/core/disk/commands/lsblk.rb +6 -11
  6. data/lib/kanrisuru/core/disk/constants.rb +9 -0
  7. data/lib/kanrisuru/core/disk/parser.rb +1 -0
  8. data/lib/kanrisuru/core/disk/parsers/lsblk_version.rb +21 -0
  9. data/lib/kanrisuru/core/disk.rb +1 -0
  10. data/lib/kanrisuru/core/dmi/commands/dmi.rb +1 -1
  11. data/lib/kanrisuru/core/file/commands/chmod.rb +1 -1
  12. data/lib/kanrisuru/core/file/commands/copy.rb +1 -3
  13. data/lib/kanrisuru/core/file/commands/mkdir.rb +11 -6
  14. data/lib/kanrisuru/core/file/commands/rm.rb +4 -1
  15. data/lib/kanrisuru/core/file/commands/touch.rb +2 -1
  16. data/lib/kanrisuru/core/system/commands/kill.rb +1 -1
  17. data/lib/kanrisuru/core/user/commands/create_user.rb +9 -17
  18. data/lib/kanrisuru/core/user/commands/delete_user.rb +1 -1
  19. data/lib/kanrisuru/core/user/commands/update_user.rb +14 -23
  20. data/lib/kanrisuru/result.rb +15 -0
  21. data/lib/kanrisuru/version.rb +1 -1
  22. data/spec/functional/core/archive_spec.rb +1 -1
  23. data/spec/functional/core/disk_spec.rb +77 -0
  24. data/spec/functional/core/dmi_spec.rb +78 -0
  25. data/spec/functional/core/file_spec.rb +284 -0
  26. data/spec/functional/core/group_spec.rb +62 -0
  27. data/spec/functional/core/system_spec.rb +135 -0
  28. data/spec/functional/core/user_spec.rb +97 -0
  29. data/spec/functional/result_spec.rb +91 -44
  30. data/spec/helper/stub_network.rb +6 -2
  31. data/spec/unit/command_spec.rb +2 -0
  32. data/spec/unit/core/ip_spec.rb +12 -0
  33. metadata +13 -4
@@ -57,72 +57,119 @@ RSpec.describe Kanrisuru::Result do
57
57
  expect(result.to_s).to eq('output')
58
58
  end
59
59
 
60
- it 'returns to_a on array result' do
61
- command.handle_status(0)
62
- result = described_class.new(command) do |_cmd|
63
- [0, 1, 2, 3]
60
+ context 'with to_a' do
61
+ it 'returns to_a on array result' do
62
+ command.handle_status(0)
63
+ result = described_class.new(command) do |_cmd|
64
+ [0, 1, 2, 3]
65
+ end
66
+
67
+ expect(result.to_a).to eq([0, 1, 2, 3])
64
68
  end
65
69
 
66
- expect(result.to_a).to eq([0, 1, 2, 3])
67
- end
70
+ it 'returns to_a on non-array result' do
71
+ command.handle_status(0)
72
+ result = described_class.new(command) do |_cmd|
73
+ 'output'
74
+ end
68
75
 
69
- it 'returns to_a on non-array result' do
70
- command.handle_status(0)
71
- result = described_class.new(command) do |_cmd|
72
- 'output'
76
+ expect(result.to_a).to eq(['output'])
73
77
  end
74
78
 
75
- expect(result.to_a).to eq(['output'])
76
- end
79
+ it 'returns to_i on integer return value' do
80
+ command.handle_status(0)
81
+ result = described_class.new(command) do |_cmd|
82
+ 55
83
+ end
77
84
 
78
- it 'returns to_i on integer return value' do
79
- command.handle_status(0)
80
- result = described_class.new(command) do |_cmd|
81
- 55
85
+ expect(result.to_i).to eq(55)
82
86
  end
83
-
84
- expect(result.to_i).to eq(55)
85
87
  end
86
88
 
87
- it 'returns to_i on non-integer return value' do
88
- command.handle_status(0)
89
- result = described_class.new(command) do |_cmd|
90
- '100'
91
- end
89
+ context 'with to_i' do
90
+ it 'returns to_i on non-integer return value' do
91
+ command.handle_status(0)
92
+ result = described_class.new(command) do |_cmd|
93
+ '100'
94
+ end
92
95
 
93
- expect(result.to_i).to eq(100)
96
+ expect(result.to_i).to eq(100)
94
97
 
95
- result = described_class.new(command) do |_cmd|
96
- 'hello'
97
- end
98
+ result = described_class.new(command) do |_cmd|
99
+ 'hello'
100
+ end
98
101
 
99
- expect(result.to_i).to eq(0)
102
+ expect(result.to_i).to eq(0)
100
103
 
101
- result = described_class.new(command) do |_cmd|
102
- [0, 1, 2, 3]
103
- end
104
+ result = described_class.new(command) do |_cmd|
105
+ [0, 1, 2, 3]
106
+ end
104
107
 
105
- expect(result.to_i).to eq([0, 1, 2, 3])
108
+ expect(result.to_i).to eq([0, 1, 2, 3])
106
109
 
107
- result = described_class.new(command) do |_cmd|
108
- %w[0 1 2 3]
110
+ result = described_class.new(command) do |_cmd|
111
+ %w[0 1 2 3]
112
+ end
113
+
114
+ expect(result.to_i).to eq([0, 1, 2, 3])
115
+
116
+ result = described_class.new(command)
117
+ expect(result.to_i).to be_nil
109
118
  end
110
119
 
111
- expect(result.to_i).to eq([0, 1, 2, 3])
120
+ it 'raises error on to_i for invalid data type' do
121
+ command.handle_status(0)
122
+ result = described_class.new(command) do |_cmd|
123
+ { 'hello' => 'world' }
124
+ end
112
125
 
113
- result = described_class.new(command)
114
- expect(result.to_i).to be_nil
126
+ expect do
127
+ result.to_i
128
+ end.to raise_error(NoMethodError)
129
+ end
115
130
  end
116
131
 
117
- it 'raises error on to_i for invalid data type' do
118
- command.handle_status(0)
119
- result = described_class.new(command) do |_cmd|
120
- { 'hello' => 'world' }
132
+ context 'with to_f' do
133
+ it 'returns to_f on non-integer return value' do
134
+ command.handle_status(0)
135
+ result = described_class.new(command) do |_cmd|
136
+ '100.5'
137
+ end
138
+
139
+ expect(result.to_f).to eq(100.5)
140
+
141
+ result = described_class.new(command) do |_cmd|
142
+ 'hello'
143
+ end
144
+
145
+ expect(result.to_f).to eq(0)
146
+
147
+ result = described_class.new(command) do |_cmd|
148
+ [0.1, 1.2, 2.3, 3.4]
149
+ end
150
+
151
+ expect(result.to_f).to eq([0.1, 1.2, 2.3, 3.4])
152
+
153
+ result = described_class.new(command) do |_cmd|
154
+ %w[0.1 1.2 2.3 3.4]
155
+ end
156
+
157
+ expect(result.to_f).to eq([0.1, 1.2, 2.3, 3.4])
158
+
159
+ result = described_class.new(command)
160
+ expect(result.to_f).to be_nil
121
161
  end
122
162
 
123
- expect do
124
- result.to_i
125
- end.to raise_error(NoMethodError)
163
+ it 'raises error on to_f for invalid data type' do
164
+ command.handle_status(0)
165
+ result = described_class.new(command) do |_cmd|
166
+ { 'hello' => 'world' }
167
+ end
168
+
169
+ expect do
170
+ result.to_f
171
+ end.to raise_error(NoMethodError)
172
+ end
126
173
  end
127
174
 
128
175
  it 'returns success string variant on inspect' do
@@ -69,8 +69,12 @@ class StubNetwork
69
69
  status = opts[:status] || 0
70
70
  command.handle_status(status)
71
71
 
72
- Kanrisuru::Result.new(command, true) do |_cmd|
73
- block.call(args)
72
+ if opts[:return_value].nil?
73
+ Kanrisuru::Result.new(command, true) do |_cmd|
74
+ block.call(args)
75
+ end
76
+ else
77
+ opts[:return_value]
74
78
  end
75
79
  end
76
80
  end
@@ -11,6 +11,7 @@ RSpec.describe Kanrisuru::Command do
11
11
  expect(command).to respond_to(:success?)
12
12
  expect(command).to respond_to(:failure?)
13
13
  expect(command).to respond_to(:to_i)
14
+ expect(command).to respond_to(:to_f)
14
15
  expect(command).to respond_to(:to_s)
15
16
  expect(command).to respond_to(:to_a)
16
17
  expect(command).to respond_to(:to_json)
@@ -26,6 +27,7 @@ RSpec.describe Kanrisuru::Command do
26
27
  expect(command).to respond_to(:append_value)
27
28
  expect(command).to respond_to(:append_arg)
28
29
  expect(command).to respond_to(:append_flag)
30
+ expect(command).to respond_to(:append_flag_no)
29
31
  expect(command).to respond_to(:append_valid_exit_code)
30
32
  end
31
33
 
@@ -35,6 +35,18 @@ RSpec.describe Kanrisuru::Core::IP do
35
35
  ])
36
36
  )
37
37
 
38
+ expect(Kanrisuru::Core::IP::IP_FAMILIES).to(eq(%w[inet inet6 link]))
39
+ expect(Kanrisuru::Core::IP::IP_SCOPES).to(eq(%w[global site link host]))
40
+ expect(Kanrisuru::Core::IP::IP_LINK_TYPES).to(
41
+ eq(%w[
42
+ vlan veth vcan vxcan dummy ifb macvlan macvtap
43
+ bridge bond team ipoib ip6tnl ipip sit vxlan
44
+ gre gretap erspan ip6gre ip6gretap ip6erspan
45
+ vti nlmon team_slave bond_slave bridge_slave
46
+ ipvlan ipvtap geneve vrf macsec netdevsim rmnet
47
+ xfrm bareudp hsr
48
+ ])
49
+ )
38
50
  expect(Kanrisuru::Core::IP::IPLinkProperty.new).to respond_to(
39
51
  :index, :name, :flags, :mtu,
40
52
  :qdisc, :state, :group, :qlen,
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.15.0
4
+ version: 0.16.0
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-12-13 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parallel_tests
@@ -136,8 +136,8 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '6.1'
139
- description: Kanrisuru helps manage remote servers with objected oriented ruby. Results
140
- come back as structured data, parsed, prepared and ready.
139
+ description: " Kanrisuru helps manage remote servers with objected oriented ruby.
140
+ \n Results come back as structured data, parsed, prepared and ready.\n"
141
141
  email: ryan@avamia.com
142
142
  executables: []
143
143
  extensions: []
@@ -193,11 +193,13 @@ files:
193
193
  - lib/kanrisuru/core/disk/commands/df.rb
194
194
  - lib/kanrisuru/core/disk/commands/du.rb
195
195
  - lib/kanrisuru/core/disk/commands/lsblk.rb
196
+ - lib/kanrisuru/core/disk/constants.rb
196
197
  - lib/kanrisuru/core/disk/parser.rb
197
198
  - lib/kanrisuru/core/disk/parsers/blkid.rb
198
199
  - lib/kanrisuru/core/disk/parsers/df.rb
199
200
  - lib/kanrisuru/core/disk/parsers/du.rb
200
201
  - lib/kanrisuru/core/disk/parsers/lsblk.rb
202
+ - lib/kanrisuru/core/disk/parsers/lsblk_version.rb
201
203
  - lib/kanrisuru/core/disk/types.rb
202
204
  - lib/kanrisuru/core/dmi.rb
203
205
  - lib/kanrisuru/core/dmi/commands.rb
@@ -439,7 +441,11 @@ files:
439
441
  - lib/kanrisuru/version.rb
440
442
  - spec/functional/core/apt_spec.rb
441
443
  - spec/functional/core/archive_spec.rb
444
+ - spec/functional/core/disk_spec.rb
445
+ - spec/functional/core/dmi_spec.rb
446
+ - spec/functional/core/file_spec.rb
442
447
  - spec/functional/core/find_spec.rb
448
+ - spec/functional/core/group_spec.rb
443
449
  - spec/functional/core/ip/ip_address_label_spec.rb
444
450
  - spec/functional/core/ip/ip_address_spec.rb
445
451
  - spec/functional/core/ip/ip_link_spec.rb
@@ -453,7 +459,9 @@ files:
453
459
  - spec/functional/core/socket_spec.rb
454
460
  - spec/functional/core/stat_spec.rb
455
461
  - spec/functional/core/stream_spec.rb
462
+ - spec/functional/core/system_spec.rb
456
463
  - spec/functional/core/transfer_spec.rb
464
+ - spec/functional/core/user_spec.rb
457
465
  - spec/functional/core/yum_spec.rb
458
466
  - spec/functional/remote/cluster_spec.rb
459
467
  - spec/functional/remote/cpu_spec.rb
@@ -677,6 +685,7 @@ licenses:
677
685
  metadata:
678
686
  source_code_uri: https://github.com/avamia/kanrisuru/
679
687
  changelog_uri: https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md
688
+ rubygems_mfa_required: 'true'
680
689
  post_install_message:
681
690
  rdoc_options: []
682
691
  require_paths: