Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use config user/group for consul_definition instead of hard coded string #362

Merged
merged 2 commits into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/consul_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ConsulConfig < Chef::Resource
attribute(:path, kind_of: String, name_attribute: true)
# @!attribute owner
# @return [String]
attribute(:owner, kind_of: String, default: 'consul')
attribute(:owner, kind_of: String, default: lazy { node['consul']['service_user'] })
# @!attribute group
# @return [String]
attribute(:group, kind_of: String, default: 'consul')
attribute(:group, kind_of: String, default: lazy { node['consul']['service_group'] })
# @!attribute config_dir
# @return [String]
attribute(:config_dir, kind_of: String, default: lazy { node['consul']['service']['config_dir'] })
Expand Down
4 changes: 2 additions & 2 deletions libraries/consul_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class ConsulDefinition < Chef::Resource

# @!attribute user
# @return [String]
attribute(:user, kind_of: String, default: 'consul')
attribute(:user, kind_of: String, default: lazy { node['consul']['service_user'] })

# @!attribute group
# @return [String]
attribute(:group, kind_of: String, default: 'consul')
attribute(:group, kind_of: String, default: lazy { node['consul']['service_group'] })

# @!attribute type
# @return [String]
Expand Down
2 changes: 2 additions & 0 deletions test/spec/libraries/consul_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
recipe = double('Chef::Recipe')
allow_any_instance_of(Chef::RunContext).to receive(:include_recipe).and_return([recipe])
default_attributes['consul'] = {
'service_user' => 'consul',
'service_group' => 'consul',
'service' => {
'config_dir' => '/etc/consul/conf.d'
}
Expand Down
36 changes: 36 additions & 0 deletions test/spec/libraries/consul_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }
before do
default_attributes['consul'] = {
'service_user' => 'consul',
'service_group' => 'consul',
'service' => {
'config_dir' => '/etc/consul/conf.d'
}
Expand Down Expand Up @@ -62,6 +64,40 @@
end
end

context 'service definition with owner and group from node config' do
before do
default_attributes['consul'] = {
'service_user' => 'root',
'service_group' => 'root',
'service' => {
'config_dir' => '/etc/consul/conf.d'
}
}
end

recipe do
consul_definition 'redis' do
type 'service'
parameters(name: 'myredis', tags: %w{master}, address: '127.0.0.1', port: 6379, interval: '10s')
end
end

it { is_expected.to create_directory('/etc/consul/conf.d') }
it do
is_expected.to create_file('/etc/consul/conf.d/redis.json')
.with(user: 'root', group: 'root', mode: '0640')
.with(content: JSON.pretty_generate(
service: {
name: 'myredis',
tags: ['master'],
address: '127.0.0.1',
port: 6379,
interval: '10s'
}
))
end
end

context 'check definition' do
recipe do
consul_definition 'web-api' do
Expand Down