1 # rubocop:disable RSpec/MultipleExpectations
3 require 'puppet_x/bodeco/archive'
5 describe PuppetX::Bodeco::Archive do
7 File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'files', 'test.zip'))
12 tempfile = File.join(dir, 'test.zip')
13 FileUtils.cp(zipfile, tempfile)
15 archive = described_class.new(tempfile)
16 expect(archive.checksum(:none)).to be nil
17 expect(archive.checksum(:md5)).to eq '557e2ebb67b35d1fddff18090b6bc26b'
18 expect(archive.checksum(:sha1)).to eq '377ec712d7fdb7266221db3441e3af2055448ead'
23 archive = described_class.new('test.tar.gz')
24 expect(archive.send(:parse_flags, 'xf', :undef, 'tar')).to eq 'xf'
25 expect(archive.send(:parse_flags, 'xf', 'xvf', 'tar')).to eq 'xvf'
26 expect(archive.send(:parse_flags, 'xf', { 'tar' => 'xzf', '7z' => '-y x' }, 'tar')).to eq 'xzf'
29 it '#command on RedHat' do
30 Facter.stubs(:value).with(:osfamily).returns 'RedHat'
32 tar = described_class.new('test.tar.gz')
33 expect(tar.send(:command, :undef)).to eq 'tar xzf test.tar.gz'
34 expect(tar.send(:command, 'xvf')).to eq 'tar xvf test.tar.gz'
35 tar = described_class.new('test.tar.bz2')
36 expect(tar.send(:command, :undef)).to eq 'tar xjf test.tar.bz2'
37 expect(tar.send(:command, 'xjf')).to eq 'tar xjf test.tar.bz2'
38 tar = described_class.new('test.tar.xz')
39 expect(tar.send(:command, :undef)).to eq 'unxz -dc test.tar.xz | tar xf -'
40 gunzip = described_class.new('test.gz')
41 expect(gunzip.send(:command, :undef)).to eq 'gunzip -d test.gz'
42 zip = described_class.new('test.zip')
43 expect(zip.send(:command, :undef)).to eq 'unzip -o test.zip'
44 expect(zip.send(:command, '-a')).to eq 'unzip -a test.zip'
46 zip = described_class.new('/tmp/fun folder/test.zip')
47 expect(zip.send(:command, :undef)).to eq 'unzip -o /tmp/fun\ folder/test.zip'
48 expect(zip.send(:command, '-a')).to eq 'unzip -a /tmp/fun\ folder/test.zip'
51 system_v = %w[Solaris AIX]
53 it "#command on #{os}" do
54 Facter.stubs(:value).with(:osfamily).returns os
56 tar = described_class.new('test.tar.gz')
57 expect(tar.send(:command, :undef)).to eq 'gunzip -dc test.tar.gz | tar xf -'
58 expect(tar.send(:command, 'gunzip' => '-dc', 'tar' => 'xvf')).to eq 'gunzip -dc test.tar.gz | tar xvf -'
59 tar = described_class.new('test.tar.bz2')
60 expect(tar.send(:command, :undef)).to eq 'bunzip2 -dc test.tar.bz2 | tar xf -'
61 expect(tar.send(:command, 'bunzip' => '-dc', 'tar' => 'xvf')).to eq 'bunzip2 -dc test.tar.bz2 | tar xvf -'
62 tar = described_class.new('test.tar.xz')
63 expect(tar.send(:command, :undef)).to eq 'unxz -dc test.tar.xz | tar xf -'
64 gunzip = described_class.new('test.gz')
65 expect(gunzip.send(:command, :undef)).to eq 'gunzip -d test.gz'
66 zip = described_class.new('test.zip')
67 expect(zip.send(:command, :undef)).to eq 'unzip -o test.zip'
68 expect(zip.send(:command, '-a')).to eq 'unzip -a test.zip'
70 zip = described_class.new('/tmp/fun folder/test.zip')
71 expect(zip.send(:command, :undef)).to eq 'unzip -o /tmp/fun\ folder/test.zip'
72 expect(zip.send(:command, '-a')).to eq 'unzip -a /tmp/fun\ folder/test.zip'
76 it '#command on Windows' do
77 Facter.stubs(:value).with(:osfamily).returns 'windows'
79 tar = described_class.new('test.tar.gz')
80 tar.stubs(:win_7zip).returns('7z.exe')
81 expect(tar.send(:command, :undef)).to eq '7z.exe x -aoa test.tar.gz'
82 expect(tar.send(:command, 'x -aot')).to eq '7z.exe x -aot test.tar.gz'
84 zip = described_class.new('test.zip')
85 zip.stubs(:win_7zip).returns('7z.exe')
86 expect(zip.send(:command, :undef)).to eq '7z.exe x -aoa test.zip'
88 zip = described_class.new('C:/Program Files/test.zip')
89 zip.stubs(:win_7zip).returns('7z.exe')
90 expect(zip.send(:command, :undef)).to eq '7z.exe x -aoa C:/Program\ Files/test.zip'