Skip to content

Commit

Permalink
Extend the extract test for Pathnames
Browse files Browse the repository at this point in the history
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Feb 18, 2021
1 parent 5f551b5 commit e6c3586
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions spec/mixlib/lib_archive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,36 @@
end
end

it "creates a tarball" do
Dir.chdir(fixtures_path) do
Mixlib::Archive::LibArchive.new(archive_path).create(file_paths, gzip: true)
shared_examples_for "creates a tarball" do
it "creates a tarball" do
Dir.chdir(fixtures_path) do
Mixlib::Archive::LibArchive.new(archive_path).create(file_paths, gzip: true)
end
expect(File.file?(archive_path)).to be true
Mixlib::Archive::LibArchive.new(archive_path).extract(target)
expect(Dir.entries(target)).to match_array file_paths
expect(File.size("#{target}/fixture_binary")).to eql 6
expect(File.size("#{target}/fixture_a")).to eql 10
expect(File.size("#{target}/fixture_b")).to eql 10
expect(File.size("#{target}/fixture_c")).to eql 11 # this specifically tests windows binmode + crlf conversions
# we test that the file sizes in the originals haven't been changed due to crlf mangling by git itself
expect(File.size("#{fixtures_path}/fixture_binary")).to eql 6
expect(File.size("#{fixtures_path}/fixture_a")).to eql 10
expect(File.size("#{fixtures_path}/fixture_b")).to eql 10
expect(File.size("#{fixtures_path}/fixture_c")).to eql 11
end
expect(File.file?(archive_path)).to be true
target = File.join(test_root, "target")
Mixlib::Archive::LibArchive.new(archive_path).extract(target)
expect(Dir.entries(target)).to match_array file_paths
expect(File.size("#{target}/fixture_binary")).to eql 6
expect(File.size("#{target}/fixture_a")).to eql 10
expect(File.size("#{target}/fixture_b")).to eql 10
expect(File.size("#{target}/fixture_c")).to eql 11 # this specifically tests windows binmode + crlf conversions
# we test that the file sizes in the originals haven't been changed due to crlf mangling by git itself
expect(File.size("#{fixtures_path}/fixture_binary")).to eql 6
expect(File.size("#{fixtures_path}/fixture_a")).to eql 10
expect(File.size("#{fixtures_path}/fixture_b")).to eql 10
expect(File.size("#{fixtures_path}/fixture_c")).to eql 11
end

context "with a string" do
let(:target) { File.join(test_root, "target") }

it_behaves_like "creates a tarball"
end

context "with a Pathname" do
let(:target) { Pathname.new(test_root) + "target" }

it_behaves_like "creates a tarball"
end
end
end

0 comments on commit e6c3586

Please sign in to comment.