diff options
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/formatters/doc_spec.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/remote_file/http_spec.rb | 21 |
2 files changed, 35 insertions, 0 deletions
diff --git a/spec/unit/formatters/doc_spec.rb b/spec/unit/formatters/doc_spec.rb index e9bff0759d..b8eccc1bc9 100644 --- a/spec/unit/formatters/doc_spec.rb +++ b/spec/unit/formatters/doc_spec.rb @@ -75,4 +75,18 @@ describe Chef::Formatters::Base do expect(formatter.elapsed_time).to eql(36610.0) expect(formatter.pretty_elapsed_time).to include("10 hours 10 minutes 10 seconds") end + + it "shows the percentage completion of an action" do + res = Chef::Resource::RemoteFile.new("canteloupe") + formatter.resource_update_progress(res, 35, 50, 10) + expect(out.string).to include(" - Progress: 70%") + end + + it "updates the percentage completion of an action" do + res = Chef::Resource::RemoteFile.new("canteloupe") + formatter.resource_update_progress(res, 70, 100, 10) + expect(out.string).to include(" - Progress: 70%") + formatter.resource_update_progress(res, 80, 100, 10) + expect(out.string).to include(" - Progress: 80%") + end end diff --git a/spec/unit/provider/remote_file/http_spec.rb b/spec/unit/provider/remote_file/http_spec.rb index 60ecd45dbb..f58a3d3c14 100644 --- a/spec/unit/provider/remote_file/http_spec.rb +++ b/spec/unit/provider/remote_file/http_spec.rb @@ -163,6 +163,12 @@ describe Chef::Provider::RemoteFile::HTTP do let(:last_response) { {} } + let(:event_dispatcher) do + event_dispatcher = double(Chef::EventDispatch::Dispatcher) + allow(event_dispatcher).to receive(:formatter?).and_return(false) + event_dispatcher + end + let(:rest) do rest = double(Chef::HTTP::Simple) allow(rest).to receive(:streaming_request).and_return(tempfile) @@ -173,6 +179,7 @@ describe Chef::Provider::RemoteFile::HTTP do before do new_resource.headers({}) new_resource.use_last_modified(false) + allow(new_resource).to receive(:events).and_return(event_dispatcher) expect(Chef::Provider::RemoteFile::CacheControlData).to receive(:load_and_validate).with(uri, current_resource_checksum).and_return(cache_control_data) expect(Chef::HTTP::Simple).to receive(:new).with(*expected_http_args).and_return(rest) @@ -205,6 +212,20 @@ describe Chef::Provider::RemoteFile::HTTP do expect(cache_control_data.checksum).to eq(fetched_content_checksum) end + context "with progress reports" do + before do + Chef::Config[:show_download_progress] = true + end + + it "should yield its progress" do + allow(rest).to receive(:streaming_request_with_progress).and_yield(50, 100).and_yield(70, 100).and_return(tempfile) + expect(event_dispatcher).to receive(:formatter?).and_return(true) + expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 50, 100, 10).ordered + expect(event_dispatcher).to receive(:resource_update_progress).with(new_resource, 70, 100, 10).ordered + fetcher.fetch + end + end + context "and the response does not contain an etag" do let(:last_response) { { "etag" => nil } } it "does not include an etag in the result" do |