diff options
Diffstat (limited to 'spec/unit/data_collector_spec.rb')
-rw-r--r-- | spec/unit/data_collector_spec.rb | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index 831643347b..131d6b8df9 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -156,6 +156,10 @@ describe Chef::DataCollector::Reporter do let(:reporter) { described_class.new } let(:run_status) { Chef::RunStatus.new(Chef::Node.new, Chef::EventDispatch::Dispatcher.new) } + before do + Chef::Config[:data_collector][:server_url] = "http://my-data-collector-server.mycompany.com" + end + describe '#run_started' do before do allow(reporter).to receive(:update_run_status) @@ -490,7 +494,8 @@ describe Chef::DataCollector::Reporter do [ Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, - Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError ].each do |exception_class| + Net::HTTPHeaderSyntaxError, Net::ProtocolError, OpenSSL::SSL::SSLError, + Errno::EHOSTDOWN ].each do |exception_class| context "when the block raises a #{exception_class} exception" do it "disables the reporter" do expect(reporter).to receive(:disable_data_collector_reporter) @@ -515,4 +520,39 @@ describe Chef::DataCollector::Reporter do end end end + + describe '#validate_data_collector_server_url!' do + context "when server_url is empty" do + it "raises an exception" do + Chef::Config[:data_collector][:server_url] = "" + expect { reporter.send(:validate_data_collector_server_url!) }.to raise_error(Chef::Exceptions::ConfigurationError) + end + end + + context "when server_url is not empty" do + context "when server_url is an invalid URI" do + it "raises an exception" do + Chef::Config[:data_collector][:server_url] = "this is not a URI" + expect { reporter.send(:validate_data_collector_server_url!) }.to raise_error(Chef::Exceptions::ConfigurationError) + end + end + + context "when server_url is a valid URI" do + context "when server_url is a URI with no host" do + it "raises an exception" do + Chef::Config[:data_collector][:server_url] = "/file/uri.txt" + expect { reporter.send(:validate_data_collector_server_url!) }.to raise_error(Chef::Exceptions::ConfigurationError) + end + + end + + context "when server_url is a URI with a valid host" do + it "does not an exception" do + Chef::Config[:data_collector][:server_url] = "http://www.google.com/data-collector" + expect { reporter.send(:validate_data_collector_server_url!) }.not_to raise_error + end + end + end + end + end end |