diff --git a/lib/serverspec/type/docker_base.rb b/lib/serverspec/type/docker_base.rb index b5105b69..5e465c3f 100644 --- a/lib/serverspec/type/docker_base.rb +++ b/lib/serverspec/type/docker_base.rb @@ -9,7 +9,8 @@ def exist? def [](key) value = inspection key.split('.').each do |k| - value = value[k] + is_index = k.start_with?('[') && k.end_with?(']') + value = value[is_index ? k.to_i : k] end value end diff --git a/spec/type/linux/docker_container_spec.rb b/spec/type/linux/docker_container_spec.rb index 71c2e4bb..91a52964 100644 --- a/spec/type/linux/docker_container_spec.rb +++ b/spec/type/linux/docker_container_spec.rb @@ -15,6 +15,7 @@ it { should have_volume('/tmp', '/data') } its(:inspection) { should include 'Driver' => 'aufs' } its(['Config.Cmd']) { should include '/bin/sh' } + its(['HostConfig.PortBindings.80.[0].HostPort']) { should eq '8080' } end describe docker_container('restarting') do @@ -73,7 +74,14 @@ def inspect_container "Links": null, "LxcConf": [], "NetworkMode": "bridge", - "PortBindings": {}, + "PortBindings": { + "80": [ + { + "HostIp": "", + "HostPort": "8080" + } + ] + }, "Privileged": false, "PublishAllPorts": false, "VolumesFrom": null