2018-09-13 18:14:05 +00:00
|
|
|
# copyright: 2017, Chef Software Inc.
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/impact"
|
2018-09-13 18:14:05 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Impact" do
|
2018-09-13 18:14:05 +00:00
|
|
|
let(:impact) { Inspec::Impact }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "impact from string method" do
|
|
|
|
it "returns the proper impact for none string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.impact_from_string("none")).must_equal 0.0
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact for low string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.impact_from_string("low")).must_equal 0.1
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact for medium string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.impact_from_string("medium")).must_equal 0.4
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact for high string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.impact_from_string("high")).must_equal 0.7
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact for critical string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.impact_from_string("critical")).must_equal 0.9
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns an error for a invalid impact string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
e = _ { impact.impact_from_string("fake") }.must_raise(Inspec::ImpactError)
|
|
|
|
_(e.message).must_match "'fake' is not a valid impact name. Valid impact names: none, low, medium, high, critical."
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "string from impact method" do
|
|
|
|
it "returns the proper impact string for 0.1" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.string_from_impact(0.1)).must_equal "low"
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact string for 0.57" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.string_from_impact(0.57)).must_equal "medium"
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact string for 0.7" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.string_from_impact(0.7)).must_equal "high"
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns the proper impact string for 1" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.string_from_impact(1)).must_equal "critical"
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns an error for a invalid impact score" do
|
2019-09-30 22:31:55 +00:00
|
|
|
e = _ { impact.string_from_impact(99) }.must_raise(Inspec::ImpactError)
|
|
|
|
_(e.message).must_match "'99.0' is not a valid impact score. Valid impact scores: [0.0 - 1.0]."
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "is_number? method" do
|
|
|
|
it "returns true for int string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.is_number?("1")).must_equal true
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns true for float string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.is_number?("10.99")).must_equal true
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns false for char string" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(impact.is_number?("abc")).must_equal false
|
2018-09-13 18:14:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|