1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
# frozen_string_literal: true
require 'spec_helper'
describe 'extlib::to_ini' do
let(:example_input) do
{
'main' => {
'logging' => 'INFO',
'limit' => 314,
'awesome' => true,
},
'dev' => {
'logging' => 'DEBUG',
'log_location' => '/var/log/dev.log',
}
}
end
it { is_expected.not_to eq(nil) }
context 'default settings' do
let(:output) do
<<~EOS
# THIS FILE IS CONTROLLED BY PUPPET
[main]
logging="INFO"
limit="314"
awesome="true"
[dev]
logging="DEBUG"
log_location="/var/log/dev.log"
EOS
end
it { is_expected.to run.with_params(example_input).and_return(output) }
end
context 'custom settings' do
let(:settings) do
{
'header' => '; THIS FILE IS CONTROLLED BY /dev/random',
'section_prefix' => '[[',
'section_suffix' => ']]',
'key_val_separator' => ': ',
'quote_char' => '',
}
end
let(:output) do
<<~EOS
; THIS FILE IS CONTROLLED BY /dev/random
[[main]]
logging: INFO
limit: 314
awesome: true
[[dev]]
logging: DEBUG
log_location: /var/log/dev.log
EOS
end
it { is_expected.to run.with_params(example_input, settings).and_return(output) }
end
context 'default settings with custom quoting' do
let(:settings) do
{
'quote_booleans' => false,
'quote_numerics' => false,
}
end
let(:output) do
<<~EOS
# THIS FILE IS CONTROLLED BY PUPPET
[main]
logging="INFO"
limit=314
awesome=true
[dev]
logging="DEBUG"
log_location="/var/log/dev.log"
EOS
end
it { is_expected.to run.with_params(example_input, settings).and_return(output) }
end
context 'default settings with empty sections' do
let(:example_input) do
{
'foo' => {},
'bar' => {}
}
end
let(:output) do
<<~EOS
# THIS FILE IS CONTROLLED BY PUPPET
[foo]
[bar]
EOS
end
it { is_expected.to run.with_params(example_input).and_return(output) }
end
end
|