CFINSPEC-86: Add comments and unit test for invalid keys

Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
Sonu Saha 2022-03-24 22:49:01 +05:30
parent 3eba207bcf
commit f6115c7aeb
2 changed files with 9 additions and 1 deletions

View file

@ -62,6 +62,7 @@ module Inspec::Resources
image_hash_inspection(hash_keys)
end
# inspection property allows to test any of the hash key-value pairs as part of the image_inspect_info
def inspection
image_inspect_info
end

View file

@ -12,15 +12,22 @@ describe "Inspec::Resources::DockerImage" do
_(resource.repo).must_equal "alpine"
end
# Test case for inspect image information handled by inspection and method_missing
it "check attributes returned by docker inspect [docker_image]" do
resource = load_resource("docker_image", "ubuntu:latest")
_(resource["Architecture"]).must_equal "arm64"
_(resource["Config.Cmd"]).must_include "bash"
# Check, minitest equivalent for: 'Architecture' => 'arm64
_(resource.inspection).must_include "Architecture"
_(resource.inspection.Architecture).must_equal "arm64"
end
# Test case for inspect image information with invalid keys
it "checks exception when key is invalid or doesn't exist as part of the inspect information" do
resource = load_resource("docker_image", "ubuntu:latest")
ex = _ { resource["Garbage.Key"] }.must_raise(Inspec::Exceptions::ResourceFailed)
_(ex.message).must_include "Garbage.Key is not a valid key for your image or has nil value."
end
it "prints as a docker_image resource" do
resource = load_resource("docker_image", "alpine")
_(resource.to_s).must_equal "Docker Image alpine:latest"