brew/Library/Homebrew/test/unpack_strategy_spec.rb

77 lines
2.2 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2018-07-16 19:00:49 +02:00
describe UnpackStrategy do
describe "#extract_nestedly" do
2018-07-16 20:56:41 +02:00
subject(:strategy) { described_class.detect(path) }
2018-07-16 19:00:49 +02:00
let(:unpack_dir) { mktmpdir }
2018-07-16 20:56:41 +02:00
context "when extracting a GZIP nested in a BZIP2" do
let(:file_name) { "file" }
let(:path) {
dir = mktmpdir
(dir/"file").write "This file was inside a GZIP inside a BZIP2."
system "gzip", dir.children.first
system "bzip2", dir.children.first
dir.children.first
}
it "can extract nested archives" do
strategy.extract_nestedly(to: unpack_dir)
expect(File.read(unpack_dir/file_name)).to eq("This file was inside a GZIP inside a BZIP2.")
end
end
2018-07-16 19:00:49 +02:00
2018-07-16 20:56:41 +02:00
context "when extracting a directory with nested directories" do
let(:directories) { "A/B/C" }
let(:writable) { true }
2018-07-16 20:56:41 +02:00
let(:path) {
(mktmpdir/"file.tar").tap do |path|
mktmpdir do |dir|
(dir/directories).mkpath
FileUtils.chmod "-w", (dir/directories) unless writable
system "tar", "--create", "--file", path, "--directory", dir, "A/"
2018-07-16 20:56:41 +02:00
end
end
}
it "does not recurse into nested directories" do
strategy.extract_nestedly(to: unpack_dir)
expect(Pathname.glob(unpack_dir/"**/*")).to include unpack_dir/directories
end
context "which are not writable" do
let(:writable) { false }
it "makes them writable but not world-writable" do
strategy.extract_nestedly(to: unpack_dir)
expect(unpack_dir/directories).to be_writable
expect(unpack_dir/directories).not_to be_world_writable
end
end
2018-07-16 19:00:49 +02:00
end
context "when extracting a nested archive" do
let(:basename) { "file.xyz" }
let(:path) {
(mktmpdir/basename).tap do |path|
mktmpdir do |dir|
FileUtils.touch dir/"file.txt"
system "tar", "--create", "--file", path, "--directory", dir, "file.txt"
end
end
}
it "does not pass down the basename of the archive" do
strategy.extract_nestedly(to: unpack_dir, basename: basename)
expect(unpack_dir/"file.txt").to be_a_file
end
end
2018-07-16 19:00:49 +02:00
end
end