File: importer.rb

package info (click to toggle)
gonzui 1.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,824 kB
  • ctags: 1,448
  • sloc: ruby: 9,570; sh: 5,684; ansic: 1,334; lex: 1,140; makefile: 466; perl: 205; ml: 131
file content (59 lines) | stat: -rwxr-xr-x 1,308 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env ruby
$LOAD_PATH.unshift("..")
require 'test/unit'
require 'fileutils'
require 'gonzui'
require 'test-util'
include Gonzui
include FileUtils

class ImporterTest < Test::Unit::TestCase
  include TestUtil

  def _test_import(url)
    config   = Config.new
    remove_db(config)
    make_archives

    importer = Importer.new(config)
    importer.import(url)
    begin
      importer.import(url)
      assert(false)
    rescue ImporterError => e
      assert(true)
    end
    summary = importer.summary
    assert(summary.is_a?(String))
    assert(/\d+/.match(summary))
    importer.finish
    remove_db(config)
  end

  def test_import_archive
    _test_import(URI.from_path(FOO_TGZ))
  end

  def test_import_by_apt
    _test_import(URI.for_apt("portmap"))
  end

  def test_import_unreadable_file
    tmp_directory = "tmp.unreadable.#{Process.pid}"
    mkdir_p(tmp_directory)

    unreadable = File.join(tmp_directory, "unreadable.txt")
    File.open(unreadable, "w") {|f| f.puts("unreadable") }
    readable = File.join(tmp_directory, "readable.txt")
    File.open(readable, "w") {|f| f.puts("readable") }

    File.chmod(0000, unreadable)
    begin
      _test_import(URI.from_path(tmp_directory))
    ensure
      File.chmod(0600, unreadable)
      rm_rf(tmp_directory)
    end
  end
end