# # Copyright Michael Orlitzky # # http://michael.orlitzky.com/ # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # http://www.fsf.org/licensing/licenses/gpl.html # require 'test/unit' require 'whatever-dl/uri_utilities.rb' class UriUtilitiesTest < Test::Unit::TestCase def test_system_call_exception_on_connection_refused uu = UriUtilities.new() # *Hopefully* this connection is refused. example_uri = 'http://localhost:1/' uri = URI.parse(example_uri) assert_raise Errno::ECONNREFUSED do uu.download_with_progress_bar(uri, 'dummy.tmp') end # This should be gone since there was an error. assert(!File.exists?('dummy.tmp')) end def test_access_denied_on_unwritable_outfile # Get rid of the dummy file if it already exists. File.delete('dummy.tmp') if File.exists?('dummy.tmp') File.new('dummy.tmp', 'w') # Make the new file unwritable File.chmod(0400, 'dummy.tmp') uu = UriUtilities.new() # *Hopefully* this connection is refused. example_uri = 'http://localhost:1/' uri = URI.parse(example_uri) assert_raise Errno::EACCES do uu.download_with_progress_bar(uri, 'dummy.tmp') end # This should *not* be deleted, since it was unwritable, # and we got an IO error instead of an HTTP or connection # error. assert(File.exists?('dummy.tmp')) # Ok, now we delete it anyway since it will mess up the other tests. File.delete('dummy.tmp') end end