|
128 | 128 | @provider.action_create |
129 | 129 | end |
130 | 130 |
|
131 | | - it "should update the cron entry if it exists" do |
| 131 | + it "should update the cron entry if it exists and has changed" do |
132 | 132 | @status = mock("Status", :exitstatus => 0) |
133 | 133 | @stdin = mock("STDIN", :null_object => true) |
134 | 134 | @stdout = mock("STDOUT", :null_object => true) |
|
142 | 142 | @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
143 | 143 | Chef::Log.should_receive(:info).with("Updated cron '#{@new_resource.name}'") |
144 | 144 | @provider.action_create |
| 145 | + end |
| 146 | + |
| 147 | + it "should not update the cron entry if it exists and has not changed" do |
| 148 | + resource = mock("Chef::Resource::Cron", |
| 149 | + :null_object => true, |
| 150 | + :name => "foo", |
| 151 | + :minute => "30", |
| 152 | + :hour => "*", |
| 153 | + :day => "*", |
| 154 | + :month => "*", |
| 155 | + :weekday => "*", |
| 156 | + :command => "/bin/true" |
| 157 | + ) |
| 158 | + provider = Chef::Provider::Cron.new(@node, resource) |
145 | 159 |
|
| 160 | + |
| 161 | + @status = mock("Status", :exitstatus => 0) |
| 162 | + @stdin = mock("STDIN", :null_object => true) |
| 163 | + @stdout = mock("STDOUT", :null_object => true) |
| 164 | + @stderr = mock("STDERR", :null_object => true) |
| 165 | + @pid = mock("PID", :null_object => true) |
| 166 | + @stdout.stub!(:each_line).and_yield("# Chef Name: bar"). |
| 167 | + and_yield("* 10 * * * /bin/false"). |
| 168 | + and_yield("# Chef Name: foo\n"). |
| 169 | + and_yield("30 * * * * /bin/true\n") |
| 170 | + provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 171 | + Chef::Log.should_not_receive(:info).with("Updated cron '#{@new_resource.name}'") |
| 172 | + Chef::Log.should_receive(:debug).with("Skipping existing cron entry '#{@new_resource.name}'") |
| 173 | + provider.cron_exists = true |
| 174 | + provider.action_create |
146 | 175 | end |
147 | 176 | end |
148 | 177 |
|
|
0 commit comments