Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Add support for Java Properties configuration. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions lib/poise_file/resources/poise_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def default_format
# have string content, it's just raw content by default.
return 'text' if pattern || content.is_a?(String)
case path
when /\.properties$/
'java'
when /\.json$/
'json'
when /\.ya?ml$/
Expand Down Expand Up @@ -209,6 +211,9 @@ def content_for_pattern
# @return [String]
def content_for_format
case @new_resource.format.to_s
when 'java'
require 'java-properties'
JavaProperties.generate(@new_resource.content)
when 'json'
require 'chef/json_compat'
# Make sure we include the trailing newline because YAML has one.
Expand Down
1 change: 1 addition & 0 deletions poise-file.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
spec.require_paths = %w{lib}

spec.add_dependency 'chef', '>= 12.1', '< 14'
spec.add_dependency 'java-properties', '~> 0.2'
spec.add_dependency 'halite', '~> 1.0'
spec.add_dependency 'poise', '~> 2.0'

Expand Down
4 changes: 4 additions & 0 deletions test/cookbook/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
content 'here' => 'is my spout', 'when' => ['I', 'get', 'all', 'steamed', 'up']
end

poise_file '/poise_test.properties' do
content 'here' => 'is my spout', 'when' => ['I', 'get', 'all', 'steamed', 'up']
end

file '/poise_test_pattern' do
content "I must shout\ntip me over\n"
end
Expand Down
12 changes: 12 additions & 0 deletions test/integration/default/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
its(:content) { is_expected.to eq "I'm a little teapot\n" }
end

describe file('/poise_test.properties') do
it { is_expected.to be_a_file }
its(:content) { is_expected.to eq <<-EOH }
[
"short and stout",
{
"here": "is my handle"
}
]
EOH
end

describe file('/poise_test.json') do
it { is_expected.to be_a_file }
its(:content) { is_expected.to eq <<-EOH }
Expand Down
10 changes: 10 additions & 0 deletions test/spec/resources/poise_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
end

describe 'formats' do
context 'with a .properties path' do
recipe(subject: false) do
poise_file "#{node['temp_path']}/test.properties" do
content 'io.poise.file' => 'java'
end
end

its(['test.properties']) { is_expected.to eq %Q(io.poise.file=java) }
end # /context with a .properties path

context 'with a .json path' do
recipe(subject: false) do
poise_file "#{node['temp_path']}/test.json" do
Expand Down