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

Add support for TOML configuration language. #3

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 @@ -93,6 +93,8 @@ def default_format
'json'
when /\.ya?ml$/
'yaml'
when /\.toml$/
'toml'
else
'text'
end
Expand Down Expand Up @@ -213,6 +215,9 @@ def content_for_format
require 'chef/json_compat'
# Make sure we include the trailing newline because YAML has one.
Chef::JSONCompat.to_json_pretty(@new_resource.content) + "\n"
when 'toml'
require 'toml'
TOML::Generator.new(@new_resource.content).body
when 'yaml'
require 'yaml'
YAML.dump(@new_resource.content)
Expand Down
1 change: 1 addition & 0 deletions poise-file.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'chef', '>= 12.1', '< 14'
spec.add_dependency 'halite', '~> 1.0'
spec.add_dependency 'poise', '~> 2.0'
spec.add_dependency 'toml', '~> 0.1'

spec.add_development_dependency 'poise-boiler', '~> 1.0'
end
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.toml' 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
14 changes: 14 additions & 0 deletions test/integration/default/serverspec/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
EOH
end

describe file('/poise_test.toml') do
it { is_expected.to be_a_file }
its(:content) { is_expected.to eq <<-EOH }
---
here: is my spout
when:
- I
- get
- all
- steamed
- up
EOH
end

describe file('/poise_test_pattern') do
it { is_expected.to be_a_file }
its(:content) { is_expected.to eq "I must yell\ntip me over\n" }
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 @@ -61,6 +61,16 @@
its(['test.json']) { is_expected.to eq "foo\nbar\n" }
end # /context with a .json path but string content

context 'with a .toml path' do
recipe(subject: false) do
poise_file "#{node['temp_path']}/test.toml" do
content 'foo' => 'bar'
end
end

its(['test.toml']) { is_expected.to eq %Q(foo = "bar"\n) }
end # /context with a .toml path

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