Class: PluginManagerCliSearch

Inherits:
MiniTest::Test
  • Object
show all
Includes:
CorePluginFunctionalHelper, PluginManagerHelpers
Defined in:
lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb

Overview

—————————————————————————————–#

inspec plugin search

—————————————————————————————–#

Constant Summary

Constants included from CorePluginFunctionalHelper

CorePluginFunctionalHelper::TRAIN_CONNECTION

Instance Method Summary collapse

Methods included from PluginManagerHelpers

#clear_empty_config_dir, #copy_in_core_config_dir, #copy_in_project_config_dir, #teardown

Methods included from CorePluginFunctionalHelper

#__find_plugin_path_from_caller, #__make_empty_plugin_file_data_structure, #__make_plugin_file_data_structure_with_path, #run_inspec_process, #run_inspec_process_with_this_plugin

Instance Method Details

#test_search_for_a_gem_that_does_not_existObject



209
210
211
212
213
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 209

def test_search_for_a_gem_that_does_not_exist
  result = run_inspec_process('plugin search --include-test-fixture inspec-test-fixture-nonesuch')
  assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'
  assert_includes result.stdout, '0 plugin(s) found', 'Search result should find 0 plugins'
end

#test_search_for_a_gem_with_missing_prefixObject



203
204
205
206
207
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 203

def test_search_for_a_gem_with_missing_prefix
  result = run_inspec_process('plugin search --include-test-fixture test-fixture')
  assert_equal 1, result.exit_status, 'Search should exit 1 on user error'
  assert_includes result.stdout, "All inspec plugins must begin with either 'inspec-' or 'train-'"
end

#test_search_for_a_real_gem_with_full_name_and_all_optionObject



190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 190

def test_search_for_a_real_gem_with_full_name_and_all_option
  result = run_inspec_process('plugin search --all --include-test-fixture inspec-test-fixture')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
  assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
  assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'

  line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
  assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+(,\s)?){2,}\)/,line,'Plugin line should include name and at least two versions')

  result = run_inspec_process('plugin search -a --include-test-fixture inspec-test-fixture')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
end

#test_search_for_a_real_gem_with_full_name_and_exact_optionObject



171
172
173
174
175
176
177
178
179
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 171

def test_search_for_a_real_gem_with_full_name_and_exact_option
  result = run_inspec_process('plugin search --exact --include-test-fixture inspec-test-fixture')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
  assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
  assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'

  result = run_inspec_process('plugin search -e --include-test-fixture inspec-test-fixture')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
end

#test_search_for_a_real_gem_with_full_name_no_optionsObject

TODO: Thor can’t hide options, but we wish it could. def test_search_include_fixture_hidden_option

result = run_inspec_process_with_this_plugin('plugin help search')
refute_includes result.stdout, '--include-test-fixture'

end



152
153
154
155
156
157
158
159
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 152

def test_search_for_a_real_gem_with_full_name_no_options
  result = run_inspec_process('plugin search --include-test-fixture inspec-test-fixture')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
  assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
  assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
  line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
  assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')
end

#test_search_for_a_real_gem_with_full_name_no_options_and_train_nameObject



215
216
217
218
219
220
221
222
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 215

def test_search_for_a_real_gem_with_full_name_no_options_and_train_name
  result = run_inspec_process('plugin search --include-test-fixture train-test-fixture')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
  assert_includes result.stdout, 'train-test-fixture', 'Search result should contain the gem name'
  assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'
  line = result.stdout.split("\n").grep(/train-test-fixture/).first
  assert_match(/\s*train-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')
end

#test_search_for_a_real_gem_with_full_name_no_options_filter_fixturesObject



235
236
237
238
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 235

def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures
  result = run_inspec_process('plugin search inspec-test-fixture')
  refute_includes result.stdout, 'inspec-test-fixture', 'Search result should not contain the fixture gem name'
end

#test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures_trainObject



240
241
242
243
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 240

def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures_train
  result = run_inspec_process('plugin search train-test-fixture')
  refute_includes result.stdout, 'train-test-fixture', 'Search result should not contain the fixture gem name'
end

#test_search_for_a_real_gem_with_stub_name_and_exact_optionObject



181
182
183
184
185
186
187
188
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 181

def test_search_for_a_real_gem_with_stub_name_and_exact_option
  result = run_inspec_process('plugin search --exact --include-test-fixture inspec-test-')
  assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'
  assert_includes result.stdout, '0 plugin(s) found', 'Search result should find 0 plugins'

  result = run_inspec_process('plugin search -e --include-test-fixture inspec-test-')
  assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'
end

#test_search_for_a_real_gem_with_stub_name_no_optionsObject



161
162
163
164
165
166
167
168
169
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 161

def test_search_for_a_real_gem_with_stub_name_no_options
  result = run_inspec_process('plugin search --include-test-fixture inspec-test-')
  assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'
  assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'
  assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'

  line = result.stdout.split("\n").grep(/inspec-test-fixture/).first
  assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')
end

#test_search_omit_excluded_inspec_pluginsObject



224
225
226
227
228
229
230
231
232
233
234
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 224

def test_search_omit_excluded_inspec_plugins
  result = run_inspec_process('plugin search --include-test-fixture inspec-')
  assert_equal 0, result.exit_status, 'Search should exit 0'
  assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the test gem'
  [
    'inspec-core',
    'inspec-multi-server',
  ].each do |plugin_name|
    refute_includes result.stdout, plugin_name, 'Search result should not contain excluded gems'
  end
end