|
3 | 3 | require 'test_helper'
|
4 | 4 |
|
5 | 5 | class TestArchive < Test::Unit::TestCase
|
6 |
| - |
7 | 6 | def setup
|
8 | 7 | clone_working_repo
|
9 | 8 | @git = Git.open(@wdir)
|
10 |
| - @tempfiles = [] |
11 |
| - end |
12 |
| - |
13 |
| - def teardown |
14 |
| - @tempfiles.clear |
15 | 9 | end
|
16 | 10 |
|
17 | 11 | def tempfile
|
18 |
| - tempfile_object = Tempfile.new('archive-test') |
19 |
| - @tempfiles << tempfile_object # prevent deletion until teardown |
20 |
| - tempfile_object.close # close to avoid locking from git processes |
21 |
| - tempfile_object.path |
| 12 | + Dir::Tmpname.create('test-archive') { } |
22 | 13 | end
|
23 | 14 |
|
24 | 15 | def test_archive
|
25 | 16 | f = @git.archive('v2.6', tempfile)
|
26 | 17 | assert(File.exist?(f))
|
| 18 | + File.delete(f) |
| 19 | + end |
27 | 20 |
|
| 21 | + def test_archive_object |
28 | 22 | f = @git.object('v2.6').archive(tempfile) # writes to given file
|
29 | 23 | assert(File.exist?(f))
|
| 24 | + File.delete(f) |
| 25 | + end |
30 | 26 |
|
| 27 | + def test_archive_object_with_no_filename |
31 | 28 | f = @git.object('v2.6').archive # returns path to temp file
|
32 | 29 | assert(File.exist?(f))
|
| 30 | + File.delete(f) |
| 31 | + end |
33 | 32 |
|
| 33 | + def test_archive_to_tar |
34 | 34 | f = @git.object('v2.6').archive(nil, :format => 'tar') # returns path to temp file
|
35 | 35 | assert(File.exist?(f))
|
36 | 36 |
|
37 |
| - lines = Minitar::Input.open(f).each.to_a.map(&:full_name) |
| 37 | + lines = [] |
| 38 | + Minitar::Input.open(f) do |tar_reader| |
| 39 | + lines = tar_reader.to_a.map(&:full_name) |
| 40 | + end |
| 41 | + File.delete(f) |
| 42 | + |
38 | 43 | assert_match(%r{ex_dir/}, lines[1])
|
39 | 44 | assert_match(/ex_dir\/ex\.txt/, lines[2])
|
40 | 45 | assert_match(/example\.txt/, lines[3])
|
| 46 | + end |
41 | 47 |
|
| 48 | + def test_archive_to_zip |
42 | 49 | f = @git.object('v2.6').archive(tempfile, :format => 'zip')
|
43 | 50 | assert(File.file?(f))
|
| 51 | + File.delete(f) |
| 52 | + end |
44 | 53 |
|
| 54 | + def test_archive_to_tgz |
45 | 55 | f = @git.object('v2.6').archive(tempfile, :format => 'tgz', :prefix => 'test/')
|
46 | 56 | assert(File.exist?(f))
|
47 | 57 |
|
48 |
| - lines = Minitar::Input.open(Zlib::GzipReader.new(File.open(f, 'rb'))).each.to_a.map(&:full_name) |
| 58 | + lines = [] |
| 59 | + File.open(f, 'rb') do |file_reader| |
| 60 | + Zlib::GzipReader.open(file_reader) do |gz_reader| |
| 61 | + Minitar::Input.open(gz_reader) do |tar_reader| |
| 62 | + lines = tar_reader.to_a.map(&:full_name) |
| 63 | + end |
| 64 | + end |
| 65 | + end |
| 66 | + File.delete(f) |
| 67 | + |
49 | 68 | assert_match(%r{test/}, lines[1])
|
50 | 69 | assert_match(%r{test/ex_dir/ex\.txt}, lines[3])
|
| 70 | + end |
51 | 71 |
|
| 72 | + def test_archive_with_prefix_and_path |
52 | 73 | f = @git.object('v2.6').archive(tempfile, :format => 'tar', :prefix => 'test/', :path => 'ex_dir/')
|
53 | 74 | assert(File.exist?(f))
|
54 | 75 |
|
55 |
| - lines = Minitar::Input.open(f).each.to_a.map(&:full_name) |
| 76 | + tar_file = Minitar::Input.open(f) |
| 77 | + lines = tar_file.each.to_a.map(&:full_name) |
| 78 | + tar_file.close |
| 79 | + File.delete(f) |
| 80 | + |
56 | 81 | assert_match(%r{test/}, lines[1])
|
57 | 82 | assert_match(%r{test/ex_dir/ex\.txt}, lines[3])
|
| 83 | + end |
58 | 84 |
|
| 85 | + def test_archive_branch |
59 | 86 | f = @git.remote('working').branch('master').archive(tempfile, :format => 'tgz')
|
60 | 87 | assert(File.exist?(f))
|
| 88 | + File.delete(f) |
61 | 89 | end
|
62 |
| - |
63 | 90 | end
|
0 commit comments