2016-02-05 15:57:51 +00:00
|
|
|
# TODO: do not use helper, since all plugins are loaded statically
|
2019-06-11 22:24:35 +00:00
|
|
|
require "minitest/autorun"
|
|
|
|
require "mocha/setup"
|
2016-02-05 15:57:51 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "inspec/plugin/v1/plugin_types/cli"
|
|
|
|
require "thor"
|
2016-02-05 11:40:57 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "plugin system" do
|
|
|
|
describe "with an empty profile" do
|
2016-02-05 11:40:57 +00:00
|
|
|
let(:cli_reg) { Inspec::Plugins::CLI }
|
|
|
|
|
2016-02-05 15:57:51 +00:00
|
|
|
before do
|
2016-02-08 21:25:07 +00:00
|
|
|
# since the registry is a global singleton, clean it before using
|
|
|
|
cli_reg.subcommands.clear
|
2016-02-05 15:57:51 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "is empty" do
|
2016-02-08 21:25:07 +00:00
|
|
|
cli_reg.subcommands.must_equal({})
|
2016-02-05 11:40:57 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "stores one cli plugin" do
|
2016-02-05 11:40:57 +00:00
|
|
|
plugin = {
|
|
|
|
klass: Thor.new,
|
2019-06-11 22:24:35 +00:00
|
|
|
subcommand_name: "my_cmd",
|
|
|
|
usage: "usage my_cmd",
|
|
|
|
description: "desc of my_cmd",
|
|
|
|
options: { test: 1 },
|
2016-02-05 11:40:57 +00:00
|
|
|
}
|
2016-02-08 21:25:07 +00:00
|
|
|
cli_reg.add_subcommand(
|
2016-02-05 11:40:57 +00:00
|
|
|
plugin[:klass],
|
|
|
|
plugin[:subcommand_name],
|
|
|
|
plugin[:usage],
|
|
|
|
plugin[:description],
|
|
|
|
plugin[:options]
|
|
|
|
)
|
2019-06-11 22:24:35 +00:00
|
|
|
cli_reg.subcommands["my_cmd"].must_equal(plugin)
|
2016-02-05 11:40:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|