Sha256: adfc75da7824737803fc7f1c96a5ce9715b550a5b917cccacb4cb05ef023cce7

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require File.expand_path('../helper', __FILE__)

describe "recipe download" do
  include Minitest::Hooks

  attr :recipe

  def server_must_receive_connection &block
    request_count = 0

    server = TCPServer.open('localhost', TestCase::HTTP_PORT)
    thread = Thread.new do
      conn = server.accept
      request_count += 1
      conn.puts "CONNECTION SUCESSFULLY MADE"
      conn.close
    end

    block.call

    thread.kill
    server.close
    
    request_count.must_be :>, 0
  end

  before do
    @request_count = 0
    @recipe = MiniPortile.new("test-download", "1.1.1")
  end

  describe "urls" do
    it "ftp" do
      @recipe.files << "ftp://localhost:#{TestCase::HTTP_PORT}/foo"
      server_must_receive_connection do
        @recipe.download
      end
    end

    it "handles http" do
      @recipe.files << "http://localhost:#{TestCase::HTTP_PORT}/foo"
      server_must_receive_connection do
        @recipe.download
      end
    end

    it "handles https" do
      @recipe.files << "https://localhost:#{TestCase::HTTP_PORT}/foo"
      server_must_receive_connection do
        @recipe.download
      end
    end

    it "file" do
      dest = "ports/archives/test-download-archive.tar.gz"
      FileUtils.rm_f dest
      path = File.expand_path(File.join(File.dirname(__FILE__), "assets", "test-download-archive.tar.gz"))
      @recipe.files << "file://#{path}"
      @recipe.download
      assert File.exist?(dest)
      Digest::MD5.file(dest).hexdigest.must_equal "5deffb997041bbb5f11bdcafdbb47975"
    end

    it "other" do
      @recipe.files << "foo://foo"
      proc { @recipe.download }.must_raise ArgumentError
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mini_portile2-2.2.0.rc1 test/test_download.rb