spec/lib/formats/yaml_spec.rb in hieracles-0.3.0 vs spec/lib/formats/yaml_spec.rb in hieracles-0.3.1
- old
+ new
@@ -68,14 +68,18 @@
" var: value1 # some/file"
}
before {
allow(node).to receive(:params).with(true).and_return(
{
- 'params.this.var' => [{
- file: 'some/file',
- value: 'value1'
- }]
+ 'params.this.var' => {
+ file: 'some/file',
+ value: 'value1',
+ overriden: false,
+ found_in: [
+ { file: 'some/file', value: 'value1' }
+ ]
+ }
}
)
allow(node).to receive(:params_tree).with(true).and_return(
{
'params' => {
@@ -96,14 +100,18 @@
" var: value1 # some/file"
}
before {
allow(node).to receive(:params).and_return(
{
- 'params.this.var' => [{
- file: 'some/file',
- value: 'value1'
- }]
+ 'params.this.var' => {
+ file: 'some/file',
+ value: 'value1',
+ overriden: false,
+ found_in: [
+ { file: 'some/file', value: 'value1' }
+ ]
+ }
}
)
allow(node).to receive(:params_tree).and_return(
{
'params' => {
@@ -127,14 +135,18 @@
" var: value1 # some/file"
}
before {
allow(node).to receive(:params).and_return(
{
- 'params.this.var' => [{
- file: 'some/file',
- value: 'value1'
- }]
+ 'params.this.var' => {
+ file: 'some/file',
+ value: 'value1',
+ overriden: false,
+ found_in: [
+ { file: 'some/file', value: 'value1' }
+ ]
+ }
}
)
allow(node).to receive(:params_tree).and_return(
{
'params' => {
@@ -155,14 +167,18 @@
" var: value1 # some/file"
}
before {
allow(node).to receive(:params).with(false).and_return(
{
- 'params.this.var' => [{
- file: 'some/file',
- value: 'value1'
- }]
+ 'params.this.var' => {
+ file: 'some/file',
+ value: 'value1',
+ overriden: false,
+ found_in: [
+ { file: 'some/file', value: 'value1' }
+ ]
+ }
}
)
allow(node).to receive(:params_tree).with(false).and_return(
{
'params' => {
@@ -179,14 +195,18 @@
describe '.mergetree' do
context "with a simple string key-value" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: 'value'
- }]
+ 'key' => {
+ file: 'what/file',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'value1' }
+ ]
+ }
}
}
let(:input) {
{ 'key' => 'value' }
}
@@ -196,14 +216,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with various boolean type of key-values (true)" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: 'true'
- }]
+ 'key' => {
+ file: 'what/file',
+ value: true,
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: true }
+ ]
+ }
}
}
let(:input) {
{ 'key' => true }
}
@@ -213,14 +237,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with various null type of key-values (nil)" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: nil
- }]
+ 'key' => {
+ file: 'what/file',
+ value: nil,
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: nil }
+ ]
+ }
}
}
let(:input) {
{ 'key' => nil }
}
@@ -230,14 +258,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with various boolean type of key-values (false)" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: 'false'
- }]
+ 'key' => {
+ file: 'what/file',
+ value: 'false',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'false' }
+ ]
+ }
}
}
let(:input) {
{ 'key' => false }
}
@@ -247,14 +279,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with various fixnum type of key-values" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: '3'
- }]
+ 'key' => {
+ file: 'what/file',
+ value: '3',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: '3' }
+ ]
+ }
}
}
let(:input) {
{ 'key' => 3 }
}
@@ -264,14 +300,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with various float type of key-values" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: '0.3'
- }]
+ 'key' => {
+ file: 'what/file',
+ value: '0.3',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: '0.3' }
+ ]
+ }
}
}
let(:input) {
{ 'key' => 0.3 }
}
@@ -281,14 +321,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with a simple array key-value" do
let(:params) {
{
- 'key' => [{
- file: 'what/file',
- value: ['value1', 'value2']
- }]
+ 'key' => {
+ file: 'what/file',
+ value: ['value1', 'value2'],
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: ['value1', 'value2'] }
+ ]
+ }
}
}
let(:input) {
{ 'key' => ['value1', 'value2'] }
}
@@ -304,31 +348,28 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with a double array key-value" do
let(:params) {
{
- 'key' => [
- {
- file: 'what/file',
- value: ['value1', 'value2'],
- merged: ['value1', 'value2']
- },
- {
- file: 'what/other-file',
- value: ['value3'],
- merged: ['value1', 'value2', 'value3']
- }
- ]
+ 'key' => {
+ file: '-',
+ value: ['value3'],
+ overriden: true,
+ found_in: [
+ { file: 'what/file', value: ['value3'] },
+ { file: 'what/other-file', value: ['value1', 'value2'] }
+ ]
+ }
}
}
let(:hiera) { Struct.new( :merge_behavior ) }
context "with native merge behavior" do
let(:input) {
{ 'key' => ['value3'] }
}
let(:expected) {
- "\nkey: \n # what/other-file\n - value3"
+ "\nkey: \n # what/file\n # what/other-file\n - value3"
}
before {
allow(node).to receive(:hiera).and_return(
hiera.new(:native)
)
@@ -351,14 +392,18 @@
end
end
context "with a 2-levels string key-value" do
let(:params) {
{
- 'key.sublevel' => [{
- file: 'what/file',
- value: 'value'
- }]
+ 'key.sublevel' => {
+ file: 'what/file',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'value' }
+ ]
+ }
}
}
let(:input) {
{
'key' => {
@@ -372,18 +417,26 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with 2 2-levels string key-value" do
let(:params) {
{
- 'key.sublevel' => [{
- file: 'what/file',
- value: 'value'
- }],
- 'key.sublevel2' => [{
- file: 'what/file2',
- value: 'value2'
- }]
+ 'key.sublevel' => {
+ file: 'what/file',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'value' }
+ ]
+ },
+ 'key.sublevel2' => {
+ file: 'what/file2',
+ value: 'value2',
+ overriden: false,
+ found_in: [
+ { file: 'what/file2', value: 'value2' }
+ ]
+ }
}
}
let(:input) {
{
'key' => {
@@ -398,14 +451,18 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with a 3-levels string key-value" do
let(:params) {
{
- 'key.sublevel.subsublevel' => [{
- file: 'what/file',
- value: 'value'
- }]
+ 'key.sublevel.subsublevel' => {
+ file: 'what/file',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'value' }
+ ]
+ }
}
}
let(:input) {
{
'key' => {
@@ -421,18 +478,26 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with a 3-levels double string key-value" do
let(:params) {
{
- 'key.sublevel.subsublevel' => [{
- file: 'what/file',
- value: 'value'
- }],
- 'key2.sublevel' => [{
- file: 'what/file2',
- value: 'value'
- }]
+ 'key.sublevel.subsublevel' => {
+ file: 'what/file',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'value' }
+ ]
+ },
+ 'key2.sublevel' => {
+ file: 'what/file2',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file2', value: 'value' }
+ ]
+ }
}
}
let(:input) {
{
'key' => {
@@ -452,24 +517,27 @@
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
context "with a 3-levels double string key-value and override" do
let(:params) {
{
- 'key.sublevel.subsublevel' => [{
- file: 'what/file',
- value: 'value'
- }],
- 'key2.sublevel' => [
- {
- file: 'what/file2',
- value: 'value'
- },
- {
- file: 'what/file1',
- value: 'value2'
- }
- ]
+ 'key.sublevel.subsublevel' => {
+ file: 'what/file',
+ value: 'value',
+ overriden: false,
+ found_in: [
+ { file: 'what/file', value: 'value' }
+ ]
+ },
+ 'key2.sublevel' => {
+ file: '-',
+ value: 'value',
+ overriden: true,
+ found_in: [
+ { file: 'what/file2', value: 'value' },
+ { file: 'what/file1', value: 'value2' }
+ ]
+ }
}
}
let(:input) {
{
'key' => {
@@ -482,10 +550,10 @@
}
}
}
let(:expected) {
"\nkey: \n sublevel: \n subsublevel: value # what/file" +
- "\nkey2: \n sublevel: value2 # what/file1"
+ "\nkey2: \n sublevel: value2 # what/file2 # what/file1"
}
it { expect(yaml_format.mergetree('', [], input, params)).to eq expected }
end
end