spec/lib/node_spec.rb in hieracles-0.3.0 vs spec/lib/node_spec.rb in hieracles-0.3.1
- old
+ new
@@ -15,11 +15,12 @@
context "when extra parameters are specified" do
describe '.new' do
let(:extraoptions) {
options.merge({ params: 'key1=value1;key2=value2' })
}
- let(:node) { Hieracles::Node.new 'server.example.com', extraoptions }
+ let(:config) { Hieracles::Config.new extraoptions }
+ let(:node) { Hieracles::Node.new 'server.example.com', config }
let(:expected) {
{
classes: ['dev'],
fqdn: 'server.example.com',
country: 'fr',
@@ -33,16 +34,18 @@
it { expect(node.hiera_params).to eq expected }
end
end
context "when parameters are not valid" do
- let(:node) { Hieracles::Node.new 'server_not_there.example.com', options }
+ let(:config) { Hieracles::Config.new options }
+ let(:node) { Hieracles::Node.new 'server_not_there.example.com', config }
it { expect{ node }.to raise_error(RuntimeError) }
end
context "when parameters are valid" do
- let(:node) { Hieracles::Node.new 'server.example.com', options }
+ let(:config) { Hieracles::Config.new options }
+ let(:node) { Hieracles::Node.new 'server.example.com', config }
describe '.new' do
let(:expected) {
{
classes: ['dev'],
@@ -76,62 +79,75 @@
it { expect(node.paths).to eq expected }
end
describe '.params' do
let(:expected) {
- [
- [ "another.more_sublevel",
- [{
+ {
+ "another.more_sublevel" =>
+ {
value: "something",
file: 'params/farm/dev.yaml',
- merged: 'something'
- }]
- ],
- [ "another.sublevel.array",
- [
- {
- value: ["one", "two", "three"],
+ overriden: false,
+ found_in: [
+ value: "something",
file: 'params/farm/dev.yaml',
- merged: ["one", "three", "two"]
- },
- {
- value: ["four", "five"],
- file: 'params/nodes/server.example.com.yaml',
- merged: ["five", "four"]
- }
- ]
- ],
- [ "another.sublevel.thing",
- [{
+ ]
+ },
+ "another.sublevel.array" =>
+ {
+ value: ["four", "five"],
+ file: '-',
+ overriden: true,
+ found_in: [
+ {
+ value: ["four", "five"],
+ file: 'params/nodes/server.example.com.yaml'
+ },
+ {
+ value: ["one", "two", "three"],
+ file: 'params/farm/dev.yaml'
+ }
+ ]
+ },
+ "another.sublevel.thing" =>
+ {
value: "always",
file: 'params/nodes/server.example.com.yaml',
- merged: "always"
- }]
- ],
- [ "common_param.subparam",
- [
- {
- value: "override-me",
- file: 'params/farm/dev.yaml',
- merged: "override-me"
- },
- {
- value: "overriden",
+ overriden: false,
+ found_in: [
+ value: "always",
file: 'params/nodes/server.example.com.yaml',
- merged: "overriden"
- }
- ]
- ],
- [ "somefarmparam",
- [{
+ ]
+ },
+ "common_param.subparam" =>
+ {
+ value: "overriden",
+ file: '-',
+ overriden: true,
+ found_in: [
+ {
+ value: "overriden",
+ file: 'params/nodes/server.example.com.yaml'
+ },
+ {
+ value: "override-me",
+ file: 'params/farm/dev.yaml'
+ },
+ ]
+ },
+ "somefarmparam" =>
+ {
value: false,
file: 'params/farm/dev.yaml',
- merged: false
- }]
- ]
- ]
- }
+ overriden: false,
+ found_in: [
+ value: false,
+ file: 'params/farm/dev.yaml',
+ ]
+ }
+ }
+ }
it { expect(node.params).to eq expected }
end
describe '.params_tree' do
let(:expected) {
@@ -162,26 +178,26 @@
}
}
it { expect(node.modules).to eq expected }
end
context "one unfound modules" do
- let(:node) { Hieracles::Node.new 'server2.example.com', options }
+ let(:node) { Hieracles::Node.new 'server2.example.com', config }
let(:expected) {
{
"fake_module" => File.expand_path("spec/files/modules/fake_module"),
"fake_module2" => File.expand_path("spec/files/modules/fake_module2"),
"fake_module4" => nil
}
}
it { expect(node.modules).to eq expected }
end
context "no farm file found" do
- let(:node) { Hieracles::Node.new 'server3.example.com', options }
+ let(:node) { Hieracles::Node.new 'server3.example.com', config }
it { expect { node.modules }.to raise_error(RuntimeError) }
end
context "multiple classes included" do
- let(:node) { Hieracles::Node.new 'server4.example.com', options }
+ let(:node) { Hieracles::Node.new 'server4.example.com', config }
let(:expected) {
{
"fake_module" => File.expand_path("spec/files/modules/fake_module"),
"fake_module2" => File.expand_path("spec/files/modules/fake_module2"),
"fake_module4" => nil,
@@ -230,11 +246,12 @@
Hieracles::Puppetdb::Response.new({ catalog_timestamp: '2015-12-01T23:09:41.540Z'}, 1)
}
let(:resp_facts) {
Hieracles::Puppetdb::Response.new([{ 'name' => 'datacenter', 'value' => 'tahiti' }], 1)
}
- let(:node) { Hieracles::Node.new 'server.example.com', options }
+ let(:config) { Hieracles::Config.new options }
+ let(:node) { Hieracles::Node.new 'server.example.com', config }
before {
allow_any_instance_of(Hieracles::Puppetdb::Client).
to receive(:request).
with("nodes/server.example.com").
and_return(resp_info)
@@ -254,11 +271,12 @@
hierafile: 'hiera_columns.yaml',
encpath: 'enc',
basepath: 'spec/files'
}
}
- let(:node) { Hieracles::Node.new 'server.example.com', options }
+ let(:config) { Hieracles::Config.new options }
+ let(:node) { Hieracles::Node.new 'server.example.com', config }
describe '.files' do
let(:expected) {
[
'params/nodes/server.example.com.yaml',
@@ -277,66 +295,80 @@
hierafile: 'hiera_deep.yaml',
encpath: 'enc',
basepath: 'spec/files'
}
}
- let(:node) { Hieracles::Node.new 'server.example.com', options }
+ let(:config) { Hieracles::Config.new options }
+ let(:node) { Hieracles::Node.new 'server.example.com', config }
describe '.params' do
let(:expected) {
- [
- [ "another.more_sublevel",
- [{
+ {
+ "another.more_sublevel" =>
+ {
value: "something",
file: 'params/farm/dev.yaml',
- merged: "something"
- }]
- ],
- [ "another.sublevel.array",
- [
- {
- value: ["one", "two", "three"],
- file: 'params/farm/dev.yaml',
- merged: ["one", "three", "two"]
- },
- {
- value: ["four", "five"],
- file: 'params/nodes/server.example.com.yaml',
- merged: ["five", "four", "one", "three", "two"]
- }
- ]
- ],
- [ "another.sublevel.thing",
- [{
+ overriden: false,
+ found_in: [
+ value: "something",
+ file: 'params/farm/dev.yaml'
+ ]
+ },
+ "another.sublevel.array" =>
+ {
+ value: ["four", "five", "one", "two", "three"],
+ file: '-',
+ overriden: true,
+ found_in: [
+ {
+ value: ["four", "five"],
+ file: 'params/nodes/server.example.com.yaml'
+ },
+ {
+ value: ["one", "two", "three"],
+ file: 'params/farm/dev.yaml'
+ }
+ ]
+ },
+ "another.sublevel.thing" =>
+ {
value: "always",
file: 'params/nodes/server.example.com.yaml',
- merged: "always"
- }]
- ],
- [ "common_param.subparam",
- [
- {
- value: "override-me",
- file: 'params/farm/dev.yaml',
- merged: "override-me"
- },
- {
- value: "overriden",
- file: 'params/nodes/server.example.com.yaml',
- merged: "overriden"
- }
- ]
- ],
- [ "somefarmparam",
- [{
+ overriden: false,
+ found_in: [
+ value: "always",
+ file: 'params/nodes/server.example.com.yaml'
+ ]
+ },
+ "common_param.subparam" =>
+ {
+ value: "overriden",
+ file: '-',
+ overriden: true,
+ found_in: [
+ {
+ value: "overriden",
+ file: 'params/nodes/server.example.com.yaml'
+ },
+ {
+ value: "override-me",
+ file: 'params/farm/dev.yaml'
+ },
+ ]
+ },
+ "somefarmparam" =>
+ {
value: false,
file: 'params/farm/dev.yaml',
- merged: false
- }]
- ]
- ]
- }
+ overriden: false,
+ found_in: [
+ value: false,
+ file: 'params/farm/dev.yaml',
+ ]
+ }
+ }
+ }
it { expect(node.params).to eq expected }
end
describe '.params_tree' do
let(:expected) {
@@ -367,67 +399,83 @@
hierafile: 'hiera_deeper.yaml',
encpath: 'enc',
basepath: 'spec/files'
}
}
- let(:node) { Hieracles::Node.new 'server.example.com', options }
+ let(:config) { Hieracles::Config.new options }
+ let(:node) { Hieracles::Node.new 'server.example.com', config }
+
describe '.params' do
let(:expected) {
- [
- [ "another.more_sublevel",
- [{
+ {
+ "another.more_sublevel" =>
+ {
value: "something",
file: 'params/farm/dev.yaml',
- merged: "something"
- }]
- ],
- [ "another.sublevel.array",
- [
- {
- value: ["one", "two", "three"],
- file: 'params/farm/dev.yaml',
- merged: ["one", "three", "two"]
- },
- {
- value: ["four", "five"],
- file: 'params/nodes/server.example.com.yaml',
- merged: ["five", "four", "one", "three", "two"]
- }
- ]
- ],
- [ "another.sublevel.thing",
- [{
+ overriden: false,
+ found_in: [
+ value: "something",
+ file: 'params/farm/dev.yaml'
+ ]
+ },
+ "another.sublevel.array" =>
+ {
+ value: ["one", "two", "three", "four", "five"],
+ file: '-',
+ overriden: true,
+ found_in: [
+ {
+ value: ["four", "five"],
+ file: 'params/nodes/server.example.com.yaml'
+ },
+ {
+ value: ["one", "two", "three"],
+ file: 'params/farm/dev.yaml'
+ }
+ ]
+ },
+ "another.sublevel.thing" =>
+ {
value: "always",
file: 'params/nodes/server.example.com.yaml',
- merged: "always"
- }]
- ],
- [ "common_param.subparam",
- [
- {
- value: "override-me",
- file: 'params/farm/dev.yaml',
- merged: "override-me"
- },
- {
- value: "overriden",
- file: 'params/nodes/server.example.com.yaml',
- merged: "overriden"
- }
- ]
- ],
- [ "somefarmparam",
- [{
+ overriden: false,
+ found_in: [
+ value: "always",
+ file: 'params/nodes/server.example.com.yaml'
+ ]
+ },
+ "common_param.subparam" =>
+ {
+ value: "overriden",
+ file: '-',
+ overriden: true,
+ found_in: [
+ {
+ value: "overriden",
+ file: 'params/nodes/server.example.com.yaml'
+ },
+ {
+ value: "override-me",
+ file: 'params/farm/dev.yaml'
+ },
+ ]
+ },
+ "somefarmparam" =>
+ {
value: false,
file: 'params/farm/dev.yaml',
- merged: false
- }]
- ]
- ]
- }
+ overriden: false,
+ found_in: [
+ value: false,
+ file: 'params/farm/dev.yaml',
+ ]
+ }
+ }
+ }
it { expect(node.params).to eq expected }
end
+
describe '.params_tree' do
let(:expected) {
{
"another" => {