summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2010-11-01 13:32:14 -0700
committerPaul Berry <paul@puppetlabs.com>2010-11-01 13:32:14 -0700
commit1f80cc6ed0caadd82171b4fb9fbe117142cd535e (patch)
tree31af46a7eeb88928ae28ce00368636116cb08ccd
parent6c116015ce4a9e6e7de392047f38b7a9e911bc0c (diff)
downloadpuppet-1f80cc6ed0caadd82171b4fb9fbe117142cd535e.tar.gz
puppet-1f80cc6ed0caadd82171b4fb9fbe117142cd535e.tar.xz
puppet-1f80cc6ed0caadd82171b4fb9fbe117142cd535e.zip
Refactored Puppet::Node::Inventory::Yaml tests in preparation for adding freshness check
-rw-r--r--spec/unit/indirector/inventory/yaml_spec.rb30
1 files changed, 9 insertions, 21 deletions
diff --git a/spec/unit/indirector/inventory/yaml_spec.rb b/spec/unit/indirector/inventory/yaml_spec.rb
index 3a7035a9e..a595f8a43 100644
--- a/spec/unit/indirector/inventory/yaml_spec.rb
+++ b/spec/unit/indirector/inventory/yaml_spec.rb
@@ -7,7 +7,7 @@ require 'puppet/indirector/inventory/yaml'
require 'puppet/indirector/request'
describe Puppet::Node::Inventory::Yaml do
- def setup_search_matching(matching, nonmatching, query)
+ def assert_search_matches(matching, nonmatching, query)
request = Puppet::Indirector::Request.new(:inventory, :search, nil, query)
Dir.stubs(:glob).returns(matching.keys + nonmatching.keys)
@@ -16,11 +16,11 @@ describe Puppet::Node::Inventory::Yaml do
YAML.stubs(:load_file).with(key).returns value
end
end
- return matching, request
+ Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return node names that match the search query options" do
- matching, request = setup_search_matching({
+ assert_search_matches({
'/path/to/matching.yaml' => Puppet::Node::Facts.new("matchingnode", "architecture" => "i386", 'processor_count' => '4'),
'/path/to/matching1.yaml' => Puppet::Node::Facts.new("matchingnode1", "architecture" => "i386", 'processor_count' => '4', 'randomfact' => 'foo')
},
@@ -32,11 +32,10 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.architecture' => 'i386', 'facts.processor_count' => '4'}
)
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return empty array when no nodes match the search query options" do
- matching, request = setup_search_matching({}, {
+ assert_search_matches({}, {
"/path/to/nonmatching.yaml" => Puppet::Node::Facts.new("nonmatchingnode", "architecture" => "powerpc", 'processor_count' => '10'),
"/path/to/nonmatching1.yaml" => Puppet::Node::Facts.new("nonmatchingnode1", "architecture" => "powerpc", 'processor_count' => '5'),
"/path/to/nonmatching2.yaml" => Puppet::Node::Facts.new("nonmatchingnode2", "architecture" => "i386", 'processor_count' => '5'),
@@ -44,12 +43,11 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.processor_count.lt' => '4', 'facts.processor_count.gt' => '4'}
)
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return node names that match the search query options with the greater than operator" do
- matching, request = setup_search_matching({
+ assert_search_matches({
'/path/to/matching.yaml' => Puppet::Node::Facts.new("matchingnode", "architecture" => "i386", 'processor_count' => '5'),
'/path/to/matching1.yaml' => Puppet::Node::Facts.new("matchingnode1", "architecture" => "powerpc", 'processor_count' => '10', 'randomfact' => 'foo')
},
@@ -60,12 +58,10 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.processor_count.gt' => '4'}
)
-
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return node names that match the search query options with the less than operator" do
- matching, request = setup_search_matching({
+ assert_search_matches({
'/path/to/matching.yaml' => Puppet::Node::Facts.new("matchingnode", "architecture" => "i386", 'processor_count' => '5'),
'/path/to/matching1.yaml' => Puppet::Node::Facts.new("matchingnode1", "architecture" => "powerpc", 'processor_count' => '30', 'randomfact' => 'foo')
},
@@ -76,12 +72,10 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.processor_count.lt' => '50'}
)
-
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return node names that match the search query options with the less than or equal to operator" do
- matching, request = setup_search_matching({
+ assert_search_matches({
'/path/to/matching.yaml' => Puppet::Node::Facts.new("matchingnode", "architecture" => "i386", 'processor_count' => '5'),
'/path/to/matching1.yaml' => Puppet::Node::Facts.new("matchingnode1", "architecture" => "powerpc", 'processor_count' => '50', 'randomfact' => 'foo')
},
@@ -92,12 +86,10 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.processor_count.le' => '50'}
)
-
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return node names that match the search query options with the greater than or equal to operator" do
- matching, request = setup_search_matching({
+ assert_search_matches({
'/path/to/matching.yaml' => Puppet::Node::Facts.new("matchingnode", "architecture" => "i386", 'processor_count' => '100'),
'/path/to/matching1.yaml' => Puppet::Node::Facts.new("matchingnode1", "architecture" => "powerpc", 'processor_count' => '50', 'randomfact' => 'foo')
},
@@ -108,12 +100,10 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.processor_count.ge' => '50'}
)
-
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
it "should return node names that match the search query options with the not equal operator" do
- matching, request = setup_search_matching({
+ assert_search_matches({
'/path/to/matching.yaml' => Puppet::Node::Facts.new("matchingnode", "architecture" => 'arm' ),
'/path/to/matching1.yaml' => Puppet::Node::Facts.new("matchingnode1", "architecture" => 'powerpc', 'randomfact' => 'foo')
},
@@ -124,7 +114,5 @@ describe Puppet::Node::Inventory::Yaml do
},
{'facts.architecture.ne' => 'i386'}
)
-
- Puppet::Node::Inventory::Yaml.new.search(request).should =~ matching.values.map {|facts| facts.name}
end
end