2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/gem"
|
2015-09-08 22:11:42 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::Gem" do
|
|
|
|
it "verify gem is not installed" do
|
|
|
|
resource = load_resource("gem", "not-installed")
|
2017-04-04 19:35:40 +00:00
|
|
|
_(resource.installed?).must_equal false
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify gem package detail parsing" do
|
|
|
|
resource = load_resource("gem", "rubocop")
|
2015-09-22 16:33:05 +00:00
|
|
|
pkg = {
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "rubocop",
|
|
|
|
version: "0.33.0",
|
|
|
|
type: "gem",
|
2015-09-22 16:33:05 +00:00
|
|
|
installed: true,
|
2018-09-18 19:00:26 +00:00
|
|
|
versions: ["0.33.0", "0.32.1", "0.28.0"],
|
2015-09-22 16:33:05 +00:00
|
|
|
}
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.info).must_equal pkg
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gem_binary).must_equal "gem"
|
2017-03-25 05:28:42 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "specifying gem binary" do
|
|
|
|
resource = load_resource("gem", "pry", "/opt/ruby-2.3.1/embedded/bin/gem")
|
2017-03-25 05:28:42 +00:00
|
|
|
pkg = {
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "pry",
|
|
|
|
version: "0.10.4",
|
|
|
|
type: "gem",
|
2017-03-25 05:28:42 +00:00
|
|
|
installed: true,
|
2018-09-18 19:00:26 +00:00
|
|
|
versions: ["0.10.4"],
|
2017-03-25 05:28:42 +00:00
|
|
|
}
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.info).must_equal pkg
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gem_binary).must_equal "/opt/ruby-2.3.1/embedded/bin/gem"
|
2017-03-25 05:28:42 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify gem in :chef" do
|
|
|
|
resource = load_resource("gem", "chef-sugar", :chef)
|
2017-03-25 05:28:42 +00:00
|
|
|
pkg = {
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "chef-sugar",
|
|
|
|
version: "3.4.0",
|
|
|
|
type: "gem",
|
2017-03-25 05:28:42 +00:00
|
|
|
installed: true,
|
2018-09-18 19:00:26 +00:00
|
|
|
versions: ["3.4.0"],
|
2017-03-25 05:28:42 +00:00
|
|
|
}
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.info).must_equal pkg
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gem_binary).must_equal "/opt/chef/embedded/bin/gem"
|
2017-03-25 05:28:42 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verifies gem in :chef when multiple versions are installed" do
|
|
|
|
resource = load_resource("gem", "chef-sugar", :chef)
|
2018-09-18 17:17:10 +00:00
|
|
|
_(resource.installed?).must_equal true
|
2019-05-31 21:59:06 +00:00
|
|
|
_(resource.versions[0]).must_match(/3\.4/)
|
|
|
|
_(resource.versions).wont_include(/2\.4/)
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gem_binary).must_equal "/opt/chef/embedded/bin/gem"
|
2018-09-18 17:17:10 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify gem in :chef on windows" do
|
|
|
|
resource = MockLoader.new(:windows).load_resource("gem", "json", :chef)
|
2017-03-25 05:28:42 +00:00
|
|
|
pkg = {
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "json",
|
|
|
|
version: "1.8.3",
|
|
|
|
type: "gem",
|
2017-03-25 05:28:42 +00:00
|
|
|
installed: true,
|
2018-09-18 19:00:26 +00:00
|
|
|
versions: ["1.8.3"],
|
2017-03-25 05:28:42 +00:00
|
|
|
}
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.info).must_equal pkg
|
2017-04-12 15:22:58 +00:00
|
|
|
_(resource.gem_binary).must_equal 'c:\opscode\chef\embedded\bin\gem.bat'
|
2017-03-25 05:28:42 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify gem in :chef_server" do
|
|
|
|
resource = load_resource("gem", "knife-backup", :chef_server)
|
2017-03-25 05:28:42 +00:00
|
|
|
pkg = {
|
2019-06-11 22:24:35 +00:00
|
|
|
name: "knife-backup",
|
|
|
|
version: "0.0.12",
|
|
|
|
type: "gem",
|
2017-03-25 05:28:42 +00:00
|
|
|
installed: true,
|
2018-09-18 19:00:26 +00:00
|
|
|
versions: ["0.0.12"],
|
2017-03-25 05:28:42 +00:00
|
|
|
}
|
|
|
|
_(resource.installed?).must_equal true
|
|
|
|
_(resource.info).must_equal pkg
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.gem_binary).must_equal "/opt/opscode/embedded/bin/gem"
|
2015-09-08 22:11:42 +00:00
|
|
|
end
|
|
|
|
end
|