diff options
| author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-07-28 19:37:11 +0200 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-08-01 11:15:29 +1000 |
| commit | b45ccf8d38a10d3f5226cbabe494240901e4e383 (patch) | |
| tree | 9e5e8bbbd88ce7f66dc5a42c6aa7c2c6c57e7b4e /spec/unit/parser/loaded_code.rb | |
| parent | 58a73b5c68485dc5d41a46936c31e5fad5f037b5 (diff) | |
| download | puppet-b45ccf8d38a10d3f5226cbabe494240901e4e383.tar.gz puppet-b45ccf8d38a10d3f5226cbabe494240901e4e383.tar.xz puppet-b45ccf8d38a10d3f5226cbabe494240901e4e383.zip | |
Implement node matching with regexes
This patch enhance AST::HostName to support regexes, and modifies
the parser to allow regex to be used as node name.
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>]
Diffstat (limited to 'spec/unit/parser/loaded_code.rb')
| -rw-r--r-- | spec/unit/parser/loaded_code.rb | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/spec/unit/parser/loaded_code.rb b/spec/unit/parser/loaded_code.rb index d33bda9a9..4bfd119f5 100644 --- a/spec/unit/parser/loaded_code.rb +++ b/spec/unit/parser/loaded_code.rb @@ -129,10 +129,18 @@ describe Puppet::Parser::LoadedCode do end describe "when finding nodes" do + before :each do + @loader = Puppet::Parser::LoadedCode.new + + @nodename1 = stub 'nodename1', :is_a? => true + @node1 = stub 'node1' + @nodename2 = stub 'nodename2', :is_a? => true + @node2 = stub 'node2' + end it "should create an HostName if nodename is a string" do Puppet::Parser::AST::HostName.expects(:new).with(:value => "foo") - loader = Puppet::Parser::LoadedCode.new - loader.node("foo") + + @loader.node("foo") end it "should not create an HostName if nodename is an HostName" do @@ -140,17 +148,50 @@ describe Puppet::Parser::LoadedCode do Puppet::Parser::AST::HostName.expects(:new).with(:value => "foo").never - loader = Puppet::Parser::LoadedCode.new - loader.node(name) + @loader.node(name) end it "should be able to find nobe by HostName" do namein = Puppet::Parser::AST::HostName.new(:value => "foo") nameout = Puppet::Parser::AST::HostName.new(:value => "foo") - loader = Puppet::Parser::LoadedCode.new - loader.add_node(namein, "bar") - loader.node(nameout) == "bar" + @loader.add_node(namein, "bar") + @loader.node(nameout) == "bar" + end + + it "should return the first matching regex nodename" do + @nodename1.stubs(:regex?).returns(true) + @nodename1.expects(:match).returns(true) + @nodename2.stubs(:regex?).returns(false) + + @loader.add_node(@nodename1, @node1) + @loader.add_node(@nodename2, @node2) + + @loader.node("test").should == @node1 + end + + it "should not scan non-regex node" do + @nodename1.stubs(:regex?).returns(true) + @nodename1.stubs(:match).returns(false) + @nodename2.stubs(:regex?).returns(false) + @nodename2.expects(:match).never + + @loader.add_node(@nodename1,@node1) + @loader.add_node(@nodename2,@node2) + + @loader.node("test") + end + + it "should prefer non-regex nodes to regex nodes" do + @nodename1.stubs(:regex?).returns(false) + @nodename1.expects(:match).never + @nodename2.stubs(:regex?).returns(true) + @nodename2.expects(:match).never + + @loader.add_node(@nodename1,@node1) + @loader.add_node(@nodename2,@node2) + + @loader.node(@nodename1) end end end |
