Skip to content

Commit 2cd7adf

Browse files
committed
Adding more tests for Chef::Client
1 parent 7b32970 commit 2cd7adf

3 files changed

Lines changed: 55 additions & 1 deletion

File tree

chef/lib/chef/client.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def run_solo
7979
Chef::Log.info("Starting Chef Solo Run")
8080

8181
build_node
82-
do_attribute_files
8382
converge
8483

8584
end_time = Time.now

chef/spec/unit/client_spec.rb

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,30 @@
9696
@client.should_receive(:converge).and_return(true)
9797
@client.run
9898
end
99+
end
100+
101+
describe Chef::Client, "run_solo" do
102+
before(:each) do
103+
@client = Chef::Client.new
104+
@client.stub!(:build_node).and_return(true)
105+
@client.stub!(:converge).and_return(true)
106+
end
99107

108+
it "should start/top the run timer" do
109+
time = Time.now
110+
Time.should_receive(:now).twice.and_return(time)
111+
@client.run_solo
112+
end
113+
114+
it "should build the node" do
115+
@client.should_receive(:build_node).and_return(true)
116+
@client.run_solo
117+
end
118+
119+
it "should converge the node to the proper state" do
120+
@client.should_receive(:converge).and_return(true)
121+
@client.run_solo
122+
end
100123
end
101124

102125
describe Chef::Client, "build_node" do
@@ -108,17 +131,49 @@
108131
Facter.stub!(:[]).with("fqdn").and_return(@mock_facter_fqdn)
109132
Facter.stub!(:[]).with("hostname").and_return(@mock_facter_hostname)
110133
Facter.stub!(:each).and_return(true)
134+
@node = Chef::Node.new
135+
@mock_rest.stub!(:get_rest).and_return(@node)
136+
Chef::REST.stub!(:new).and_return(@mock_rest)
111137
@client = Chef::Client.new
112138
end
113139

114140
it "should set the name equal to the FQDN" do
141+
@mock_rest.stub!(:get_rest).and_return(nil)
115142
@client.build_node
116143
@client.node.name.should eql("foo.bar.com")
117144
end
118145

119146
it "should set the name equal to the hostname if FQDN is not available" do
120147
@mock_facter_fqdn.stub!(:value).and_return(nil)
148+
@mock_rest.stub!(:get_rest).and_return(nil)
121149
@client.build_node
122150
@client.node.name.should eql("foo")
123151
end
152+
153+
it "should add any json attributes to the node" do
154+
@client.json_attribs = { "one" => "two", "three" => "four" }
155+
@client.build_node
156+
@client.node.one.should eql("two")
157+
@client.node.three.should eql("four")
158+
end
159+
160+
it "should allow you to set recipes from the json attributes" do
161+
@client.json_attribs = { "recipes" => [ "one", "two", "three" ]}
162+
@client.build_node
163+
@client.node.recipes.should eql([ "one", "two", "three" ])
164+
end
165+
166+
it "should not add duplicate recipes from the json attributes" do
167+
@client.node = Chef::Node.new
168+
@client.node.recipes << "one"
169+
@client.json_attribs = { "recipes" => [ "one", "two", "three" ]}
170+
@client.build_node
171+
@client.node.recipes.should eql([ "one", "two", "three" ])
172+
end
173+
end
174+
175+
describe Chef::Client, "register" do
176+
before(:each) do
177+
@mock_rest = mock("Chef::REST", :new => true)
178+
end
124179
end

example-repository/cookbooks/tempfile/files/default/packages/blank

Whitespace-only changes.

0 commit comments

Comments
 (0)