Skip to content

Commit

Permalink
Add access to Docker config arrays.
Browse files Browse the repository at this point in the history
Support accessing arrays from the "docker inspect" output via normal index access.
  • Loading branch information
DarrellMozingo committed Sep 18, 2015
1 parent e5ee36e commit 7a6e491
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/serverspec/type/docker_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion spec/type/linux/docker_container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,7 +74,14 @@ def inspect_container
"Links": null,
"LxcConf": [],
"NetworkMode": "bridge",
"PortBindings": {},
"PortBindings": {
"80": [
{
"HostIp": "",
"HostPort": "8080"
}
]
},
"Privileged": false,
"PublishAllPorts": false,
"VolumesFrom": null
Expand Down

0 comments on commit 7a6e491

Please sign in to comment.