moose-inventory 1.0.8 → 2.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 (104) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +49 -0
  3. data/.github/workflows/release.yml +58 -0
  4. data/.gitignore +1 -1
  5. data/.gitleaks.toml +9 -0
  6. data/.rubocop.yml +19 -784
  7. data/BACKLOG.md +290 -0
  8. data/Gemfile.lock +95 -0
  9. data/README.md +38 -9
  10. data/Rakefile +1 -1
  11. data/bin/moose-inventory +1 -1
  12. data/docs/release/publishing.md +109 -0
  13. data/docs/release/release-readiness.md +55 -0
  14. data/docs/security-audit-2026-05-21.md +71 -0
  15. data/docs/security-audit-2026-05-26-rerun.md +75 -0
  16. data/docs/security-audit-2026-05-26.md +63 -0
  17. data/lib/moose_inventory/cli/formatter.rb +16 -17
  18. data/lib/moose_inventory/cli/group.rb +4 -1
  19. data/lib/moose_inventory/cli/group_add.rb +89 -75
  20. data/lib/moose_inventory/cli/group_addchild.rb +84 -71
  21. data/lib/moose_inventory/cli/group_addhost.rb +78 -69
  22. data/lib/moose_inventory/cli/group_addvar.rb +37 -37
  23. data/lib/moose_inventory/cli/group_get.rb +23 -26
  24. data/lib/moose_inventory/cli/group_list.rb +12 -15
  25. data/lib/moose_inventory/cli/group_listvars.rb +12 -14
  26. data/lib/moose_inventory/cli/group_rm.rb +104 -76
  27. data/lib/moose_inventory/cli/group_rmchild.rb +99 -54
  28. data/lib/moose_inventory/cli/group_rmhost.rb +64 -60
  29. data/lib/moose_inventory/cli/group_rmvar.rb +5 -5
  30. data/lib/moose_inventory/cli/helpers.rb +76 -0
  31. data/lib/moose_inventory/cli/host.rb +4 -1
  32. data/lib/moose_inventory/cli/host_add.rb +51 -66
  33. data/lib/moose_inventory/cli/host_addgroup.rb +77 -68
  34. data/lib/moose_inventory/cli/host_addvar.rb +6 -6
  35. data/lib/moose_inventory/cli/host_get.rb +15 -18
  36. data/lib/moose_inventory/cli/host_list.rb +3 -3
  37. data/lib/moose_inventory/cli/host_listvars.rb +21 -23
  38. data/lib/moose_inventory/cli/host_rm.rb +9 -9
  39. data/lib/moose_inventory/cli/host_rmgroup.rb +63 -60
  40. data/lib/moose_inventory/cli/host_rmvar.rb +3 -3
  41. data/lib/moose_inventory/config/config.rb +43 -40
  42. data/lib/moose_inventory/db/db.rb +92 -52
  43. data/lib/moose_inventory/db/models.rb +11 -12
  44. data/lib/moose_inventory/inventory_context.rb +50 -0
  45. data/lib/moose_inventory/operations/add_associations.rb +127 -0
  46. data/lib/moose_inventory/operations/add_groups.rb +115 -0
  47. data/lib/moose_inventory/operations/add_hosts.rb +110 -0
  48. data/lib/moose_inventory/operations/group_child_relations.rb +118 -0
  49. data/lib/moose_inventory/operations/group_cleanup.rb +55 -0
  50. data/lib/moose_inventory/operations/remove_associations.rb +101 -0
  51. data/lib/moose_inventory/operations/remove_groups.rb +79 -0
  52. data/lib/moose_inventory/version.rb +1 -1
  53. data/moose-inventory.gemspec +38 -20
  54. data/scripts/check.sh +10 -0
  55. data/scripts/ci/check_permissions.sh +35 -0
  56. data/scripts/ci/check_rubocop.sh +28 -0
  57. data/scripts/ci/check_secrets.sh +26 -0
  58. data/scripts/ci/check_security.sh +68 -0
  59. data/scripts/ci/install_security_tools.sh +47 -0
  60. data/scripts/ci/package_sanity.sh +46 -0
  61. data/scripts/files.rb +1 -4
  62. data/scripts/install_dependencies.sh +19 -0
  63. data/scripts/reports.sh +2 -2
  64. data/spec/lib/moose_inventory/cli/cli_spec.rb +13 -14
  65. data/spec/lib/moose_inventory/cli/group_add_spec.rb +118 -119
  66. data/spec/lib/moose_inventory/cli/group_addchild_spec.rb +49 -51
  67. data/spec/lib/moose_inventory/cli/group_addhost_spec.rb +80 -83
  68. data/spec/lib/moose_inventory/cli/group_addvar_spec.rb +91 -91
  69. data/spec/lib/moose_inventory/cli/group_get_spec.rb +22 -23
  70. data/spec/lib/moose_inventory/cli/group_list_spec.rb +19 -20
  71. data/spec/lib/moose_inventory/cli/group_listvar_spec.rb +35 -36
  72. data/spec/lib/moose_inventory/cli/group_rm_spec.rb +115 -78
  73. data/spec/lib/moose_inventory/cli/group_rmchild_spec.rb +86 -45
  74. data/spec/lib/moose_inventory/cli/group_rmhost_spec.rb +43 -46
  75. data/spec/lib/moose_inventory/cli/group_rmvar_spec.rb +131 -131
  76. data/spec/lib/moose_inventory/cli/group_spec.rb +9 -9
  77. data/spec/lib/moose_inventory/cli/host_add_spec.rb +103 -43
  78. data/spec/lib/moose_inventory/cli/host_addgroup_spec.rb +78 -80
  79. data/spec/lib/moose_inventory/cli/host_addvar_spec.rb +122 -122
  80. data/spec/lib/moose_inventory/cli/host_get_spec.rb +16 -16
  81. data/spec/lib/moose_inventory/cli/host_list_spec.rb +8 -8
  82. data/spec/lib/moose_inventory/cli/host_listvar_spec.rb +50 -52
  83. data/spec/lib/moose_inventory/cli/host_rm_spec.rb +12 -12
  84. data/spec/lib/moose_inventory/cli/host_rmgroup_spec.rb +48 -51
  85. data/spec/lib/moose_inventory/cli/host_rmvar_spec.rb +136 -136
  86. data/spec/lib/moose_inventory/config/config_spec.rb +16 -3
  87. data/spec/lib/moose_inventory/db/db_spec.rb +386 -2
  88. data/spec/lib/moose_inventory/db/models_spec.rb +10 -11
  89. data/spec/lib/moose_inventory/operations/add_associations_spec.rb +77 -0
  90. data/spec/lib/moose_inventory/operations/add_groups_spec.rb +65 -0
  91. data/spec/lib/moose_inventory/operations/add_hosts_spec.rb +69 -0
  92. data/spec/lib/moose_inventory/operations/group_child_relations_spec.rb +76 -0
  93. data/spec/lib/moose_inventory/operations/remove_associations_spec.rb +78 -0
  94. data/spec/lib/moose_inventory/operations/remove_groups_spec.rb +57 -0
  95. data/spec/shared/shared_config_setup.rb +2 -2
  96. data/spec/spec_helper.rb +7 -8
  97. metadata +157 -105
  98. data/.coveralls.yml +0 -0
  99. data/Guardfile +0 -38
  100. data/config/dotfiles/coveralls.yml +0 -0
  101. data/config/dotfiles/gitignore +0 -20
  102. data/config/dotfiles/rubocop.yml +0 -793
  103. data/scripts/guard_quality.sh +0 -3
  104. data/scripts/guard_test.sh +0 -2
@@ -9,7 +9,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
9
9
  @mockarg_parts = {
10
10
  config: File.join(spec_root, 'config/config.yml'),
11
11
  format: 'yaml',
12
- env: 'test'
12
+ env: 'test',
13
13
  }
14
14
 
15
15
  @mockargs = []
@@ -19,7 +19,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
19
19
  end
20
20
 
21
21
  @console = Moose::Inventory::Cli::Formatter
22
-
22
+
23
23
  @config = Moose::Inventory::Config
24
24
  @config.init(@mockargs)
25
25
 
@@ -45,35 +45,34 @@ RSpec.describe Moose::Inventory::Cli::Group do
45
45
 
46
46
  #------------------------
47
47
  it 'addhost <missing args> ... should abort with an error' do
48
- actual = runner do
48
+ actual = runner do
49
49
  @app.start(%w(group addhost)) # <- no group given
50
50
  end
51
51
 
52
- #@console.out(actual, 'y')
53
-
52
+ # @console.out(actual, 'y')
53
+
54
54
  # Check output
55
- desired = { aborted: true}
55
+ desired = { aborted: true }
56
56
  desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
57
57
  expected(actual, desired)
58
58
  end
59
59
 
60
60
  #------------------------
61
61
  it 'GROUP HOST ... should abort if the group does not exist' do
62
-
63
62
  host_name = 'example'
64
63
  group_name = 'not-a-group'
65
-
64
+
66
65
  actual = runner do
67
66
  @app.start(%W(group addhost #{group_name} #{host_name}))
68
67
  end
69
68
 
70
- #@console.out(actual, 'y')
69
+ # @console.out(actual, 'y')
71
70
  # Check output
72
- desired = { aborted: true}
73
- desired[:STDOUT] =
71
+ desired = { aborted: true }
72
+ desired[:STDOUT] =
74
73
  "Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
75
74
  " - retrieve group '#{group_name}'...\n"
76
- desired[:STDERR] =
75
+ desired[:STDERR] =
77
76
  "ERROR: The group '#{group_name}' does not exist.\n"\
78
77
  "An error occurred during a transaction, any changes have been rolled back.\n"
79
78
  expected(actual, desired)
@@ -83,18 +82,18 @@ RSpec.describe Moose::Inventory::Cli::Group do
83
82
  it 'GROUP HOST... should add the host to an existing group' do
84
83
  # 1. Should add the host to the group
85
84
  # 2. Should remove the host from the 'ungrouped' automatic group
86
-
85
+
87
86
  host_name = 'test1'
88
87
  group_name = 'testgroup1'
89
88
 
90
89
  runner { @app.start(%W(host add #{host_name})) }
91
90
  @db.models[:group].create(name: group_name)
92
91
 
93
- actual = runner { @app.start(%W(group addhost #{group_name} #{host_name} )) }
92
+ actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
94
93
 
95
94
  # rubocop:disable Metrics/LineLength
96
- desired = { aborted: false}
97
- desired[:STDOUT] =
95
+ desired = { aborted: false }
96
+ desired[:STDOUT] =
98
97
  "Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
99
98
  " - retrieve group '#{group_name}'...\n"\
100
99
  " - OK\n"\
@@ -109,28 +108,27 @@ RSpec.describe Moose::Inventory::Cli::Group do
109
108
 
110
109
  # We should have the correct group associations
111
110
  host = @db.models[:host].find(name: host_name)
112
- groups = host.groups_dataset
111
+ groups = host.groups_dataset
113
112
  expect(groups.count).to eq(1)
114
113
  expect(groups[name: group_name]).not_to be_nil
115
- expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
114
+ expect(groups[name: 'ungrouped']).to be_nil # redundant, but for clarity!
116
115
  end
117
116
 
118
117
  #------------------------
119
118
  it '\'ungrouped\' HOST... should abort with an error' do
120
-
121
119
  host_name = 'test1'
122
120
  group_name = 'ungrouped'
123
-
121
+
124
122
  runner { @app.start(%W(host add #{host_name})) }
125
-
126
- actual = runner { @app.start(%W(group addhost #{group_name} #{host_name} )) }
127
-
128
- desired = { aborted: true}
129
- desired[:STDERR] =
123
+
124
+ actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
125
+
126
+ desired = { aborted: true }
127
+ desired[:STDERR] =
130
128
  "ERROR: Cannot manually manipulate the automatic group 'ungrouped'.\n"
131
129
  expected(actual, desired)
132
- end
133
-
130
+ end
131
+
134
132
  #------------------------
135
133
  it 'GROUP HOST ... should add the host to an group, creating the host if necessary' do
136
134
  host_name = 'test1'
@@ -140,11 +138,11 @@ RSpec.describe Moose::Inventory::Cli::Group do
140
138
 
141
139
  # DON'T CREATE THE HOST! That's the point of the test. ;o)
142
140
 
143
- actual = runner { @app.start(%W(group addhost #{group_name} #{host_name} )) }
141
+ actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
144
142
 
145
143
  # Check output
146
144
  desired = {}
147
- desired[:STDOUT] =
145
+ desired[:STDOUT] =
148
146
  "Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
149
147
  " - retrieve group '#{group_name}'...\n"\
150
148
  " - OK\n"\
@@ -155,54 +153,54 @@ RSpec.describe Moose::Inventory::Cli::Group do
155
153
  " - all OK\n"\
156
154
  "Succeeded, with warnings.\n"
157
155
  desired[:STDERR] =
158
- "WARNING: Host '#{host_name}' does not exist and will be created.\n"
156
+ "WARNING: Host '#{host_name}' does not exist and will be created.\n"
159
157
  expected(actual, desired)
160
158
 
161
- # Check db
159
+ # Check db
162
160
  group = @db.models[:group].find(name: group_name)
163
161
  hosts = group.hosts_dataset
164
162
  expect(hosts.count).to eq(1)
165
163
  expect(hosts[name: host_name]).not_to be_nil
166
164
  end
167
-
165
+
168
166
  #------------------------
169
167
  it 'GROUP HOST... should skip associations that already '\
170
168
  ' exist, but raise a warning.' do
171
- host_name = 'test1'
172
- group_name = 'testgroup1'
173
-
174
- runner { @app.start(%W(group add #{group_name})) }
175
- runner { @app.start(%W(host add #{host_name})) }
176
-
177
- # Run once to make the initial association
178
- runner { @app.start(%W(group addhost #{group_name} #{host_name} )) }
179
-
180
- # Run again, to prove expected result
181
- actual = runner { @app.start(%W(group addhost #{group_name} #{host_name} )) }
182
-
183
- #@console.out(actual,'y')
184
-
185
- # Check output
186
- desired = {}
187
- desired[:STDOUT] =
188
- "Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
189
- " - retrieve group \'#{group_name}\'...\n"\
190
- " - OK\n"\
191
- " - add association {group:#{group_name} <-> host:#{host_name}}...\n"\
192
- " - already exists, skipping.\n"\
193
- " - OK\n"\
194
- " - all OK\n"\
195
- "Succeeded, with warnings.\n"
196
- desired[:STDERR] =
197
- "WARNING: Association {group:#{group_name} <-> host:#{host_name}} already exists, skipping.\n"
198
- expected(actual, desired)
199
-
200
- # Check db
201
- group = @db.models[:group].find(name: group_name)
202
- hosts = group.hosts_dataset
203
- expect(hosts.count).to eq(1)
204
- expect(hosts[name: host_name]).not_to be_nil
205
- end
169
+ host_name = 'test1'
170
+ group_name = 'testgroup1'
171
+
172
+ runner { @app.start(%W(group add #{group_name})) }
173
+ runner { @app.start(%W(host add #{host_name})) }
174
+
175
+ # Run once to make the initial association
176
+ runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
177
+
178
+ # Run again, to prove expected result
179
+ actual = runner { @app.start(%W(group addhost #{group_name} #{host_name})) }
180
+
181
+ # @console.out(actual,'y')
182
+
183
+ # Check output
184
+ desired = {}
185
+ desired[:STDOUT] =
186
+ "Associate group '#{group_name}' with host(s) '#{host_name}':\n"\
187
+ " - retrieve group \'#{group_name}\'...\n"\
188
+ " - OK\n"\
189
+ " - add association {group:#{group_name} <-> host:#{host_name}}...\n"\
190
+ " - already exists, skipping.\n"\
191
+ " - OK\n"\
192
+ " - all OK\n"\
193
+ "Succeeded, with warnings.\n"
194
+ desired[:STDERR] =
195
+ "WARNING: Association {group:#{group_name} <-> host:#{host_name}} already exists, skipping.\n"
196
+ expected(actual, desired)
197
+
198
+ # Check db
199
+ group = @db.models[:group].find(name: group_name)
200
+ hosts = group.hosts_dataset
201
+ expect(hosts.count).to eq(1)
202
+ expect(hosts[name: host_name]).not_to be_nil
203
+ end
206
204
 
207
205
  #------------------------
208
206
  it 'GROUP HOST1 HOST2 ... should associate the group with '\
@@ -214,32 +212,31 @@ RSpec.describe Moose::Inventory::Cli::Group do
214
212
  host_names.each do |host|
215
213
  runner { @app.start(%W(host add #{host})) }
216
214
  end
217
-
215
+
218
216
  actual = runner { @app.start(%W(group addhost #{group_name}) + host_names) }
219
217
 
220
- #@console.out(actual, 'y')
221
-
218
+ # @console.out(actual, 'y')
219
+
222
220
  # Check output
223
- desired = { aborted: false, STDERR: ''}
221
+ desired = { aborted: false, STDERR: '' }
224
222
  desired[:STDOUT] =
225
223
  "Associate group '#{group_name}' with host(s) '#{host_names.join(',')}':\n"\
226
224
  " - retrieve group '#{group_name}'...\n"\
227
225
  " - OK\n"
228
226
  host_names.each do |host|
229
- desired[:STDOUT] = desired[:STDOUT] +
230
- " - add association {group:#{group_name} <-> host:#{host}}...\n"\
231
- " - OK\n"\
232
- " - remove automatic association {group:ungrouped <-> host:#{host}}...\n"\
233
- " - OK\n"\
234
-
235
- #desired[:STDERR] = desired[:STDERR] +
236
- # "WARNING: Host '#{host}' does not exist and will be created.\n"
227
+ desired[:STDOUT] = desired[:STDOUT] +
228
+ " - add association {group:#{group_name} <-> host:#{host}}...\n"\
229
+ " - OK\n"\
230
+ " - remove automatic association {group:ungrouped <-> host:#{host}}...\n"\
231
+ " - OK\n"\
232
+
233
+ # desired[:STDERR] = desired[:STDERR] +
234
+ # "WARNING: Host '#{host}' does not exist and will be created.\n"
237
235
  end
238
- desired[:STDOUT] = desired[:STDOUT] +
239
- " - all OK\n"\
240
- "Succeeded.\n"
236
+ desired[:STDOUT] = desired[:STDOUT] +
237
+ " - all OK\n"\
238
+ "Succeeded.\n"
241
239
  expected(actual, desired)
242
-
243
240
 
244
241
  # We should have group associations
245
242
  group = @db.models[:group].find(name: group_name)
@@ -9,7 +9,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
9
9
  @mockarg_parts = {
10
10
  config: File.join(spec_root, 'config/config.yml'),
11
11
  format: 'yaml',
12
- env: 'test'
12
+ env: 'test',
13
13
  }
14
14
 
15
15
  @mockargs = []
@@ -40,96 +40,96 @@ RSpec.describe Moose::Inventory::Cli::Group do
40
40
  result = @group.instance_methods(false).include?(:addvar)
41
41
  expect(result).to eq(true)
42
42
  end
43
-
43
+
44
44
  #-----------------
45
45
  it '<missing args> ... should abort with an error' do
46
46
  actual = runner do
47
47
  @app.start(%w(group addvar)) # <- no group given
48
48
  end
49
49
  # @console.out(actual, 'y')
50
-
50
+
51
51
  # Check output
52
- desired = { aborted: true}
52
+ desired = { aborted: true }
53
53
  desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 2 or more.\n"
54
54
  expected(actual, desired)
55
55
  end
56
56
 
57
57
  #------------------------
58
58
  it 'GROUP key=value ... should abort if the group does not exist' do
59
- group_name ='not-a-group'
60
- group_var = "foo=bar"
61
-
59
+ group_name = 'not-a-group'
60
+ group_var = 'foo=bar'
61
+
62
62
  actual = runner do
63
63
  @app.start(%W(group addvar #{group_name} #{group_var}))
64
64
  end
65
65
 
66
66
  # Check output
67
- desired = { aborted: true}
68
- desired[:STDOUT] =
67
+ desired = { aborted: true }
68
+ desired[:STDOUT] =
69
69
  "Add variables '#{group_var}' to group '#{group_name}':\n"\
70
70
  " - retrieve group '#{group_name}'...\n"
71
- desired[:STDERR] =
71
+ desired[:STDERR] =
72
72
  "An error occurred during a transaction, any changes have been rolled back.\n"\
73
73
  "ERROR: The group '#{group_name}' does not exist.\n"
74
74
  expected(actual, desired)
75
75
  end
76
76
 
77
77
  #------------------------
78
- it 'GROUP <malformed> ... should abort with an error' do
79
- # 1. Should add the var to the db
80
- # 2. Should associate the host with the var
81
-
82
- group_name = 'test_group'
83
- @db.models[:group].create(name: group_name)
84
-
85
- var = {name: 'var1', value: "testval"}
86
- cases = %W(
87
- testvar
88
- testvar=
89
- =testval
90
- testvar=testval=
91
- =testvar=testval
92
- testvar=testval=extra
93
- )
94
-
95
- cases.each do |args|
96
- actual = runner do
97
- @app.start(%W(group addvar #{group_name} #{args} ))
98
- end
99
- #@console.out(actual,'p')
100
-
101
- desired = { aborted: true}
102
- desired[:STDOUT] =
103
- "Add variables '#{args}' to group '#{group_name}':\n"\
104
- " - retrieve group '#{group_name}'...\n"\
105
- " - OK\n"\
106
- " - add variable '#{args}'...\n"
107
-
108
- desired[:STDERR] =
109
- "An error occurred during a transaction, any changes have been rolled back.\n"\
110
- "ERROR: Incorrect format in '{#{args}}'. Expected 'key=value'.\n"
111
-
112
- expected(actual, desired)
113
- end
114
- end
115
-
78
+ it 'GROUP <malformed> ... should abort with an error' do
79
+ # 1. Should add the var to the db
80
+ # 2. Should associate the host with the var
81
+
82
+ group_name = 'test_group'
83
+ @db.models[:group].create(name: group_name)
84
+
85
+ var = { name: 'var1', value: 'testval' }
86
+ cases = %w(
87
+ testvar
88
+ testvar=
89
+ =testval
90
+ testvar=testval=
91
+ =testvar=testval
92
+ testvar=testval=extra
93
+ )
94
+
95
+ cases.each do |args|
96
+ actual = runner do
97
+ @app.start(%W(group addvar #{group_name} #{args}))
98
+ end
99
+ # @console.out(actual,'p')
100
+
101
+ desired = { aborted: true }
102
+ desired[:STDOUT] =
103
+ "Add variables '#{args}' to group '#{group_name}':\n"\
104
+ " - retrieve group '#{group_name}'...\n"\
105
+ " - OK\n"\
106
+ " - add variable '#{args}'...\n"
107
+
108
+ desired[:STDERR] =
109
+ "An error occurred during a transaction, any changes have been rolled back.\n"\
110
+ "ERROR: Incorrect format in '{#{args}}'. Expected 'key=value'.\n"
111
+
112
+ expected(actual, desired)
113
+ end
114
+ end
115
+
116
116
  #------------------------
117
117
  it 'GROUP key=value ... should associate the group with the key/value pair' do
118
118
  # 1. Should add the var to the db
119
119
  # 2. Should associate the host with the var
120
-
120
+
121
121
  group_name = 'test1'
122
- var = {name: 'var1', value: "testval"}
122
+ var = { name: 'var1', value: 'testval' }
123
123
 
124
124
  @db.models[:group].create(name: group_name)
125
-
125
+
126
126
  actual = runner do
127
- @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]} ))
127
+ @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}))
128
128
  end
129
- #@console.out(actual,'p')
130
-
131
- desired = { aborted: false}
132
- desired[:STDOUT] =
129
+ # @console.out(actual,'p')
130
+
131
+ desired = { aborted: false }
132
+ desired[:STDOUT] =
133
133
  "Add variables '#{var[:name]}=#{var[:value]}' to group '#{group_name}':\n"\
134
134
  " - retrieve group '#{group_name}'...\n"\
135
135
  " - OK\n"\
@@ -146,71 +146,71 @@ RSpec.describe Moose::Inventory::Cli::Group do
146
146
  expect(groupvars[name: var[:name]]).not_to be_nil
147
147
  expect(groupvars[name: var[:name]][:value]).to eq(var[:value])
148
148
  end
149
-
149
+
150
150
  #------------------------
151
151
  it 'GROUP key1=value1 key2=value2 ... should associate the group with multiple key/value pairs' do
152
152
  # 1. Should add the var to the db
153
153
  # 2. Should associate the host with the var
154
-
154
+
155
155
  group_name = 'test1'
156
156
  varsarray = [
157
- {name: 'var1', value: "val1"},
158
- {name: 'var2', value: "val2"}
157
+ { name: 'var1', value: 'val1' },
158
+ { name: 'var2', value: 'val2' },
159
159
  ]
160
-
160
+
161
161
  vars = []
162
162
  varsarray.each do |var|
163
163
  vars << "#{var[:name]}=#{var[:value]}"
164
164
  end
165
-
165
+
166
166
  @db.models[:group].create(name: group_name)
167
-
167
+
168
168
  actual = runner do
169
- @app.start(%W(group addvar #{group_name}) + vars )
169
+ @app.start(%W(group addvar #{group_name}) + vars)
170
170
  end
171
-
172
- #@console.out(actual,'y')
173
-
174
- desired = { aborted: false}
175
- desired[:STDOUT] =
171
+
172
+ # @console.out(actual,'y')
173
+
174
+ desired = { aborted: false }
175
+ desired[:STDOUT] =
176
176
  "Add variables '#{vars.join(',')}' to group '#{group_name}':\n"\
177
177
  " - retrieve group '#{group_name}'...\n"\
178
178
  " - OK\n"
179
179
  vars.each do |var|
180
- desired[:STDOUT] = desired[:STDOUT] +
181
- " - add variable '#{var}'...\n"\
182
- " - OK\n"
180
+ desired[:STDOUT] = desired[:STDOUT] +
181
+ " - add variable '#{var}'...\n"\
182
+ " - OK\n"
183
183
  end
184
- desired[:STDOUT] = desired[:STDOUT] +
185
- " - all OK\n"\
186
- "Succeeded.\n"
184
+ desired[:STDOUT] = desired[:STDOUT] +
185
+ " - all OK\n"\
186
+ "Succeeded.\n"
187
187
  expected(actual, desired)
188
-
188
+
189
189
  # We should have the correct hostvar associations
190
190
  group = @db.models[:group].find(name: group_name)
191
191
  groupvars = group.groupvars_dataset
192
192
  expect(vars.count).to eq(vars.length)
193
- end
193
+ end
194
194
 
195
195
  #------------------------
196
196
  it 'GROUP key=value ... should update an already existing association' do
197
197
  # 1. Should add the var to the db
198
198
  # 2. Should associate the host with the var
199
-
199
+
200
200
  group_name = 'test1'
201
- var = {name: 'var1', value: "testval"}
202
-
201
+ var = { name: 'var1', value: 'testval' }
202
+
203
203
  @db.models[:group].create(name: group_name)
204
- runner { @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]} )) }
205
-
206
- var[:value] = "newtestval"
204
+ runner { @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]})) }
205
+
206
+ var[:value] = 'newtestval'
207
207
  actual = runner do
208
- @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]} ))
208
+ @app.start(%W(group addvar #{group_name} #{var[:name]}=#{var[:value]}))
209
209
  end
210
- #@console.out(actual,'y')
211
-
212
- desired = { aborted: false}
213
- desired[:STDOUT] =
210
+ # @console.out(actual,'y')
211
+
212
+ desired = { aborted: false }
213
+ desired[:STDOUT] =
214
214
  "Add variables '#{var[:name]}=#{var[:value]}' to group '#{group_name}':\n"\
215
215
  " - retrieve group '#{group_name}'...\n"\
216
216
  " - OK\n"\
@@ -220,16 +220,16 @@ RSpec.describe Moose::Inventory::Cli::Group do
220
220
  " - all OK\n"\
221
221
  "Succeeded.\n"
222
222
  expected(actual, desired)
223
-
223
+
224
224
  # We should have the correct hostvar associations
225
225
  group = @db.models[:group].find(name: group_name)
226
226
  groupvars = group.groupvars_dataset
227
227
  expect(groupvars.count).to eq(1)
228
228
  expect(groupvars[name: var[:name]]).not_to be_nil
229
229
  expect(groupvars[name: var[:name]][:value]).to eq(var[:value])
230
-
230
+
231
231
  groupvars = @db.models[:groupvar].all
232
- expect(groupvars.count).to eq(1)
232
+ expect(groupvars.count).to eq(1)
233
233
  end
234
234
  end
235
235
  end
@@ -9,7 +9,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
9
9
  @mockarg_parts = {
10
10
  config: File.join(spec_root, 'config/config.yml'),
11
11
  format: 'yaml',
12
- env: 'test'
12
+ env: 'test',
13
13
  }
14
14
 
15
15
  @mockargs = []
@@ -21,7 +21,7 @@ RSpec.describe Moose::Inventory::Cli::Group do
21
21
  @config = Moose::Inventory::Config
22
22
  @config.init(@mockargs)
23
23
  @console = Moose::Inventory::Cli::Formatter
24
-
24
+
25
25
  @db = Moose::Inventory::DB
26
26
  @db.init if @db.db.nil?
27
27
 
@@ -43,23 +43,23 @@ RSpec.describe Moose::Inventory::Cli::Group do
43
43
 
44
44
  #---------------------
45
45
  it '<missing args> ... should abort with an error' do
46
- actual = runner { @app.start(%W(group get)) }
46
+ actual = runner { @app.start(%w(group get)) }
47
+
48
+ # @console.out(actual,'y')
47
49
 
48
- #@console.out(actual,'y')
49
-
50
- desired = {aborted: true}
50
+ desired = { aborted: true }
51
51
  desired[:STDERR] = "ERROR: Wrong number of arguments, 0 for 1 or more\n"
52
52
 
53
53
  expected(actual, desired)
54
54
  end
55
-
55
+
56
56
  #---------------------
57
57
  it "GROUP ... should return an empty set when GROUP doesn't exist" do
58
58
  group_name = 'does-not-exist'
59
- actual = runner { @app.start(%W(group get #{ group_name })) }
59
+ actual = runner { @app.start(%W(group get #{group_name})) }
60
+
61
+ # @console.out(actual, 'y')
60
62
 
61
- #@console.out(actual, 'y')
62
-
63
63
  desired = {}
64
64
  desired[:STDOUT] = {}.to_yaml
65
65
 
@@ -69,14 +69,14 @@ RSpec.describe Moose::Inventory::Cli::Group do
69
69
  #---------------------
70
70
  it 'GROUP ... should get a group from the db' do
71
71
  name = 'test_group'
72
- runner { @app.start(%W(group add #{ name })) }
72
+ runner { @app.start(%W(group add #{name})) }
73
73
 
74
- actual = runner { @app.start(%W(group get #{ name })) }
74
+ actual = runner { @app.start(%W(group get #{name})) }
75
75
 
76
76
  mock = {}
77
77
  mock[name.to_sym] = {}
78
- # mock[name.to_sym][:hosts] = [] # TODO: Should this be present or not?
79
-
78
+ # mock[name.to_sym][:hosts] = [] # TODO: Should this be present or not?
79
+
80
80
  desired = { aborted: false, STDOUT: '', STDERR: '' }
81
81
  desired[:STDOUT] = mock.to_yaml
82
82
 
@@ -87,21 +87,20 @@ RSpec.describe Moose::Inventory::Cli::Group do
87
87
  it 'GROUP ... should display groupvars, if any are set' do
88
88
  name = 'test_group'
89
89
  var = 'foo=bar'
90
- tmp = runner { @app.start(%W(group add #{ name })) }
91
- tmp = runner { @app.start(%W(group addvar #{ name } #{ var })) }
90
+ tmp = runner { @app.start(%W(group add #{name})) }
91
+ tmp = runner { @app.start(%W(group addvar #{name} #{var})) }
92
+
93
+ actual = runner { @app.start(%W(group get #{name})) }
94
+ # @console.out(actual, 'y')
92
95
 
93
- actual = runner { @app.start(%W(group get #{ name })) }
94
- #@console.out(actual, 'y')
95
-
96
96
  mock = {}
97
97
  mock[name.to_sym] = {}
98
- mock[name.to_sym][:groupvars] = {foo: 'bar'}
99
-
98
+ mock[name.to_sym][:groupvars] = { foo: 'bar' }
99
+
100
100
  desired = {}
101
101
  desired[:STDOUT] = mock.to_yaml
102
-
102
+
103
103
  expected(actual, desired)
104
104
  end
105
-
106
105
  end
107
106
  end