Class: PluginManagerCliUninstall

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 uninstall

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

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_fail_uninstall_from_plugin_that_is_not_installedObject



716
717
718
719
720
721
722
723
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 716

def test_fail_uninstall_from_plugin_that_is_not_installed
  uninstall_result = run_inspec_process_with_this_plugin("plugin uninstall inspec-test-fixture-nonesuch")

  assert_empty uninstall_result.stderr
  assert_equal 1, uninstall_result.exit_status, "Exit status should be 1"
  refute_includes "Inspec::Plugin::V2::UnInstallError", uninstall_result.stdout # Stacktrace marker
  assert_match(/No such plugin installed: .+ - uninstall failed/, uninstall_result.stdout)
end

#test_when_a_gem_plugin_can_be_uninstalledObject



672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 672

def test_when_a_gem_plugin_can_be_uninstalled
  pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
    plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
    copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
  end

  # Attempt uninstall
  uninstall_result = run_inspec_process_with_this_plugin("plugin uninstall inspec-test-fixture", pre_run: pre_block, post_run: list_after_run)
  assert_empty uninstall_result.stderr
  assert_equal 0, uninstall_result.exit_status, "Exit status should be 0"

  success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last
  refute_nil success_message, "Should find a success message at the end"
  assert_includes success_message, "inspec-test-fixture"
  assert_includes success_message, "0.1.0"
  assert_includes success_message, "has been uninstalled"

  list_result = uninstall_result.payload.list_result
  itf_line = list_result.stdout.split("\n").grep(/inspec-test-fixture/).first
  assert_nil itf_line, "inspec-test-fixture should not appear in the output of inspec list"
end

#test_when_a_path_plugin_can_be_uninstalledObject



694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb', line 694

def test_when_a_path_plugin_can_be_uninstalled
  pre_block = Proc.new do |plugin_statefile_data, tmp_dir|
    plugin_statefile_data.clear # Signal not to write a file, we'll provide one.
    # This fixture includes a path install for inspec-meaning-of-life
    copy_in_core_config_dir("test-fixture-1-float", tmp_dir)
  end

  uninstall_result = run_inspec_process_with_this_plugin("plugin uninstall inspec-meaning-of-life", pre_run: pre_block, post_run: list_after_run)
  assert_empty uninstall_result.stderr
  assert_equal 0, uninstall_result.exit_status, "Exit status should be 0"

  success_message = uninstall_result.stdout.split("\n").grep(/uninstalled/).last
  refute_nil success_message, "Should find a success message at the end"
  assert_includes success_message, "inspec-meaning-of-life"
  assert_includes success_message, "path-based plugin install"
  assert_includes success_message, "has been uninstalled"

  list_result = uninstall_result.payload.list_result
  itf_line = list_result.stdout.split("\n").grep(/inspec-meaning-of-life/).first
  assert_nil itf_line, "inspec-meaning-of-life should not appear in the output of inspec list"
end