Class: PluginManagerCliSearch

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

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



87
88
89
90
91
92
93
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 87

def test_search_for_a_gem_that_does_not_exist
  result = run_inspec_process("plugin search --include-test-fixture inspec-test-fixture-nonesuch")

  assert_includes result.stdout, "0 plugin(s) found", "Search result should find 0 plugins"

  assert_exit_code 2, result
end

#test_search_for_a_gem_with_missing_prefixObject



81
82
83
84
85
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 81

def test_search_for_a_gem_with_missing_prefix
  result = run_inspec_process("plugin search --include-test-fixture test-fixture")
  assert_exit_code 1, result
  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



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 65

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_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")

  assert_exit_code 0, result

  # TODO: split
  result = run_inspec_process("plugin search -a --include-test-fixture inspec-test-fixture")

  assert_exit_code 0, result
end

#test_search_for_a_real_gem_with_full_name_and_exact_optionObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 38

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_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"

  assert_exit_code 0, result

  # TODO: split
  result = run_inspec_process("plugin search -e --include-test-fixture inspec-test-fixture")

  assert_exit_code 0, result
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



15
16
17
18
19
20
21
22
23
24
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 15

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_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")

  assert_exit_code 0, result
end

#test_search_for_a_real_gem_with_full_name_no_options_and_train_nameObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 95

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_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")

  assert_exit_code 0, result
end

#test_search_for_a_real_gem_with_full_name_no_options_filter_fixturesObject



120
121
122
123
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 120

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



125
126
127
128
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 125

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



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 52

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_includes result.stdout, "0 plugin(s) found", "Search result should find 0 plugins"

  assert_exit_code 2, result

  # TODO: split
  result = run_inspec_process("plugin search -e --include-test-fixture inspec-test-")

  assert_exit_code 2, result
end

#test_search_for_a_real_gem_with_stub_name_no_optionsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 26

def test_search_for_a_real_gem_with_stub_name_no_options
  result = run_inspec_process("plugin search --include-test-fixture inspec-test-")

  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")

  assert_exit_code 0, result
end

#test_search_omit_excluded_inspec_pluginsObject



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/plugins/inspec-plugin-manager-cli/test/functional/search_test.rb', line 106

def test_search_omit_excluded_inspec_plugins
  result = run_inspec_process("plugin search --include-test-fixture inspec-")

  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

  assert_exit_code 0, result
end