2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/docker_image"
|
2017-04-24 14:47:03 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::DockerImage" do
|
|
|
|
describe "docker_image" do
|
|
|
|
it "check docker image parsing" do
|
|
|
|
resource = load_resource("docker_image", "alpine")
|
|
|
|
_(resource.id).must_equal "sha256:4a415e3663882fbc554ee830889c68a33b3585503892cc718a4698e91ef2a526"
|
|
|
|
_(resource.tag).must_equal "latest"
|
|
|
|
_(resource.image).must_equal "alpine:latest"
|
|
|
|
_(resource.repo).must_equal "alpine"
|
2017-04-24 14:47:03 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "prints as a docker_image resource" do
|
|
|
|
resource = load_resource("docker_image", "alpine")
|
|
|
|
resource.to_s.must_equal "Docker Image alpine:latest"
|
2017-04-24 14:47:03 +00:00
|
|
|
end
|
|
|
|
end
|
2017-12-01 09:24:15 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#parse_components_from_image" do
|
|
|
|
let(:resource) { load_resource("docker_image", "alpine") }
|
2017-12-01 09:24:15 +00:00
|
|
|
let(:parsed) { resource.send(:parse_components_from_image, image_string) }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "a nil image string" do
|
2017-12-01 09:24:15 +00:00
|
|
|
let(:image_string) { nil }
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns an empty hash" do
|
2017-12-01 09:24:15 +00:00
|
|
|
parsed.must_equal({})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "an image string containing a simple repo" do
|
|
|
|
let(:image_string) { "chef/inspec" }
|
2017-12-01 09:24:15 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns correct data" do
|
|
|
|
parsed[:repo].must_equal "chef/inspec"
|
2017-12-01 09:24:15 +00:00
|
|
|
parsed[:tag].must_be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "parses an image string containing a repo with a port number" do
|
|
|
|
let(:image_string) { "localhost:5000/chef/inspec" }
|
2017-12-01 09:24:15 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns correct data" do
|
|
|
|
parsed[:repo].must_equal "localhost:5000/chef/inspec"
|
2017-12-01 09:24:15 +00:00
|
|
|
parsed[:tag].must_be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "parses an image string containing a repo with a tag" do
|
|
|
|
let(:image_string) { "chef/inspec:1.46.3" }
|
2017-12-01 09:24:15 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns correct data" do
|
|
|
|
parsed[:repo].must_equal "chef/inspec"
|
|
|
|
parsed[:tag].must_equal "1.46.3"
|
2017-12-01 09:24:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "parses an image string containing a repo with a port number and a tag" do
|
|
|
|
let(:image_string) { "localhost:5000/chef/inspec:1.46.3" }
|
2017-12-01 09:24:15 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "returns correct data" do
|
|
|
|
parsed[:repo].must_equal "localhost:5000/chef/inspec"
|
|
|
|
parsed[:tag].must_equal "1.46.3"
|
2017-12-01 09:24:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-24 14:47:03 +00:00
|
|
|
end
|