From 7e10693e94d8e075ba3c88931d44d7df6f354623 Mon Sep 17 00:00:00 2001 From: John Bellone Date: Wed, 13 Sep 2017 10:50:13 -0400 Subject: [PATCH] Add support for Java Properties configuration. --- lib/poise_file/resources/poise_file.rb | 5 +++++ poise-file.gemspec | 1 + test/cookbook/recipes/default.rb | 4 ++++ test/integration/default/serverspec/default_spec.rb | 12 ++++++++++++ test/spec/resources/poise_file_spec.rb | 10 ++++++++++ 5 files changed, 32 insertions(+) diff --git a/lib/poise_file/resources/poise_file.rb b/lib/poise_file/resources/poise_file.rb index 8b03d37..f20be56 100644 --- a/lib/poise_file/resources/poise_file.rb +++ b/lib/poise_file/resources/poise_file.rb @@ -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$/ @@ -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. diff --git a/poise-file.gemspec b/poise-file.gemspec index 5cec165..0644ab6 100644 --- a/poise-file.gemspec +++ b/poise-file.gemspec @@ -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' diff --git a/test/cookbook/recipes/default.rb b/test/cookbook/recipes/default.rb index d72ea3b..c8d7bf7 100644 --- a/test/cookbook/recipes/default.rb +++ b/test/cookbook/recipes/default.rb @@ -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 diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index 3c51a91..48a121a 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -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 } diff --git a/test/spec/resources/poise_file_spec.rb b/test/spec/resources/poise_file_spec.rb index 89e297c..c8d4ab7 100644 --- a/test/spec/resources/poise_file_spec.rb +++ b/test/spec/resources/poise_file_spec.rb @@ -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