mirror of
https://github.com/inspec/inspec
synced 2025-02-16 22:18:38 +00:00
CFINSPEC-86: Add comments and unit test for invalid keys
Signed-off-by: Sonu Saha <sonu.saha@progress.com>
This commit is contained in:
parent
3eba207bcf
commit
f6115c7aeb
2 changed files with 9 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue