Sha256: 8cab92fcbea8c89b719baf4718abb8b6530231f08d451ed6907a41cbb8cd6d9a

Contents?: true

Size: 1.58 KB

Versions: 10

Compression:

Stored size: 1.58 KB

Contents

require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')

class HttpDownloaderTest < Test::Unit::TestCase
  setup do
    @downloader, @tempfile = mock_downloader(Vagrant::Downloaders::HTTP)
    @downloader.stubs(:report_progress)
    @downloader.stubs(:complete_progress)
    @uri = "foo.box"
  end

  context "downloading" do
    setup do
      @parsed_uri = mock("parsed")
      URI.stubs(:parse).with(@uri).returns(@parsed_uri)
    end

    should "parse the URI and use that parsed URI for Net::HTTP" do
      URI.expects(:parse).with(@uri).returns(@parsed_uri).once
      Net::HTTP.expects(:get_response).with(@parsed_uri).once
      @downloader.download!(@uri, @tempfile)
    end

    should "read the body of the response and place each segment into the file" do
      response = mock("response")
      response.stubs(:content_length)
      segment = mock("segment")
      segment.stubs(:length).returns(7)

      Net::HTTP.stubs(:get_response).yields(response)
      response.expects(:read_body).once.yields(segment)
      @tempfile.expects(:write).with(segment).once

      @downloader.download!(@uri, @tempfile)
    end
  end

  context "matching the uri" do
    should "use extract to verify that the string is in fact a uri" do
      URI.expects(:extract).returns(['foo'])
      assert Vagrant::Downloaders::HTTP.match?('foo')
    end

    should "return false if there are no extract results" do
      URI.expects(:extract).returns([])
      assert !Vagrant::Downloaders::HTTP.match?('foo')
    end    
  end

  context "reporting progress" do
    # TODO: Testing for this, probably
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
vagrantup-0.3.4 test/vagrant/downloaders/http_test.rb
vagrantup-0.3.3 test/vagrant/downloaders/http_test.rb
vagrantup-0.3.2 test/vagrant/downloaders/http_test.rb
vagrantup-0.3.1 test/vagrant/downloaders/http_test.rb
vagrantup-0.3.0 test/vagrant/downloaders/http_test.rb
vagrant-0.3.4 test/vagrant/downloaders/http_test.rb
vagrant-0.3.3 test/vagrant/downloaders/http_test.rb
vagrant-0.3.2 test/vagrant/downloaders/http_test.rb
vagrant-0.3.1 test/vagrant/downloaders/http_test.rb
vagrant-0.3.0 test/vagrant/downloaders/http_test.rb