Sha256: c1d05f524386776df9999bce9af1cccd5d3eec7561edf3a1269ba20557a36f7d

Contents?: true

Size: 1.7 KB

Versions: 3

Compression:

Stored size: 1.7 KB

Contents

# -*- encoding: utf-8 -*-

require 'minitest/autorun'
require 'fileutils'
require 'rbconfig'
require 'webgen/source/tar_archive'

class TestSourceTarArchive < MiniTest::Unit::TestCase

  class FakeStream

    def open
      require 'stringio'
      sio = StringIO.new
      stream = Archive::Tar::Minitar::Writer.new(sio)
      stream.mkdir('/test', :mtime => (Time.now - 5).to_i, :mode => 0100755)
      stream.add_file('/test/hallo.page', :mtime => (Time.now - 4).to_i, :mode => 0100644) do |os, opts|
        os.write('This is the contents!')
      end
      stream.add_file('/other.page', :mtime => (Time.now - 4).to_i, :mode => 0100644) do |os, opts|
        os.write('This is other content!')
      end
      stream.add_file('hallo.page', :mtime => (Time.now - 4).to_i, :mode => 0100644) do |os, opts|
        os.write('This is the hallo.page!')
      end
      sio.rewind
      sio
    end

  end

  def setup
    @stream = FakeStream.new
  end

  def test_initialize
    source = Webgen::Source::TarArchive.new(nil, 'http://example.com/test.tar.gz')
    assert_equal('http://example.com/test.tar.gz', source.uri)
  end

  def test_paths
    source = Webgen::Source::TarArchive.new(nil, @stream)
    assert_equal(4, source.paths.length)
    assert(source.paths.include?(Webgen::Path.new('/test/')))
    assert(source.paths.include?(Webgen::Path.new('/test/hallo.page')))
    assert(source.paths.include?(Webgen::Path.new('/hallo.page')))
    assert_equal('This is the contents!', source.paths.find {|p| p.path == '/test/hallo.page'}.data)

    source = Webgen::Source::TarArchive.new(nil, @stream, '/test/*')
    assert_equal(1, source.paths.length)
    assert(source.paths.include?(Webgen::Path.new('/test/hallo.page')))
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
webgen-1.0.0.beta3 test/webgen/source/test_tar_archive.rb
webgen-1.0.0.beta2 test/webgen/source/test_tar_archive.rb
webgen-1.0.0.beta1 test/webgen/source/test_tar_archive.rb