|
26 | 26 | File.stub!(:read).and_return("monkeypoop") |
27 | 27 | @rest.stub!(:get_rest).and_return(@tempfile) |
28 | 28 | @resource = Chef::Resource::Template.new("seattle") |
| 29 | + @resource.cookbook_name = "foo" |
29 | 30 | @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) |
30 | 31 | @resource.source("http://foo") |
31 | 32 | @node = Chef::Node.new |
|
35 | 36 | @provider.current_resource = @resource.clone |
36 | 37 | @provider.current_resource.checksum("dad86c61eea237932f201009e5431609") |
37 | 38 | FileUtils.stub!(:cp).and_return(true) |
| 39 | + Chef::FileCache.stub!(:has_key).and_return(false) |
| 40 | + Chef::FileCache.stub!(:move_to).and_return(true) |
| 41 | + Chef::FileCache.stub!(:load).and_return("monkeypoop") |
38 | 42 | end |
39 | 43 |
|
40 | 44 | def do_action_create |
@@ -82,6 +86,50 @@ def do_action_create |
82 | 86 | @provider.should_receive(:set_mode).and_return(true) |
83 | 87 | do_action_create |
84 | 88 | end |
| 89 | + |
| 90 | + it "should build a checksum of the file in the cache (assuming it exists)" do |
| 91 | + Chef::FileCache.stub!(:has_key?).and_return(true) |
| 92 | + Chef::FileCache.stub!(:load).and_return("/some/path") |
| 93 | + @provider.should_receive(:checksum).with("/some/path") |
| 94 | + do_action_create |
| 95 | + end |
| 96 | + |
| 97 | + it "should not update the filecache if the template has not been modified on the server" do |
| 98 | + error_response = mock("Net::HTTPNotModified", { :kind_of? => true }) |
| 99 | + @rest.stub!(:get_rest).and_raise(Net::HTTPRetriableError.new("foo", error_response)) |
| 100 | + Chef::FileCache.should_not_receive(:move_to) |
| 101 | + do_action_create |
| 102 | + end |
| 103 | + |
| 104 | + it "should raise an exception if we get a Net::HTTPRetriableError that is not from a NotModified response" do |
| 105 | + error_response = mock("Net::HTTPNotModified", { :kind_of? => false }) |
| 106 | + @rest.stub!(:get_rest).and_raise(Net::HTTPRetriableError.new("foo", error_response)) |
| 107 | + lambda { do_action_create }.should raise_error(Net::HTTPRetriableError) |
| 108 | + end |
| 109 | + |
| 110 | +end |
| 111 | + |
| 112 | +describe Chef::Provider::Template, "action_create_if_missing" do |
| 113 | + before(:each) do |
| 114 | + @resource = Chef::Resource::Template.new("seattle") |
| 115 | + @resource.cookbook_name = "daft" |
| 116 | + @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt")) |
| 117 | + @node = Chef::Node.new |
| 118 | + @node.name "latte" |
| 119 | + @provider = Chef::Provider::Template.new(@node, @resource) |
| 120 | + end |
| 121 | + |
| 122 | + it "should not call action_create if the new resources path exists" do |
| 123 | + File.stub!(:exists?).and_return(true) |
| 124 | + @provider.should_not_receive(:action_create) |
| 125 | + @provider.action_create_if_missing |
| 126 | + end |
| 127 | + |
| 128 | + it "should call action create if the new resource path does not exist" do |
| 129 | + File.stub!(:exists?).and_return(false) |
| 130 | + @provider.should_receive(:action_create).and_return(true) |
| 131 | + @provider.action_create_if_missing |
| 132 | + end |
85 | 133 | end |
86 | 134 |
|
87 | 135 | describe Chef::Provider::Template, "generate_url" do |
|
0 commit comments