blob: 2eaf3c12e47023a5d870e0d0a6b02e277362c963 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/exec/node'
describe Puppet::Indirector::Exec::Node, " when constructing the command to run" do
before do
@indirection = mock 'indirection'
Puppet.config.stubs(:value).with(:external_nodes).returns("/echo")
@searcher = Puppet::Indirector::Exec::Node.new
end
it "should use the external_node script as the command" do
Puppet.expects(:[]).with(:external_nodes).returns("/bin/echo")
@searcher.command.should == %w{/bin/echo}
end
it "should throw an exception if no external node command is set" do
Puppet.expects(:[]).with(:external_nodes).returns("none")
proc { @searcher.find("foo") }.should raise_error(ArgumentError)
end
end
describe Puppet::Indirector::Exec::Node, " when handling the results of the command" do
before do
@indirection = mock 'indirection'
Puppet.config.stubs(:value).with(:external_nodes).returns("/echo")
@searcher = Puppet::Indirector::Exec::Node.new
@node = stub 'node', :fact_merge => nil
@name = "yay"
Puppet::Node.expects(:new).with(@name).returns(@node)
@result = {}
# Use a local variable so the reference is usable in the execute() definition.
result = @result
@searcher.meta_def(:execute) do |command|
return YAML.dump(result)
end
end
it "should translate the YAML into a Node instance" do
# Use an empty hash
@searcher.find(@name).should equal(@node)
end
it "should set the resulting parameters as the node parameters" do
@result[:parameters] = {"a" => "b", "c" => "d"}
@node.expects(:parameters=).with "a" => "b", "c" => "d"
@searcher.find(@name)
end
it "should set the resulting classes as the node classes" do
@result[:classes] = %w{one two}
@node.expects(:classes=).with %w{one two}
@searcher.find(@name)
end
it "should merge the node's facts with its parameters" do
@node.expects(:fact_merge)
@searcher.find(@name)
end
end
|