Best Inspec_ruby code snippet using PluginManagerHelpers.copy_in_core_config_dir
inspec-plugin_test.rb
Source:inspec-plugin_test.rb
...20 src = Dir.glob(File.join(project_config_dirs_path, fixture_name, '*'))21 dest ||= File.join(project_config_dirs_path, 'empty')22 src.each { |path| FileUtils.cp_r(path, dest) }23 end24 def copy_in_core_config_dir(fixture_name, dest = nil)25 src = Dir.glob(File.join(core_config_dir_path, fixture_name, '*'))26 dest ||= File.join(project_config_dirs_path, 'empty')27 src.each { |path| FileUtils.cp_r(path, dest) }28 end29 def clear_empty_config_dir30 Dir.glob(File.join(project_config_dirs_path, 'empty', '*')).each do |path|31 next if path.end_with? '.gitkeep'32 FileUtils.rm_rf(path)33 end34 end35 def teardown36 clear_empty_config_dir37 end38end39#-----------------------------------------------------------------------------------------#40# inspec help41#-----------------------------------------------------------------------------------------#42class PluginManagerCliHelp < MiniTest::Test43 include CorePluginFunctionalHelper44 # Main inspec help subcommand listing45 def test_inspec_help_includes_plugin46 result = run_inspec_process_with_this_plugin('help')47 assert_includes result.stdout, 'inspec plugin'48 end49 # inspec plugin help subcommand listing50 def test_inspec_plugin_help_includes_plugin51 result = run_inspec_process_with_this_plugin('plugin help')52 assert_includes result.stdout, 'inspec plugin list'53 assert_includes result.stdout, 'inspec plugin search'54 assert_includes result.stdout, 'inspec plugin install'55 assert_includes result.stdout, 'inspec plugin update'56 assert_includes result.stdout, 'inspec plugin uninstall'57 end58end59#-----------------------------------------------------------------------------------------#60# inspec plugin list61#-----------------------------------------------------------------------------------------#62class PluginManagerCliList < MiniTest::Test63 include CorePluginFunctionalHelper64 include PluginManagerHelpers65 def test_list_when_no_user_plugins_installed66 result = run_inspec_process_with_this_plugin('plugin list')67 assert_equal 0, result.exit_status, 'exist status must be 0'68 assert_includes result.stdout, '0 plugin(s) total', 'Empty list should include zero count'69 end70 def test_list_all_when_no_user_plugins_installed71 result = run_inspec_process_with_this_plugin('plugin list --all')72 assert_equal 0, result.exit_status, 'exist status must be 0'73 assert_includes result.stdout, '6 plugin(s) total', '--all list should find six'74 assert_includes result.stdout, 'inspec-plugin-manager-cli', '--all list should find inspec-plugin-manager-cli'75 assert_includes result.stdout, 'habitat', '--all list should find habitat'76 result = run_inspec_process_with_this_plugin('plugin list -a')77 assert_equal 0, result.exit_status, 'exist status must be 0'78 assert_includes result.stdout, '6 plugin(s) total', '-a list should find six'79 end80 def test_list_when_gem_and_path_plugins_installed81 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|82 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.83 copy_in_core_config_dir('test-fixture-1-float', tmp_dir)84 end85 result = run_inspec_process_with_this_plugin('plugin list', pre_run: pre_block)86 assert_equal 0, result.exit_status, 'exist status must be 0'87 assert_includes result.stdout, '2 plugin(s) total', 'gem+path should show two plugins'88 # Plugin Name Version Via ApiVer89 # -------------------------------------------------------90 # inspec-meaning-of-life src path 291 # inspec-test-fixture 0.1.0 gem 292 # -------------------------------------------------------93 # 2 plugin(s) total94 gem_line = result.stdout.split("\n").grep(/gem/).first95 assert_match(/\s*inspec-\S+\s+\d+\.\d+\.\d+\s+gem\s+2/, gem_line)96 path_line = result.stdout.split("\n").grep(/path/).first97 assert_match(/\s*inspec-\S+\s+src\s+path\s+2/, path_line)98 end99 def test_list_when_a_train_plugin_is_installed100 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|101 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.102 copy_in_core_config_dir('train-test-fixture', tmp_dir)103 end104 result = run_inspec_process_with_this_plugin('plugin list', pre_run: pre_block)105 assert_equal 0, result.exit_status, 'exist status must be 0'106 assert_includes result.stdout, '1 plugin(s) total', 'list train should show one plugins'107 # Plugin Name Version Via ApiVer108 # -------------------------------------------------------109 # train-test-fixture 0.1.0 gem train-1110 # -------------------------------------------------------111 # 1 plugin(s) total112 train_line = result.stdout.split("\n").grep(/train/).first113 assert_includes(train_line, 'train-test-fixture')114 assert_includes(train_line, '0.1.0')115 assert_includes(train_line, 'gem')116 assert_includes(train_line, 'train-1')117 end118end119#-----------------------------------------------------------------------------------------#120# inspec plugin search121#-----------------------------------------------------------------------------------------#122class PluginManagerCliSearch < MiniTest::Test123 include CorePluginFunctionalHelper124 include PluginManagerHelpers125 # TODO: Thor can't hide options, but we wish it could.126 # def test_search_include_fixture_hidden_option127 # result = run_inspec_process_with_this_plugin('plugin help search')128 # refute_includes result.stdout, '--include-test-fixture'129 # end130 def test_search_for_a_real_gem_with_full_name_no_options131 result = run_inspec_process('plugin search --include-test-fixture inspec-test-fixture')132 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'133 assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'134 assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'135 line = result.stdout.split("\n").grep(/inspec-test-fixture/).first136 assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')137 end138 def test_search_for_a_real_gem_with_stub_name_no_options139 result = run_inspec_process('plugin search --include-test-fixture inspec-test-')140 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'141 assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'142 assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'143 line = result.stdout.split("\n").grep(/inspec-test-fixture/).first144 assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')145 end146 def test_search_for_a_real_gem_with_full_name_and_exact_option147 result = run_inspec_process('plugin search --exact --include-test-fixture inspec-test-fixture')148 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'149 assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'150 assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'151 result = run_inspec_process('plugin search -e --include-test-fixture inspec-test-fixture')152 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'153 end154 def test_search_for_a_real_gem_with_stub_name_and_exact_option155 result = run_inspec_process('plugin search --exact --include-test-fixture inspec-test-')156 assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'157 assert_includes result.stdout, '0 plugin(s) found', 'Search result should find 0 plugins'158 result = run_inspec_process('plugin search -e --include-test-fixture inspec-test-')159 assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'160 end161 def test_search_for_a_real_gem_with_full_name_and_all_option162 result = run_inspec_process('plugin search --all --include-test-fixture inspec-test-fixture')163 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'164 assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the gem name'165 assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'166 line = result.stdout.split("\n").grep(/inspec-test-fixture/).first167 assert_match(/\s*inspec-test-fixture\s+\((\d+\.\d+\.\d+(,\s)?){2,}\)/,line,'Plugin line should include name and at least two versions')168 result = run_inspec_process('plugin search -a --include-test-fixture inspec-test-fixture')169 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'170 end171 def test_search_for_a_gem_with_missing_prefix172 result = run_inspec_process('plugin search --include-test-fixture test-fixture')173 assert_equal 1, result.exit_status, 'Search should exit 1 on user error'174 assert_includes result.stdout, "All inspec plugins must begin with either 'inspec-' or 'train-'"175 end176 def test_search_for_a_gem_that_does_not_exist177 result = run_inspec_process('plugin search --include-test-fixture inspec-test-fixture-nonesuch')178 assert_equal 2, result.exit_status, 'Search should exit 2 on a miss'179 assert_includes result.stdout, '0 plugin(s) found', 'Search result should find 0 plugins'180 end181 def test_search_for_a_real_gem_with_full_name_no_options_and_train_name182 result = run_inspec_process('plugin search --include-test-fixture train-test-fixture')183 assert_equal 0, result.exit_status, 'Search should exit 0 on a hit'184 assert_includes result.stdout, 'train-test-fixture', 'Search result should contain the gem name'185 assert_includes result.stdout, '1 plugin(s) found', 'Search result should find 1 plugin'186 line = result.stdout.split("\n").grep(/train-test-fixture/).first187 assert_match(/\s*train-test-fixture\s+\((\d+\.\d+\.\d+){1}\)/,line,'Plugin line should include name and exactly one version')188 end189 def test_search_omit_excluded_inspec_plugins190 result = run_inspec_process('plugin search --include-test-fixture inspec-')191 assert_equal 0, result.exit_status, 'Search should exit 0'192 assert_includes result.stdout, 'inspec-test-fixture', 'Search result should contain the test gem'193 [194 'inspec-core',195 'inspec-multi-server',196 ].each do |plugin_name|197 refute_includes result.stdout, plugin_name, 'Search result should not contain excluded gems'198 end199 end200 def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures201 result = run_inspec_process('plugin search inspec-test-fixture')202 refute_includes result.stdout, 'inspec-test-fixture', 'Search result should not contain the fixture gem name'203 end204 def test_search_for_a_real_gem_with_full_name_no_options_filter_fixtures_train205 result = run_inspec_process('plugin search train-test-fixture')206 refute_includes result.stdout, 'train-test-fixture', 'Search result should not contain the fixture gem name'207 end208end209#-----------------------------------------------------------------------------------------#210# inspec plugin install211#-----------------------------------------------------------------------------------------#212class PluginManagerCliInstall < MiniTest::Test213 include CorePluginFunctionalHelper # gives us instance methods, like `let` aliases inside test methods214 extend CorePluginFunctionalHelper # gives us class methods, like `let` aliases out here outside test methods215 include PluginManagerHelpers216 ruby_abi_version = (Gem.ruby_version.segments[0, 2] << 0).join('.')217 # Test multiple hueristics of the path-mode install.218 # These are all positive tests; they should resolve the entry point to the same path in each case.219 {220 'is_perfect' => {221 given: File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb'),222 },223 'refers_to_the_entry_point_with_no_extension' => {224 given: File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture'),225 },226 'refers_to_the_src_root_of_a_plugin' => {227 given: File.join(core_fixture_plugins_path, 'inspec-test-fixture'),228 },229 'refers_to_a_versioned_gem_install' => {230 given: File.join(core_config_dir_path, 'test-fixture-1-float', 'gems', ruby_abi_version, 'gems', 'inspec-test-fixture-0.1.0', 'lib', 'inspec-test-fixture.rb'),231 resolved_path: File.join(core_config_dir_path, 'test-fixture-1-float', 'gems', ruby_abi_version, 'gems', 'inspec-test-fixture-0.1.0', 'lib', 'inspec-test-fixture.rb'),232 },233 'refers_to_a_versioned_gem_install_missing_extension' => {234 given: File.join(core_config_dir_path, 'test-fixture-1-float', 'gems', ruby_abi_version, 'gems', 'inspec-test-fixture-0.1.0', 'lib', 'inspec-test-fixture'),235 resolved_path: File.join(core_config_dir_path, 'test-fixture-1-float', 'gems', ruby_abi_version, 'gems', 'inspec-test-fixture-0.1.0', 'lib', 'inspec-test-fixture.rb'),236 },237 'refers_to_a_relative_path' => {238 given: File.join('test', 'unit', 'mock', 'plugins', 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb'),239 },240 'refers_to_a_train_plugin' => {241 given: File.join(core_config_dir_path, 'train-test-fixture', 'gems', ruby_abi_version, 'gems', 'train-test-fixture-0.1.0', 'lib', 'train-test-fixture.rb'),242 plugin_name: 'train-test-fixture',243 resolved_path: File.join(core_config_dir_path, 'train-test-fixture', 'gems', ruby_abi_version, 'gems', 'train-test-fixture-0.1.0', 'lib', 'train-test-fixture.rb'),244 },245 }.each do |test_name, fixture_info|246 define_method(('test_install_from_path_when_path_' + test_name).to_sym) do247 fixture_info = {248 plugin_name: 'inspec-test-fixture',249 resolved_path: File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb')250 }.merge(fixture_info)251 install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_info[:given]}", post_run: list_after_run)252 assert_empty install_result.stderr253 assert_equal 0, install_result.exit_status, 'Exit status should be 0'254 # Check UX messaging255 success_message = install_result.stdout.split("\n").grep(/installed/).last256 refute_nil success_message, 'Should find a success message at the end'257 assert_includes success_message, fixture_info[:plugin_name]258 assert_includes success_message, 'plugin installed via source path reference'259 # Check round-trip UX via list260 list_result = install_result.payload.list_result261 itf_line = list_result.stdout.split("\n").grep(Regexp.new(fixture_info[:plugin_name])).first262 refute_nil itf_line, 'plugin name should now appear in the output of inspec list'263 assert_match(/\s*(inspec|train)-test-fixture\s+src\s+path\s+/, itf_line, 'list output should show that it is a path installation')264 # Check plugin statefile. Extra important in this case, since all should resolve to the same entry point.265 plugin_data = install_result.payload.plugin_data266 entry = plugin_data['plugins'].detect { |e| e['name'] == fixture_info[:plugin_name] }267 assert_equal fixture_info[:resolved_path], entry['installation_path'], 'Regardless of input, the entry point should be correct.'268 end269 end270 def test_fail_install_from_nonexistant_path271 bad_path = File.join(project_fixtures_path, 'none', 'such', 'inspec-test-fixture-nonesuch.rb')272 install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")273 assert_empty install_result.stderr274 assert_equal 1, install_result.exit_status, 'Exit status should be 1'275 error_message = install_result.stdout.split("\n").last276 assert_includes error_message, "No such source code path"277 assert_includes error_message, 'inspec-test-fixture-nonesuch.rb'278 assert_includes error_message, 'installation failed'279 end280 def test_fail_install_from_path_with_wrong_name281 bad_path = File.join(project_fixtures_path, 'plugins', 'wrong-name', 'lib', 'wrong-name.rb')282 install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")283 assert_empty install_result.stderr284 assert_equal 1, install_result.exit_status, 'Exit status should be 1'285 error_message = install_result.stdout.split("\n").last286 assert_includes error_message, "Invalid plugin name"287 assert_includes error_message, 'wrong-name'288 assert_includes error_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"289 assert_includes error_message, 'installation failed'290 end291 def test_fail_install_from_path_when_it_is_not_a_plugin292 bad_path = File.join(project_fixtures_path, 'plugins', 'inspec-egg-white-omelette', 'lib', 'inspec-egg-white-omelette.rb')293 install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")294 assert_empty install_result.stderr295 assert_equal 1, install_result.exit_status, 'Exit status should be 1'296 error_message = install_result.stdout.split("\n").last297 assert_includes error_message, "Does not appear to be a plugin"298 assert_includes error_message, 'inspec-egg-white-omelette'299 assert_includes error_message, "After probe-loading the supposed plugin, it did not register"300 assert_includes error_message, "Ensure something inherits from 'Inspec.plugin(2)'"301 assert_includes error_message, 'installation failed'302 end303 def test_fail_install_from_path_when_it_is_already_installed304 plugin_path = File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'lib', 'inspec-test-fixture.rb')305 pre_block = Proc.new do |plugin_data, _tmp_dir|306 plugin_data["plugins"] << {307 "name" => "inspec-test-fixture",308 "installation_type" => "path",309 "installation_path" => plugin_path,310 }311 end312 install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_path}", pre_run: pre_block)313 assert_empty install_result.stderr314 assert_equal 2, install_result.exit_status, 'Exit status on second install should be 2'315 error_message = install_result.stdout.split("\n").last316 assert_includes error_message, "Plugin already installed"317 assert_includes error_message, 'inspec-test-fixture'318 assert_includes error_message, "Use 'inspec plugin list' to see previously installed plugin"319 assert_includes error_message, 'installation failed'320 end321 def test_fail_install_from_path_when_the_dir_structure_is_wrong322 bad_path = File.join(project_fixtures_path, 'plugins', 'inspec-wrong-structure')323 install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")324 assert_empty install_result.stderr325 assert_equal 1, install_result.exit_status, 'Exit status should be 1'326 error_message = install_result.stdout.split("\n").last327 assert_includes error_message, "Unrecognizable plugin structure"328 assert_includes error_message, 'inspec-wrong-structure'329 assert_includes error_message, ' When installing from a path, please provide the path of the entry point file'330 assert_includes error_message, 'installation failed'331 end332 def test_install_from_gemfile333 fixture_gemfile_path = File.join(core_fixture_plugins_path, 'inspec-test-fixture', 'pkg', 'inspec-test-fixture-0.1.0.gem')334 install_result = run_inspec_process_with_this_plugin("plugin install #{fixture_gemfile_path}", post_run: list_after_run)335 assert_empty install_result.stderr336 assert_equal 0, install_result.exit_status, 'Exit status should be 0'337 success_message = install_result.stdout.split("\n").grep(/installed/).last338 refute_nil success_message, 'Should find a success message at the end'339 assert_includes success_message, 'inspec-test-fixture'340 assert_includes success_message, '0.1.0'341 assert_includes success_message, 'installed from local .gem file'342 list_result = install_result.payload.list_result343 itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first344 refute_nil itf_line, 'inspec-test-fixture should now appear in the output of inspec list'345 assert_match(/\s*inspec-test-fixture\s+0.1.0\s+gem\s+/, itf_line, 'list output should show that it is a gem installation with version')346 end347 def test_fail_install_from_nonexistant_gemfile348 bad_path = File.join(project_fixtures_path, 'none', 'such', 'inspec-test-fixture-nonesuch-0.3.0.gem')349 install_result = run_inspec_process_with_this_plugin("plugin install #{bad_path}")350 assert_empty install_result.stderr351 assert_equal 1, install_result.exit_status, 'Exit status should be 1'352 assert_match(/No such plugin gem file .+ - installation failed./, install_result.stdout)353 end354 def test_install_from_rubygems_latest355 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture', post_run: list_after_run)356 assert_empty install_result.stderr357 assert_equal 0, install_result.exit_status, 'Exit status should be 0'358 success_message = install_result.stdout.split("\n").grep(/installed/).last359 refute_nil success_message, 'Should find a success message at the end'360 assert_includes success_message, 'inspec-test-fixture'361 assert_includes success_message, '0.2.0'362 assert_includes success_message, 'installed from rubygems.org'363 list_result = install_result.payload.list_result364 itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first365 refute_nil itf_line, 'inspec-test-fixture should now appear in the output of inspec list'366 assert_match(/\s*inspec-test-fixture\s+0.2.0\s+gem\s+/, itf_line, 'list output should show that it is a gem installation with version')367 end368 def test_fail_install_from_nonexistant_remote_rubygem369 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture-nonesuch')370 assert_empty install_result.stderr371 assert_equal 1, install_result.exit_status, 'Exit status should be 1'372 assert_match(/No such plugin gem .+ could be found on rubygems.org - installation failed./, install_result.stdout)373 end374 def test_install_from_rubygems_with_pinned_version375 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture -v 0.1.0', post_run: list_after_run)376 assert_empty install_result.stderr377 assert_equal 0, install_result.exit_status, 'Exit status should be 0'378 success_message = install_result.stdout.split("\n").grep(/installed/).last379 refute_nil success_message, 'Should find a success message at the end'380 assert_includes success_message, 'inspec-test-fixture'381 assert_includes success_message, '0.1.0'382 assert_includes success_message, 'installed from rubygems.org'383 list_result = install_result.payload.list_result384 itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first385 refute_nil itf_line, 'inspec-test-fixture should now appear in the output of inspec list'386 assert_match(/\s*inspec-test-fixture\s+0.1.0\s+gem\s+/, itf_line, 'list output should show that it is a gem installation with version')387 end388 def test_fail_install_from_nonexistant_rubygem_version389 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture -v 99.99.99')390 assert_empty install_result.stderr391 assert_equal 1, install_result.exit_status, 'Exit status should be 1'392 fail_message = install_result.stdout.split("\n").grep(/failed/).last393 refute_nil fail_message, 'Should find a failure message at the end'394 assert_includes fail_message, 'inspec-test-fixture'395 assert_includes fail_message, '99.99.99'396 assert_includes fail_message, 'no such version'397 assert_includes fail_message, 'on rubygems.org'398 end399 def test_refuse_install_when_missing_prefix400 install_result = run_inspec_process_with_this_plugin('plugin install test-fixture')401 assert_empty install_result.stderr402 assert_equal 1, install_result.exit_status, 'Exit status should be 1'403 fail_message = install_result.stdout.split("\n").grep(/failed/).last404 refute_nil fail_message, 'Should find a failure message at the end'405 assert_includes fail_message, 'test-fixture'406 assert_includes fail_message, "All inspec plugins must begin with either 'inspec-' or 'train-'"407 end408 def test_refuse_install_when_already_installed_same_version409 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|410 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.411 copy_in_core_config_dir('test-fixture-2-float', tmp_dir)412 end413 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture', pre_run: pre_block)414 assert_empty install_result.stderr415 assert_equal 2, install_result.exit_status, 'Exit status should be 2'416 refusal_message = install_result.stdout.split("\n").grep(/refusing/).last417 refute_nil refusal_message, 'Should find a failure message at the end'418 assert_includes refusal_message, 'inspec-test-fixture'419 assert_includes refusal_message, '0.2.0'420 assert_includes refusal_message, 'Plugin already installed at latest version'421 end422 def test_refuse_install_when_already_installed_can_update423 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|424 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.425 copy_in_core_config_dir('test-fixture-1-float', tmp_dir)426 end427 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture', pre_run: pre_block)428 assert_empty install_result.stderr429 assert_equal 2, install_result.exit_status, 'Exit status should be 2'430 refusal_message = install_result.stdout.split("\n").grep(/refusing/).last431 refute_nil refusal_message, 'Should find a failure message at the end'432 assert_includes refusal_message, 'inspec-test-fixture'433 assert_includes refusal_message, '0.1.0'434 assert_includes refusal_message, '0.2.0'435 assert_includes refusal_message, 'Update required'436 assert_includes refusal_message, 'inspec plugin update'437 end438 def test_install_from_rubygems_latest_with_train_plugin439 install_result = run_inspec_process_with_this_plugin('plugin install train-test-fixture', post_run: list_after_run)440 assert_empty install_result.stderr441 assert_equal 0, install_result.exit_status, 'Exit status should be 0'442 success_message = install_result.stdout.split("\n").grep(/installed/).last443 refute_nil success_message, 'Should find a success message at the end'444 assert_includes success_message, 'train-test-fixture'445 assert_includes success_message, '0.1.0'446 assert_includes success_message, 'installed from rubygems.org'447 list_result = install_result.payload.list_result448 itf_line = list_result.stdout.split("\n").grep(/train-test-fixture/).first449 refute_nil itf_line, 'train-test-fixture should now appear in the output of inspec list'450 assert_match(/\s*train-test-fixture\s+0.1.0\s+gem\s+/, itf_line, 'list output should show that it is a gem installation with version')451 end452 def test_refuse_install_when_plugin_on_exclusion_list453 # Here, 'inspec-core', 'inspec-multi-server', and 'train-tax-collector'454 # are the names of real rubygems. They are not InSpec/Train plugins, though,455 # and installing them would be a jam-up.456 # This is configured in 'etc/plugin-filter.json'.457 [458 'inspec-core',459 'inspec-multi-server',460 'train-tax-calculator',461 ].each do |plugin_name|462 install_result = run_inspec_process_with_this_plugin("plugin install #{plugin_name}")463 assert_empty install_result.stderr464 assert_equal 2, install_result.exit_status, 'Exit status should be 2'465 refusal_message = install_result.stdout466 refute_nil refusal_message, 'Should find a failure message at the end'467 assert_includes refusal_message, plugin_name468 assert_includes refusal_message, 'Plugin on Exclusion List'469 assert_includes refusal_message, 'refusing to install'470 assert_includes refusal_message, 'Rationale:'471 assert_includes refusal_message, 'etc/plugin_filters.json'472 assert_includes refusal_message, 'github.com/inspec/inspec/issues/new'473 end474 end475 def test_error_install_with_debug_enabled476 install_result = run_inspec_process_with_this_plugin('plugin install inspec-test-fixture -v 0.1.1 --log-level debug')477 assert_equal 1, install_result.exit_status, 'Exit status should be 1'478 assert_includes install_result.stdout, 'DEBUG'479 assert_includes install_result.stderr, "can't activate rake"480 end481end482#-----------------------------------------------------------------------------------------#483# inspec plugin update484#-----------------------------------------------------------------------------------------#485class PluginManagerCliUpdate < MiniTest::Test486 include CorePluginFunctionalHelper487 include PluginManagerHelpers488 def test_when_a_plugin_can_be_updated489 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|490 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.491 copy_in_core_config_dir('test-fixture-1-float', tmp_dir)492 end493 update_result = run_inspec_process_with_this_plugin('plugin update inspec-test-fixture', pre_run: pre_block, post_run: list_after_run)494 assert_empty update_result.stderr495 assert_equal 0, update_result.exit_status, 'Exit status should be 0'496 success_message = update_result.stdout.split("\n").grep(/updated/).last497 refute_nil success_message, 'Should find a success message at the end'498 assert_includes success_message, 'inspec-test-fixture'499 assert_includes success_message, '0.1.0'500 assert_includes success_message, '0.2.0'501 assert_includes success_message, 'updated from rubygems.org'502 list_result = update_result.payload.list_result503 itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first504 refute_nil itf_line, 'inspec-test-fixture should appear in the output of inspec list'505 assert_match(/\s*inspec-test-fixture\s+0.2.0\s+gem\s+/, itf_line, 'list output should show that it is a gem installation with version 0.2.0')506 end507 def test_refuse_update_when_already_current508 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|509 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.510 copy_in_core_config_dir('test-fixture-2-float', tmp_dir)511 end512 update_result = run_inspec_process_with_this_plugin('plugin update inspec-test-fixture', pre_run: pre_block)513 assert_empty update_result.stderr514 assert_equal 2, update_result.exit_status, 'Exit status should be 2'515 refusal_message = update_result.stdout.split("\n").grep(/refusing/).last516 refute_nil refusal_message, 'Should find a failure message at the end'517 assert_includes refusal_message, 'inspec-test-fixture'518 assert_includes refusal_message, '0.2.0'519 assert_includes refusal_message, 'Already installed at latest version'520 end521 def test_fail_update_from_nonexistant_gem522 update_result = run_inspec_process_with_this_plugin('plugin update inspec-test-fixture-nonesuch')523 assert_empty update_result.stderr524 assert_equal 1, update_result.exit_status, 'Exit status should be 1'525 assert_match(/No such plugin installed: .+ - update failed/, update_result.stdout)526 end527 def test_fail_update_path528 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|529 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.530 copy_in_core_config_dir('meaning_by_path', tmp_dir)531 end532 update_result = run_inspec_process_with_this_plugin('plugin update inspec-meaning-of-life', pre_run: pre_block)533 assert_empty update_result.stderr534 assert_equal 2, update_result.exit_status, 'Exit status should be 2'535 refusal_message = update_result.stdout.split("\n").grep(/refusing/).last536 refute_nil refusal_message, 'Should find a failure message at the end'537 assert_includes refusal_message, 'inspec-meaning-of-life'538 assert_includes refusal_message, 'inspec plugin uninstall'539 assert_includes refusal_message, 'Cannot update path-based install'540 end541end542#-----------------------------------------------------------------------------------------#543# inspec plugin uninstall544#-----------------------------------------------------------------------------------------#545class PluginManagerCliUninstall < MiniTest::Test546 include CorePluginFunctionalHelper547 include PluginManagerHelpers548 def test_when_a_gem_plugin_can_be_uninstalled549 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|550 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.551 copy_in_core_config_dir('test-fixture-1-float', tmp_dir)552 end553 # Attempt uninstall554 uninstall_result = run_inspec_process_with_this_plugin('plugin uninstall inspec-test-fixture', pre_run: pre_block, post_run: list_after_run)555 assert_empty uninstall_result.stderr556 assert_equal 0, uninstall_result.exit_status, 'Exit status should be 0'557 success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last558 refute_nil success_message, 'Should find a success message at the end'559 assert_includes success_message, 'inspec-test-fixture'560 assert_includes success_message, '0.1.0'561 assert_includes success_message, 'has been uninstalled'562 list_result = uninstall_result.payload.list_result563 itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first564 assert_nil itf_line, 'inspec-test-fixture should not appear in the output of inspec list'565 end566 def test_when_a_path_plugin_can_be_uninstalled567 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|568 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.569 # This fixture includes a path install for inspec-meaning-of-life570 copy_in_core_config_dir('test-fixture-1-float', tmp_dir)571 end572 uninstall_result = run_inspec_process_with_this_plugin('plugin uninstall inspec-meaning-of-life', pre_run: pre_block, post_run: list_after_run)573 assert_empty uninstall_result.stderr574 assert_equal 0, uninstall_result.exit_status, 'Exit status should be 0'575 success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last576 refute_nil success_message, 'Should find a success message at the end'577 assert_includes success_message, 'inspec-meaning-of-life'578 assert_includes success_message, 'path-based plugin install'579 assert_includes success_message, 'has been uninstalled'580 list_result = uninstall_result.payload.list_result581 itf_line = list_result.stdout.split("\n").grep(/inspec-meaning-of-life/).first582 assert_nil itf_line, 'inspec-meaning-of-life should not appear in the output of inspec list'583 end584 def test_fail_uninstall_from_plugin_that_is_not_installed...
update_test.rb
Source:update_test.rb
...5 def test_when_a_plugin_can_be_updated6 skip "this test requires bundler to pass" unless defined? ::Bundler7 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|8 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.9 copy_in_core_config_dir("test-fixture-1-float", tmp_dir)10 end11 update_result = run_inspec_process_with_this_plugin("plugin update inspec-test-fixture", pre_run: pre_block, post_run: list_after_run)12 success_message = update_result.stdout.split("\n").grep(/updated/).last13 skip_windows!14 refute_nil success_message, "Should find a success message at the end"15 assert_includes success_message, "inspec-test-fixture"16 assert_includes success_message, "0.1.0"17 assert_includes success_message, "0.2.0"18 assert_includes success_message, "updated from rubygems.org"19 itf_plugin = update_result.payload.list_result.detect { |p| p[:name] == "inspec-test-fixture" }20 refute_nil itf_plugin, "plugin name should now appear in the output of inspec list"21 assert_equal "gem (user)", itf_plugin[:type]22 assert_equal "0.2.0", itf_plugin[:version]23 assert_empty update_result.stderr24 assert_exit_code 0, update_result25 end26 def test_refuse_update_when_already_current27 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|28 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.29 copy_in_core_config_dir("test-fixture-2-float", tmp_dir)30 end31 update_result = run_inspec_process_with_this_plugin("plugin update inspec-test-fixture", pre_run: pre_block)32 refusal_message = update_result.stdout.split("\n").grep(/refusing/).last33 skip_windows!34 refute_nil refusal_message, "Should find a failure message at the end"35 assert_includes refusal_message, "inspec-test-fixture"36 assert_includes refusal_message, "0.2.0"37 assert_includes refusal_message, "Already installed at latest version"38 assert_empty update_result.stderr39 assert_exit_code 2, update_result40 end41 def test_fail_update_from_nonexistant_gem42 update_result = run_inspec_process_with_this_plugin("plugin update inspec-test-fixture-nonesuch")43 skip_windows!44 assert_match(/No such plugin installed:.+ - update failed/, update_result.stdout)45 assert_empty update_result.stderr46 assert_exit_code 1, update_result47 end48 def test_fail_update_path49 pre_block = Proc.new do |plugin_statefile_data, tmp_dir|50 plugin_statefile_data.clear # Signal not to write a file, we'll provide one.51 copy_in_core_config_dir("meaning_by_path", tmp_dir)52 end53 update_result = run_inspec_process_with_this_plugin("plugin update inspec-meaning-of-life", pre_run: pre_block)54 refusal_message = update_result.stdout.split("\n").grep(/refusing/).last55 skip_windows!56 refute_nil refusal_message, "Should find a failure message at the end"57 assert_includes refusal_message, "inspec-meaning-of-life"58 assert_includes refusal_message, "inspec plugin uninstall"59 assert_includes refusal_message, "Cannot update path-based install"60 assert_empty update_result.stderr61 assert_exit_code 2, update_result62 end63end...
copy_in_core_config_dir
Using AI Code Generation
1 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)2 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)3 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)4 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)5 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)
copy_in_core_config_dir
Using AI Code Generation
1 def copy_in_core_config_dir(plugin_name)2 FileUtils.cp_r(File.join(File.dirname(__FILE__), "config"), File.join(File.dirname(__FILE__), "vendor", plugin_name))3 def copy_in_core_config_dir(plugin_name)4 def copy_in_core_config_dir(plugin_name)5 def copy_in_core_config_dir(plugin_name)6 FileUtils.cp_r(File.join(File.dirname(__FILE__), "config"), File.join(File.dirname(__FILE__), "vendor", plugin_name))7 def copy_in_core_config_dir(plugin_name)8 FileUtils.cp_r(File.join(File.dirname(__FILE__), "config"), File.join(File.dirname(__FILE__), "vendor", plugin_name))
copy_in_core_config_dir
Using AI Code Generation
1 plugin_config_dir = File.join('config', 'plugins', @plugin_name)2 core_config_dir = File.join('config', 'core')3 core_config_files = Dir[File.join(core_config_dir, '*.yml')]4 plugin_config_file = File.join(plugin_config_dir, File.basename(core_config_file))5 FileUtils.cp(core_config_file, plugin_config_dir)6 plugin_config_dir = File.join('config', 'plugins', @plugin_name)7 core_config_dir = File.join('config', 'core')8 core_config_files = Dir[File.join(core_config_dir, '*.yml')]9 plugin_config_file = File.join(plugin_config_dir, File.basename(core_config_file))10 FileUtils.cp(core_config_file, plugin_config_dir)
copy_in_core_config_dir
Using AI Code Generation
1 core_config_dir = File.expand_path("../../../bundler", __FILE__)2 FileUtils.mkdir_p(config_dir)3 core_config_dir = File.expand_path("../../../bundler", __FILE__)4 FileUtils.mkdir_p(config_dir)5 core_config_dir = File.expand_path("../../../bundler", __FILE__)6 FileUtils.mkdir_p(config_dir)7 core_config_dir = File.expand_path("../../../bundler", __FILE__)8 FileUtils.mkdir_p(config_dir)
copy_in_core_config_dir
Using AI Code Generation
1copy_in_core_config_dir("gerrit", "config/gerrit.yml")2 register_plugin_routes("gerrit")3 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)4 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)5 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)6 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)7 FileUtils.cp_r(File.join(Gem::ConfigMap[:datadir], 'ri'), @config_dir)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!