summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/facts
diff options
context:
space:
mode:
authorNick Lewis <nick@puppetlabs.com>2011-03-07 17:28:43 -0800
committerNick Lewis <nick@puppetlabs.com>2011-03-08 15:42:33 -0800
commit880d0c6cbd20758e02848d1fa61966402dc44dc0 (patch)
treeb6807dd90b1eee0359df73d91b7d8d351f0b819f /spec/unit/indirector/facts
parentf83636698229241b2ab35849437f3e515f6ac5c1 (diff)
downloadpuppet-880d0c6cbd20758e02848d1fa61966402dc44dc0.tar.gz
puppet-880d0c6cbd20758e02848d1fa61966402dc44dc0.tar.xz
puppet-880d0c6cbd20758e02848d1fa61966402dc44dc0.zip
(#6338) Support searching on metadata in InventoryActiveRecord terminus
Timestamps are currently the only supported metadata for searching. Paired-With: Max Martin Reviewed-By: Jacob Helwig
Diffstat (limited to 'spec/unit/indirector/facts')
-rw-r--r--spec/unit/indirector/facts/inventory_active_record_spec.rb89
1 files changed, 55 insertions, 34 deletions
diff --git a/spec/unit/indirector/facts/inventory_active_record_spec.rb b/spec/unit/indirector/facts/inventory_active_record_spec.rb
index 7fb55561d..69d614023 100644
--- a/spec/unit/indirector/facts/inventory_active_record_spec.rb
+++ b/spec/unit/indirector/facts/inventory_active_record_spec.rb
@@ -97,54 +97,75 @@ describe "Puppet::Node::Facts::InventoryActiveRecord", :if => (Puppet.features.r
end
describe "#search" do
+ def search_request(conditions)
+ Puppet::Indirector::Request.new(:facts, :search, nil, conditions)
+ end
- it "should return node names that match 'equal' constraints" do
- Puppet::Node::Facts.new("foo", "fact1" => "value1", "fact2" => "value2", "fact3" => "value3").save
- Puppet::Node::Facts.new("bar", "fact1" => "value2").save
- Puppet::Node::Facts.new("baz", "fact1" => "value1", "fact2" => "value1", "fact3" => "value1").save
+ before :each do
+ @now = Time.now
+ @foo = Puppet::Node::Facts.new("foo", "fact1" => "value1", "fact2" => "value2", "uptime_days" => "30")
+ @bar = Puppet::Node::Facts.new("bar", "fact1" => "value1", "uptime_days" => "60")
+ @baz = Puppet::Node::Facts.new("baz", "fact1" => "value2", "fact2" => "value1", "uptime_days" => "90")
+ @bat = Puppet::Node::Facts.new("bat")
+ @foo.timestamp = @now - 3600*1
+ @bar.timestamp = @now - 3600*3
+ @baz.timestamp = @now - 3600*5
+ @bat.timestamp = @now - 3600*7
+ @foo.save
+ @bar.save
+ @baz.save
+ @bat.save
+ end
- request = Puppet::Indirector::Request.new(:facts, :search, nil,
- {'facts.fact1.eq' => 'value1',
- 'facts.fact2.eq' => 'value2',
- 'facts.fact3.eq' => 'value3'})
- terminus.search(request).should =~ ["foo"]
+ it "should return node names that match 'equal' constraints" do
+ request = search_request('facts.fact1.eq' => 'value1',
+ 'facts.fact2.eq' => 'value2')
+ terminus.search(request).should == ["foo"]
end
it "should return node names that match 'not equal' constraints" do
- Puppet::Node::Facts.new("foo", "fact1" => "value1", "fact2" => "value2", "fact3" => "value3").save
- Puppet::Node::Facts.new("bar", "fact1" => "value2").save
- Puppet::Node::Facts.new("baz", "fact1" => "value1", "fact2" => "value1", "fact3" => "value1").save
- Puppet::Node::Facts.new("bang", "fact1" => "value1", "fact2" => "value2", "fact3" => "value1").save
-
- request = Puppet::Indirector::Request.new(:facts, :search, nil,
- {'facts.fact1.ne' => 'value3',
- 'facts.fact2.ne' => 'value1',
- 'facts.fact3.ne' => 'value2'})
- terminus.search(request).should =~ ["foo","bang"]
+ request = search_request('facts.fact1.ne' => 'value2')
+ terminus.search(request).should == ["bar","foo"]
end
it "should return node names that match strict inequality constraints" do
- Puppet::Node::Facts.new("foo", "uptime_days" => "30").save
- Puppet::Node::Facts.new("bar", "uptime_days" => "60").save
- Puppet::Node::Facts.new("baz", "uptime_days" => "90").save
+ request = search_request('facts.uptime_days.gt' => '20',
+ 'facts.uptime_days.lt' => '70')
+ terminus.search(request).should == ["bar","foo"]
+ end
- request = Puppet::Indirector::Request.new(:facts, :search, nil,
- {'facts.uptime_days.gt' => '20',
- 'facts.uptime_days.lt' => '70'})
+ it "should return node names that match non-strict inequality constraints" do
+ request = search_request('facts.uptime_days.ge' => '30',
+ 'facts.uptime_days.le' => '60')
+ terminus.search(request).should == ["bar","foo"]
+ end
- terminus.search(request).should =~ ["foo","bar"]
+ it "should return node names whose facts are within a given timeframe" do
+ request = search_request('meta.timestamp.ge' => @now - 3600*5,
+ 'meta.timestamp.le' => @now - 3600*1)
+ terminus.search(request).should == ["bar","baz","foo"]
end
- it "should return node names that match non-strict inequality constraints" do
- Puppet::Node::Facts.new("foo", "uptime_days" => "30").save
- Puppet::Node::Facts.new("bar", "uptime_days" => "60").save
- Puppet::Node::Facts.new("baz", "uptime_days" => "90").save
+ it "should return node names whose facts are from a specific time" do
+ request = search_request('meta.timestamp.eq' => @now - 3600*3)
+ terminus.search(request).should == ["bar"]
+ end
- request = Puppet::Indirector::Request.new(:facts, :search, nil,
- {'facts.uptime_days.ge' => '30',
- 'facts.uptime_days.le' => '60'})
+ it "should return node names whose facts are not from a specific time" do
+ request = search_request('meta.timestamp.ne' => @now - 3600*1)
+ terminus.search(request).should == ["bar","bat","baz"]
+ end
+
+ it "should perform strict searches on nodes by timestamp" do
+ request = search_request('meta.timestamp.gt' => @now - 3600*5,
+ 'meta.timestamp.lt' => @now - 3600*1)
+ terminus.search(request).should == ["bar"]
+ end
- terminus.search(request).should =~ ["foo","bar"]
+ it "should search nodes based on both facts and timestamp values" do
+ request = search_request('facts.uptime_days.gt' => '45',
+ 'meta.timestamp.lt' => @now - 3600*4)
+ terminus.search(request).should == ["baz"]
end
end
end