diff options
author | Adam Jacob <adam@hjksolutions.com> | 2008-04-08 00:57:17 -0700 |
---|---|---|
committer | Adam Jacob <adam@hjksolutions.com> | 2008-04-08 00:57:17 -0700 |
commit | 95eb1375f0647accd1b1a1569a7d0e3acc4a61e4 (patch) | |
tree | a58d6fddde4d7818dc33511ff8275c7b9f69f1c6 /spec/unit/node_spec.rb | |
parent | 434f25ba07b5c0c50baa1e15b14a945bba3c3c3b (diff) | |
download | chef-95eb1375f0647accd1b1a1569a7d0e3acc4a61e4.tar.gz |
Adding chef-solo command, config examples, Chef::Log class, Chef::Log::Formatter, Chef::Compile, and all the tests
Diffstat (limited to 'spec/unit/node_spec.rb')
-rw-r--r-- | spec/unit/node_spec.rb | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index a8c456e8f5..c72aea0b7d 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -22,6 +22,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "spec_helper")) describe Chef::Node do before(:each) do + Chef::Config.node_path(File.join(File.dirname(__FILE__), "..", "data", "nodes")) @node = Chef::Node.new() end @@ -56,6 +57,11 @@ describe Chef::Node do @node["secret"].should eql(nil) end + it "should allow you to set an attribute via node[]=" do + @node["secret"] = "shush" + @node["secret"].should eql("shush") + end + it "should allow you to query whether an attribute exists with attribute?" do @node.attribute["locust"] = "something" @node.attribute?("locust").should eql(true) @@ -94,7 +100,7 @@ describe Chef::Node do it "should load a node from a ruby file" do @node.from_file(File.join(File.dirname(__FILE__), "..", "data", "nodes", "test.rb")) - @node.name.should eql("ops1prod") + @node.name.should eql("test.example.com short") @node.sunshine.should eql("in") @node.something.should eql("else") @node.recipes.should eql(["operations-master", "operations-monitoring"]) @@ -116,5 +122,53 @@ describe Chef::Node do seen_attributes[:sunshine].should == "is bright" seen_attributes[:canada].should == "is a nice place" end + + it "should load a node from a file by fqdn" do + node = Chef::Node.find("test.example.com") + node.name.should == "test.example.com" + end + + it "should load a node from a file by hostname" do + File.stub!(:exists?).and_return(true) + File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) + node = Chef::Node.find("test.example.com") + node.name.should == "test.example.com short" + end + + it "should load a node from the default file" do + File.stub!(:exists?).and_return(true) + File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) + File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false) + node = Chef::Node.find("test.example.com") + node.name.should == "test.example.com default" + end + + it "should raise an ArgumentError if it cannot find any node file at all" do + File.stub!(:exists?).and_return(true) + File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.example.com.rb")).and_return(false) + File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "test.rb")).and_return(false) + File.should_receive(:exists?).with(File.join(Chef::Config[:node_path], "default.rb")).and_return(false) + lambda { Chef::Node.find("test.example.com") }.should raise_error(ArgumentError) + end + + it "should serialize itself as json" do + node = Chef::Node.find("test.example.com") + json = node.to_json + result = JSON.load(json) + result["name"].should == "test.example.com" + result["type"].should == "Chef::Node" + result["attributes"]["something"].should == "else" + result["attributes"]["sunshine"].should == "in" + result["recipes"].detect { |r| r == "operations-master" }.should == "operations-master" + result["recipes"].detect { |r| r == "operations-monitoring" }.should == "operations-monitoring" + end + + it "should return a list of node names based on which files are in the node_path" do + list = Chef::Node.list + list.should be_a_kind_of(Array) + list[0].should == "default" + list[1].should == "test.example.com" + list[2].should == "test" + end end
\ No newline at end of file |