Skip to content

Commit

Permalink
Merge pull request #548 from hdeheer/pr/515
Browse files Browse the repository at this point in the history
sorted_json should quote args for checks
  • Loading branch information
bastelfreak authored Aug 26, 2020
2 parents bc4a3f1 + 5e5792b commit cfbeea5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/puppet/functions/consul/sorted_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def sorted_json(unsorted_hash = {}, pretty = false, indent_len = 4)
when Hash
ret = []
obj.keys.sort.each do |k|
if k =~ /\A(node_meta|meta|tags)\z/ then
if k =~ /\A(node_meta|meta|tags|args)\z/ then
quoted = true
elsif k =~ /\A(weights)\z/ then
quoted = false
Expand Down Expand Up @@ -138,7 +138,7 @@ def sorted_json(unsorted_hash = {}, pretty = false, indent_len = 4)
# This level works in a similar way to the above
level += 1
obj.keys.sort.each do |k|
if k =~ /\A(node_meta|meta|tags)\z/ then
if k =~ /\A(node_meta|meta|tags|args)\z/ then
quoted = true
elsif k =~ /\A(weights)\z/ then
quoted = false
Expand Down
6 changes: 3 additions & 3 deletions spec/defines/consul_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let :facts do
facts
end

let(:title) { "my_check" }

describe 'with no args' do
Expand Down Expand Up @@ -36,15 +36,15 @@
describe 'with args' do
let(:params) {{
'interval' => '30s',
'args' => ['sh', '-c', 'true'],
'args' => ['sh', '-c', 'true', '1', 2],
}}
it {
should contain_file("/etc/consul/check_my_check.json") \
.with_content(/"id" *: *"my_check"/) \
.with_content(/"name" *: *"my_check"/) \
.with_content(/"check" *: *\{/) \
.with_content(/"interval" *: *"30s"/) \
.with_content(/"args" *: *\[ *"sh", *"-c", *"true" *\]/)
.with_content(/"args" *: *\[ *"sh", *"-c", *"true", *"1", *"2" *\]/)
}
end
describe 'with script and service_id' do
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/consul_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
'passing' => 10,
'warning' => 1
}
}
}
}}
it {
should contain_file("/etc/consul/service_my_service.json") \
Expand Down
3 changes: 3 additions & 0 deletions spec/functions/consul_sorted_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def deprettyfy(string, leave_pretty)
it 'quotes values of node_meta' do
is_expected.to run.with_params({'node_meta' => {'cpus' => 8 } },pretty).and_return(deprettyfy("{\n \"node_meta\": {\n \"cpus\": \"8\"\n }\n}\n",pretty))
end
it 'quotes values of args' do
is_expected.to run.with_params({'args' => ['aString', '1', 2] },pretty).and_return(deprettyfy("{\n \"args\": [\n \"aString\",\n \"1\",\n \"2\"\n ]\n}\n",pretty))
end
end
describe 'consul::sorted_json', :type => :puppet_function do

Expand Down

0 comments on commit cfbeea5

Please sign in to comment.