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, #setup, #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



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

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



212
213
214
215
216
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 212

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



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 199

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



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

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



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

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



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

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



245
246
247
248
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 245

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



250
251
252
253
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 250

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



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

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



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

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



233
234
235
236
237
238
239
240
241
242
243
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 233

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"
  %w{
    inspec-core
    inspec-multi-server
  }.each do |plugin_name|
    refute_includes result.stdout, plugin_name, "Search result should not contain excluded gems"
  end
end