class Serverspec::Type::DockerContainer
This class monkey patches serverspec's docker container type with some more method to be used in matchers
Public Instance Methods
domain_name()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 64 def domain_name inspection['Config']['Domainname'] end
environment_variable(regex)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 36 def environment_variable(regex) environment_variables.find { |str| str =~ /^#{regex}=/ }.split('=')[1..-1].join('=') end
environment_variables()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 40 def environment_variables inspection['Config']['Env'] end
has_domainname?(domain)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 60 def has_domainname?(domain) domain_name == domain end
has_environment_variable?(regex, value = nil)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 28 def has_environment_variable?(regex, value = nil) if value environment_variable(regex) == value else environment_variable(regex) end end
has_host?(host)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 84 def has_host?(host) hosts.include? host end
has_hostname?(hostname)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 52 def has_hostname?(hostname) self.hostname == hostname end
has_image?(image)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 12 def has_image?(image) self.image == image end
has_image_sha?(image)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 16 def has_image_sha?(image) image_sha == image end
has_mount?(source, target, type)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 109 def has_mount?(source, target, type) mounts.find { |mount| mount['Source'] == source && mount['Destination'] == target && mount['Type'] == type } end
has_restart_limit?(limit)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 68 def has_restart_limit?(limit) restart_limit == limit end
has_restart_policy?(policy)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 76 def has_restart_policy?(policy) restart_policy == policy end
has_user?(user)
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 44 def has_user?(user) self.user == user end
hostname()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 56 def hostname inspection['Config']['Hostname'] end
hosts()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 88 def hosts inspection['HostConfig']['ExtraHosts'].map { |itm| itm.split(':')[1] + ' ' + itm.split(':')[0] } end
image()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 20 def image inspection['Config']['Image'].split('@')[0] end
image_sha()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 24 def image_sha inspection['Config']['Image'].split('@')[1] end
include_regex?()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 8 def include_regex? inspection.find { |str| str =~ regex } end
map_port?(host, container, protocol = 'tcp')
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 101 def map_port?(host, container, protocol = 'tcp') inspection['NetworkSettings']['Ports']["#{container}/#{protocol}"][0]['HostPort'] == host end
mounts()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 113 def mounts inspection['Mounts'] end
port_map()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 105 def port_map inspection['HostConfig']['PortBindings'] end
privileged?()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 92 def privileged? inspection['HostConfig']['Privileged'] end
publishes_all_ports?()
click to toggle source
TODO: matcher for this
# File lib/serverspec_extra_types/types/docker_container.rb, line 97 def publishes_all_ports? inspection['HostConfig']['PublishAllPorts'] end
restart_limit()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 72 def restart_limit inspection['HostConfig']['RestartPolicy']['MaximumRetryCount'] end
restart_policy()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 80 def restart_policy inspection['HostConfig']['RestartPolicy']['Name'] end
user()
click to toggle source
# File lib/serverspec_extra_types/types/docker_container.rb, line 48 def user inspection['Config']['User'] end
Private Instance Methods
get_inspection()
click to toggle source
rubocop:disable Naming/AccessorMethodName
# File lib/serverspec_extra_types/types/docker_container.rb, line 122 def get_inspection @containers ||= @name.include?('=') ? @runner.run_command("docker ps -qa -f #{@name}").stdout : @name @get_inspection ||= @runner.run_command("docker inspect #{@containers}") end