diff options
Diffstat (limited to 'spec/unit')
-rwxr-xr-x | spec/unit/indirector/facts/yaml.rb | 4 | ||||
-rwxr-xr-x | spec/unit/indirector/indirector.rb | 15 | ||||
-rwxr-xr-x | spec/unit/indirector/node/external.rb | 22 | ||||
-rwxr-xr-x | spec/unit/indirector/node/ldap.rb | 16 | ||||
-rwxr-xr-x | spec/unit/indirector/node/none.rb | 8 | ||||
-rwxr-xr-x | spec/unit/node/facts.rb | 11 | ||||
-rwxr-xr-x | spec/unit/node/node.rb | 8 | ||||
-rwxr-xr-x | spec/unit/node/searching.rb | 16 |
8 files changed, 53 insertions, 47 deletions
diff --git a/spec/unit/indirector/facts/yaml.rb b/spec/unit/indirector/facts/yaml.rb index 176a47f04..49b361a95 100755 --- a/spec/unit/indirector/facts/yaml.rb +++ b/spec/unit/indirector/facts/yaml.rb @@ -23,7 +23,7 @@ describe Puppet::Indirector.terminus(:facts, :yaml), " when managing facts" do it "should store facts in YAML in the yamlfactdir" do values = {"one" => "two", "three" => "four"} facts = Puppet::Node::Facts.new("node", values) - @store.post(facts) + @store.save(facts) # Make sure the file exists path = File.join(Puppet[:yamlfactdir], facts.name) + ".yaml" @@ -47,7 +47,7 @@ describe Puppet::Indirector.terminus(:facts, :yaml), " when managing facts" do f.print values.to_yaml end - facts = Puppet::Node::Facts.get('node') + facts = Puppet::Node::Facts.find('node') facts.should be_instance_of(Puppet::Node::Facts) # We iterate over them, because the store might add extra values. diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb index 78f1c7f73..b5a70cd8f 100755 --- a/spec/unit/indirector/indirector.rb +++ b/spec/unit/indirector/indirector.rb @@ -41,6 +41,9 @@ describe Puppet::Indirector, "when registering an indirection" do extend Puppet::Indirector end Puppet::Indirector.stubs(:terminus_for_indirection).returns(:ldap) + @terminus = mock 'terminus' + @terminus_class = stub 'terminus class', :new => @terminus + Puppet::Indirector.stubs(:terminus).returns(@terminus_class) end it "should require a name when registering a model" do @@ -81,11 +84,12 @@ describe Puppet::Indirector, "when registering an indirection" do end it "should provide a way to get a handle to the terminus for a model" do - mock_terminus = mock('Terminus') Puppet::Indirector.expects(:terminus_for_indirection).with(:node).returns(:ldap) - Puppet::Indirector.expects(:terminus).returns(mock_terminus) + terminus = mock 'terminus' + terminus_class = stub 'terminus class', :new => terminus + Puppet::Indirector.expects(:terminus).returns(terminus_class) @thingie.send(:indirects, :node) - @thingie.indirection.should == mock_terminus + @thingie.indirection.should == terminus end it "should list the model in a list of known indirections" do @@ -100,9 +104,10 @@ describe Puppet::Indirector, "when registering an indirection" do end it "should use the collection type described in the per-model configuration" do - mock_terminus = mock('Terminus') + terminus = mock 'terminus' + terminus_class = stub 'terminus class', :new => terminus Puppet::Indirector.expects(:terminus_for_indirection).with(:foo).returns(:bar) - Puppet::Indirector.expects(:terminus).with(:foo, :bar).returns(mock_terminus) + Puppet::Indirector.expects(:terminus).with(:foo, :bar).returns(terminus_class) @thingie.send(:indirects, :foo) end diff --git a/spec/unit/indirector/node/external.rb b/spec/unit/indirector/node/external.rb index 30b2f74c2..c64a6f6e2 100755 --- a/spec/unit/indirector/node/external.rb +++ b/spec/unit/indirector/node/external.rb @@ -32,32 +32,32 @@ describe Puppet::Indirector.terminus(:node, :external), " when searching for nod it "should throw an exception if the node_source is external but no external node command is set" do Puppet[:external_nodes] = "none" - proc { @searcher.get("foo") }.should raise_error(ArgumentError) + proc { @searcher.find("foo") }.should raise_error(ArgumentError) end it "should throw an exception if the external node source is not fully qualified" do Puppet[:external_nodes] = "mycommand" - proc { @searcher.get("foo") }.should raise_error(ArgumentError) + proc { @searcher.find("foo") }.should raise_error(ArgumentError) end it "should execute the command with the node name as the only argument" do command = [Puppet[:external_nodes], "yay"] @searcher.expects(:execute).with(command).returns("") - @searcher.get("yay") + @searcher.find("yay") end it "should return a node object" do - @searcher.get("apple").should be_instance_of(Puppet::Node) + @searcher.find("apple").should be_instance_of(Puppet::Node) end it "should set the node's name" do - @searcher.get("apple").name.should == "apple" + @searcher.find("apple").name.should == "apple" end # If we use a name that has a 'p' but no 'a', then our test generator # will return classes but no parameters. it "should be able to configure a node's classes" do - node = @searcher.get("plum") + node = @searcher.find("plum") node.classes.should == %w{plum1 plum2 plum3} node.parameters.should == {} end @@ -65,26 +65,26 @@ describe Puppet::Indirector.terminus(:node, :external), " when searching for nod # If we use a name that has an 'a' but no 'p', then our test generator # will return parameters but no classes. it "should be able to configure a node's parameters" do - node = @searcher.get("guava") + node = @searcher.find("guava") node.classes.should == [] node.parameters.should == {"one" => "guava1", "two" => "guava2"} end it "should be able to configure a node's classes and parameters" do - node = @searcher.get("apple") + node = @searcher.find("apple") node.classes.should == %w{apple1 apple2 apple3} node.parameters.should == {"one" => "apple1", "two" => "apple2"} end it "should merge node facts with returned parameters" do facts = Puppet::Node::Facts.new("apple", "three" => "four") - Puppet::Node::Facts.expects(:get).with("apple").returns(facts) - node = @searcher.get("apple") + Puppet::Node::Facts.expects(:find).with("apple").returns(facts) + node = @searcher.find("apple") node.parameters["three"].should == "four" end it "should return nil when it cannot find the node" do - @searcher.get("honeydew").should be_nil + @searcher.find("honeydew").should be_nil end # Make sure a nodesearch with arguments works diff --git a/spec/unit/indirector/node/ldap.rb b/spec/unit/indirector/node/ldap.rb index c6eb45ffc..e4b0cd7d4 100755 --- a/spec/unit/indirector/node/ldap.rb +++ b/spec/unit/indirector/node/ldap.rb @@ -20,33 +20,33 @@ describe Puppet::Indirector.terminus(:node, :ldap), " when searching for nodes" end it "should return nil for hosts that cannot be found" do - @searcher.get("foo").should be_nil + @searcher.find("foo").should be_nil end it "should return Puppet::Node instances" do @nodetable["foo"] = [nil, %w{}, {}] - @searcher.get("foo").should be_instance_of(Puppet::Node) + @searcher.find("foo").should be_instance_of(Puppet::Node) end it "should set the node name" do @nodetable["foo"] = [nil, %w{}, {}] - @searcher.get("foo").name.should == "foo" + @searcher.find("foo").name.should == "foo" end it "should set the classes" do @nodetable["foo"] = [nil, %w{one two}, {}] - @searcher.get("foo").classes.should == %w{one two} + @searcher.find("foo").classes.should == %w{one two} end it "should set the parameters" do @nodetable["foo"] = [nil, %w{}, {"one" => "two"}] - @searcher.get("foo").parameters.should == {"one" => "two"} + @searcher.find("foo").parameters.should == {"one" => "two"} end it "should set classes and parameters from the parent node" do @nodetable["foo"] = ["middle", %w{one two}, {"one" => "two"}] @nodetable["middle"] = [nil, %w{three four}, {"three" => "four"}] - node = @searcher.get("foo") + node = @searcher.find("foo") node.classes.sort.should == %w{one two three four}.sort node.parameters.should == {"one" => "two", "three" => "four"} end @@ -54,14 +54,14 @@ describe Puppet::Indirector.terminus(:node, :ldap), " when searching for nodes" it "should prefer child parameters to parent parameters" do @nodetable["foo"] = ["middle", %w{}, {"one" => "two"}] @nodetable["middle"] = [nil, %w{}, {"one" => "four"}] - @searcher.get("foo").parameters["one"].should == "two" + @searcher.find("foo").parameters["one"].should == "two" end it "should recurse indefinitely through parent relationships" do @nodetable["foo"] = ["middle", %w{one two}, {"one" => "two"}] @nodetable["middle"] = ["top", %w{three four}, {"three" => "four"}] @nodetable["top"] = [nil, %w{five six}, {"five" => "six"}] - node = @searcher.get("foo") + node = @searcher.find("foo") node.parameters.should == {"one" => "two", "three" => "four", "five" => "six"} node.classes.sort.should == %w{one two three four five six}.sort end diff --git a/spec/unit/indirector/node/none.rb b/spec/unit/indirector/node/none.rb index d52d7ca83..2329cdfbb 100755 --- a/spec/unit/indirector/node/none.rb +++ b/spec/unit/indirector/node/none.rb @@ -11,17 +11,17 @@ describe Puppet::Indirector.terminus(:node, :none), " when searching for nodes" end it "should create a node instance" do - @searcher.get("yay").should be_instance_of(Puppet::Node) + @searcher.find("yay").should be_instance_of(Puppet::Node) end it "should create a new node with the correct name" do - @searcher.get("yay").name.should == "yay" + @searcher.find("yay").name.should == "yay" end it "should merge the node's facts" do facts = Puppet::Node::Facts.new("yay", "one" => "two", "three" => "four") - Puppet::Node::Facts.expects(:get).with("yay").returns(facts) - node = @searcher.get("yay") + Puppet::Node::Facts.expects(:find).with("yay").returns(facts) + node = @searcher.find("yay") node.parameters["one"].should == "two" node.parameters["three"].should == "four" end diff --git a/spec/unit/node/facts.rb b/spec/unit/node/facts.rb index c677c1d2e..61f05a2b2 100755 --- a/spec/unit/node/facts.rb +++ b/spec/unit/node/facts.rb @@ -7,21 +7,22 @@ require 'puppet/node/facts' describe Puppet::Node::Facts, " when indirecting" do before do @terminus = mock 'terminus' - Puppet::Indirector.terminus(:facts, Puppet[:fact_store].intern).stubs(:new).returns(@terminus) + Puppet::Node::Facts.stubs(:indirection).returns(@terminus) # We have to clear the cache so that the facts ask for our terminus stub, # instead of anything that might be cached. Puppet::Indirector::Indirection.clear_cache + @facts = Puppet::Node::Facts.new("me", "one" => "two") end it "should redirect to the specified fact store for retrieval" do - @terminus.expects(:get).with(:my_facts) - Puppet::Node::Facts.get(:my_facts) + @terminus.expects(:find).with(:my_facts) + Puppet::Node::Facts.find(:my_facts) end it "should redirect to the specified fact store for storage" do - @terminus.expects(:post).with(:my_facts) - Puppet::Node::Facts.post(:my_facts) + @terminus.expects(:save).with(@facts) + @facts.save end after do diff --git a/spec/unit/node/node.rb b/spec/unit/node/node.rb index 9342dc5ce..899d81ac7 100755 --- a/spec/unit/node/node.rb +++ b/spec/unit/node/node.rb @@ -85,7 +85,7 @@ end describe Puppet::Node, " when merging facts" do before do @node = Puppet::Node.new("testnode") - Puppet::Node::Facts.stubs(:get).with(@node.name).returns(Puppet::Node::Facts.new(@node.name, "one" => "c", "two" => "b")) + Puppet::Node::Facts.stubs(:find).with(@node.name).returns(Puppet::Node::Facts.new(@node.name, "one" => "c", "two" => "b")) end it "should prefer parameters already set on the node over facts from the node" do @@ -110,12 +110,12 @@ end describe Puppet::Node, " when indirecting" do before do @terminus = mock 'terminus' - Puppet::Indirector.terminus(:node, Puppet[:node_source]).stubs(:new).returns(@terminus) + Puppet::Node.stubs(:indirection).returns(@terminus) end it "should redirect to the specified node source" do - @terminus.expects(:get).with(:my_node) - Puppet::Node.get(:my_node) + @terminus.expects(:find).with(:my_node.to_s) + Puppet::Node.find(:my_node.to_s) end after do diff --git a/spec/unit/node/searching.rb b/spec/unit/node/searching.rb index 553822576..b7105050a 100755 --- a/spec/unit/node/searching.rb +++ b/spec/unit/node/searching.rb @@ -10,12 +10,12 @@ describe Puppet::Node::Searching, " when searching for nodes" do @searcher.extend(Puppet::Node::Searching) @facts = Puppet::Node::Facts.new("foo", "hostname" => "yay", "domain" => "domain.com") @node = Puppet::Node.new("foo") - Puppet::Node::Facts.stubs(:get).with("foo").returns(@facts) + Puppet::Node::Facts.stubs(:find).with("foo").returns(@facts) end it "should search for the node by its key first" do names = [] - @searcher.expects(:get).with do |name| + @searcher.expects(:find).with do |name| names << name names == %w{foo} end.returns(@node) @@ -24,15 +24,15 @@ describe Puppet::Node::Searching, " when searching for nodes" do it "should return the first node found using the generated list of names" do names = [] - @searcher.expects(:get).with("foo").returns(nil) - @searcher.expects(:get).with("yay.domain.com").returns(@node) + @searcher.expects(:find).with("foo").returns(nil) + @searcher.expects(:find).with("yay.domain.com").returns(@node) @searcher.search("foo").should equal(@node) end it "should search for the rest of the names inversely by length" do names = [] @facts.values["fqdn"] = "longer.than.the.normal.fqdn.com" - @searcher.stubs(:get).with do |name| + @searcher.stubs(:find).with do |name| names << name end @searcher.search("foo") @@ -51,7 +51,7 @@ describe Puppet::Node::Searching, " when searching for nodes" do it "should attempt to find a default node if no names are found" do names = [] - @searcher.stubs(:get).with do |name| + @searcher.stubs(:find).with do |name| names << name end.returns(nil) @searcher.search("foo") @@ -59,7 +59,7 @@ describe Puppet::Node::Searching, " when searching for nodes" do end it "should cache the nodes" do - @searcher.expects(:get).with("foo").returns(@node) + @searcher.expects(:find).with("foo").returns(@node) @searcher.search("foo").should equal(@node) @searcher.search("foo").should equal(@node) end @@ -68,7 +68,7 @@ describe Puppet::Node::Searching, " when searching for nodes" do node2 = Puppet::Node.new("foo2") Puppet[:filetimeout] = -1 # I couldn't get this to work with :expects - @searcher.stubs(:get).returns(@node, node2).then.raises(ArgumentError) + @searcher.stubs(:find).returns(@node, node2).then.raises(ArgumentError) @searcher.search("foo").should equal(@node) @searcher.search("foo").should equal(node2) end |