Skip to content

Commit

Permalink
allow docker::networks::networks param to be undef
Browse files Browse the repository at this point in the history
I would like to include the docker::networks class into the role
(manifest) of nodes which are also including the docker module but not
necessarily always defining docker network(s). This would allow docker
networks to optionally be defined, when needed, via hiera. Currently,
this type of arrangement would require constructing a wrapper class as
the docker::networks::networks parameter is mandatory.
  • Loading branch information
jhoblitt committed May 3, 2022
1 parent 196ae94 commit 85e563d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions manifests/networks.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# @param networks
#
class docker::networks (
$networks
Optional[Hash[String, Hash]] $networks = undef,
) {
create_resources(docker_network, $networks)
if $networks {
create_resources(docker_network, $networks)
}
}
6 changes: 6 additions & 0 deletions spec/classes/networks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@
'ip_range' => params['ip_range'],
)
}

it { is_expected.to have_docker_network_resource_count(1) }
end
end

context 'with no params' do
it { is_expected.to have_docker_network_resource_count(0) }
end
end
end
end

0 comments on commit 85e563d

Please sign in to comment.