|
96 | 96 | @client.should_receive(:converge).and_return(true) |
97 | 97 | @client.run |
98 | 98 | 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 |
99 | 107 |
|
| 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 |
100 | 123 | end |
101 | 124 |
|
102 | 125 | describe Chef::Client, "build_node" do |
|
108 | 131 | Facter.stub!(:[]).with("fqdn").and_return(@mock_facter_fqdn) |
109 | 132 | Facter.stub!(:[]).with("hostname").and_return(@mock_facter_hostname) |
110 | 133 | 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) |
111 | 137 | @client = Chef::Client.new |
112 | 138 | end |
113 | 139 |
|
114 | 140 | it "should set the name equal to the FQDN" do |
| 141 | + @mock_rest.stub!(:get_rest).and_return(nil) |
115 | 142 | @client.build_node |
116 | 143 | @client.node.name.should eql("foo.bar.com") |
117 | 144 | end |
118 | 145 |
|
119 | 146 | it "should set the name equal to the hostname if FQDN is not available" do |
120 | 147 | @mock_facter_fqdn.stub!(:value).and_return(nil) |
| 148 | + @mock_rest.stub!(:get_rest).and_return(nil) |
121 | 149 | @client.build_node |
122 | 150 | @client.node.name.should eql("foo") |
123 | 151 | 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 |
124 | 179 | end |
0 commit comments