Unit test fix for docker containers and profile context

Signed-off-by: Nik08 <nikita.mathur@progress.com>
This commit is contained in:
Nik08 2024-09-10 15:09:29 +05:30
parent 5da1433ffc
commit 2bbe8d97c0
2 changed files with 17 additions and 4 deletions

View file

@ -8,6 +8,7 @@ class Module
end
RUBY3_1_PLUS = Gem.ruby_version >= Gem::Version.new("3.1")
RUBY3_3_PLUS = Gem.ruby_version >= Gem::Version.new("3.3")
module DescribeOneTest
it "loads an empty describe.one" do
@ -95,14 +96,22 @@ describe Inspec::ProfileContext do
it "supports empty describe calls" do
assert_load("describe", "")
_(profile.rules.keys.length).must_equal 1
_(profile.rules.keys[0]).must_match(/^\(generated from \(eval\):1 [0-9a-f]+\)$/)
if RUBY3_3_PLUS
_(profile.rules.keys[0]).must_match(/^\(generated from \(eval at .+:\d+\):\d+ [0-9a-f]+\)$/)
else
_(profile.rules.keys[0]).must_match(/^\(generated from \(eval\):1 [0-9a-f]+\)$/)
end
_(profile.rules.values[0]).must_be_kind_of Inspec::Rule
end
it "provides the describe keyword in the global DSL" do
assert_load("describe true do; it { should_eq true }; end", "")
_(profile.rules.keys.length).must_equal 1
_(profile.rules.keys[0]).must_match(/^\(generated from \(eval\):1 [0-9a-f]+\)$/)
if RUBY3_3_PLUS
_(profile.rules.keys[0]).must_match(/^\(generated from profile_context\.rb:\d+\):\d+ [0-9a-f]+\)$/)
else
_(profile.rules.keys[0]).must_match(/^\(generated from \(eval\):1 [0-9a-f]+\)$/)
end
_(profile.rules.values[0]).must_be_kind_of Inspec::Rule
end
@ -110,7 +119,11 @@ describe Inspec::ProfileContext do
assert_load("%w{1 2 3}.each do\ndescribe true do; it { should_eq true }; end\nend", "")
_(profile.rules.keys.length).must_equal 3
[0, 1, 2].each do |i|
_(profile.rules.keys[i]).must_match(/^\(generated from \(eval\):2 [0-9a-f]+\)$/)
if RUBY3_3_PLUS
_(profile.rules.keys[i]).must_match(/^\(generated from profile_context\.rb:\d+\):\d+ [0-9a-f]+\)$/)
else
_(profile.rules.keys[i]).must_match(/^\(generated from \(eval\):2 [0-9a-f]+\)$/)
end
_(profile.rules.values[i]).must_be_kind_of Inspec::Rule
end
end

View file

@ -69,7 +69,7 @@ describe "Inspec::Resources::DockerContainer" do
it "checks exception when no volume has been mounted for the docker resource and the container doesnt'e exist" do
resource = load_resource("docker_container", "non_existing_container")
ex = _ { resource.has_volume?("/app", "/var/lib/docker/volumes/myvol2/_data") }.must_raise(NoMethodError)
_(ex.message).must_include "undefined method `[]' for nil:NilClass"
_(ex.message).must_include "undefined method '[]' for nil"
end
end
end