Skip to content

Commit

Permalink
Merge pull request #265 from paybyphone/fix_config_dir
Browse files Browse the repository at this point in the history
Create config files in config_dir
  • Loading branch information
johnbellone committed Feb 2, 2016
2 parents 8fabbdf + 3e3a9fd commit c8b2f4b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Metrics/AbcSize:
Enabled: false
PerceivedComplexity:
Enabled: false
SingleSpaceBeforeFirstArg:
Style/SingleSpaceBeforeFirstArg:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Expand Down
2 changes: 1 addition & 1 deletion libraries/consul_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ConsulDefinition < Chef::Resource

# @!attribute path
# @return [String]
attribute(:path, kind_of: String, default: lazy { join_path config_prefix_path, "#{name}.json" })
attribute(:path, kind_of: String, default: lazy { join_path node['consul']['service']['config_dir'], "#{name}.json" })

# @!attribute user
# @return [String]
Expand Down
3 changes: 2 additions & 1 deletion libraries/consul_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ module Resource
# @since 1.0.0
class ConsulWatch < Chef::Resource
include Poise(fused: true)
include ConsulCookbook::Helpers
provides(:consul_watch)
default_action(:create)

# @!attribute path
# @return [String]
attribute(:path, kind_of: String, default: lazy { "/etc/consul/#{name}.json" })
attribute(:path, kind_of: String, default: lazy { join_path node['consul']['service']['config_dir'], "#{name}.json" })

# @!attribute user
# @return [String]
Expand Down
19 changes: 13 additions & 6 deletions test/spec/libraries/consul_definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
describe ConsulCookbook::Resource::ConsulDefinition do
step_into(:consul_definition)
let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }
before do
default_attributes['consul'] = {
'service' => {
'config_dir' => '/etc/consul/conf.d'
}
}
end

context 'service definition' do
recipe do
Expand All @@ -13,9 +20,9 @@
end
end

it { is_expected.to create_directory('/etc/consul') }
it { is_expected.to create_directory('/etc/consul/conf.d') }
it do
is_expected.to create_file('/etc/consul/redis.json')
is_expected.to create_file('/etc/consul/conf.d/redis.json')
.with(user: 'consul', group: 'consul', mode: '0640')
.with(content: JSON.pretty_generate(
service: {
Expand All @@ -37,9 +44,9 @@
end
end

it { is_expected.to create_directory('/etc/consul') }
it { is_expected.to create_directory('/etc/consul/conf.d') }
it do
is_expected.to create_file('/etc/consul/redis.json')
is_expected.to create_file('/etc/consul/conf.d/redis.json')
.with(user: 'consul', group: 'consul', mode: '0640')
.with(content: JSON.pretty_generate(
service: {
Expand All @@ -61,9 +68,9 @@
end
end

it { is_expected.to create_directory('/etc/consul') }
it { is_expected.to create_directory('/etc/consul/conf.d') }
it do
is_expected.to create_file('/etc/consul/web-api.json')
is_expected.to create_file('/etc/consul/conf.d/web-api.json')
.with(user: 'consul', group: 'consul', mode: '0640')
.with(content: JSON.pretty_generate(
check: {
Expand Down
11 changes: 9 additions & 2 deletions test/spec/libraries/consul_watch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
describe ConsulCookbook::Resource::ConsulWatch do
step_into(:consul_watch)
let(:chefspec_options) { {platform: 'ubuntu', version: '14.04'} }
before do
default_attributes['consul'] = {
'service' => {
'config_dir' => '/etc/consul/conf.d'
}
}
end

context 'key watch' do
recipe do
Expand All @@ -13,9 +20,9 @@
end
end

it { is_expected.to create_directory('/etc/consul') }
it { is_expected.to create_directory('/etc/consul/conf.d') }
it do
is_expected.to create_file('/etc/consul/foo.json')
is_expected.to create_file('/etc/consul/conf.d/foo.json')
.with(user: 'consul', group: 'consul', mode: '0640')
.with(content: JSON.pretty_generate(
{
Expand Down

0 comments on commit c8b2f4b

Please sign in to comment.