updated the unit test to look at some of the archive files
[rubygit.git] / tests / units / test_archive.rb
blobefff94a3c7a22291704a5f315f82859f64a7fbbb
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../test_helper'
5 class TestArchive < Test::Unit::TestCase
6   
7   def setup
8     set_file_paths
9     @git = Git.open(@wdir)
10   end
11   
12   def tempfile
13     Tempfile.new('archive-test').path
14   end
15   
16   def test_archive
17     f = @git.archive('v2.6', tempfile)
18     assert(File.exists?(f))
20     f = @git.object('v2.6').archive(tempfile)  # writes to given file
21     assert(File.exists?(f))
23     f = @git.object('v2.6').archive # returns path to temp file
24     assert(File.exists?(f))
25     
26     f = @git.object('v2.6').archive(nil, :format => 'tar') # returns path to temp file
27     assert(File.exists?(f))
28     
29     lines = `cd /tmp; tar xvpf #{f}`.split("\n")
30     assert_equal('ex_dir/', lines[0])
31     assert_equal('example.txt', lines[2])
32     
33     f = @git.object('v2.6').archive(tempfile, :format => 'zip')
34     assert(File.file?(f))
36     f = @git.object('v2.6').archive(tempfile, :format => 'tgz', :prefix => 'test/')
37     assert(File.exists?(f))
38     
39     f = @git.object('v2.6').archive(tempfile, :format => 'tar', :prefix => 'test/', :path => 'ex_dir/')
40     assert(File.exists?(f))
41     
42     lines = `cd /tmp; tar xvpf #{f}`.split("\n")
43     assert_equal('test/', lines[0])
44     assert_equal('test/ex_dir/ex.txt', lines[2])
46     in_temp_dir do
47       c = Git.clone(@wbare, 'new')
48       c.chdir do
49         f = @git.remote('origin').branch('master').archive(tempfile, :format => 'tgz')
50         assert(File.exists?(f))
51       end
52     end
53   end
54   
55 end