brew/Library/Homebrew/test/unpack_strategy_spec.rb

193 lines
4.4 KiB
Ruby
Raw Normal View History

2018-07-01 23:35:29 +02:00
require "unpack_strategy"
2018-07-09 20:04:33 +02:00
RSpec.shared_examples "UnpackStrategy::detect" do
it "is correctly detected" do
expect(UnpackStrategy.detect(path)).to be_a described_class
end
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
RSpec.shared_examples "#extract" do |children: []|
specify "#extract" do
mktmpdir do |unpack_dir|
described_class.new(path).extract(to: unpack_dir)
expect(unpack_dir.children(false).map(&:to_s)).to match_array children
2018-07-01 23:35:29 +02:00
end
end
2018-07-09 20:04:33 +02:00
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe UncompressedUnpackStrategy do
let(:path) {
(mktmpdir/"test").tap do |path|
FileUtils.touch path
2018-07-01 23:35:29 +02:00
end
2018-07-09 20:04:33 +02:00
}
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe P7ZipUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.7z" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe XarUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.xar" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["container"]
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe XzUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.xz" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe RarUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.rar" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe LzipUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"test.lz" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe LhaUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"test.lha" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe JarUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"test.jar" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["test.jar"]
end
describe ZipUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/MyFancyApp.zip" }
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["MyFancyApp"]
context "when ZIP archive is corrupted" do
let(:path) {
(mktmpdir/"test.zip").tap do |path|
FileUtils.touch path
2018-07-01 23:35:29 +02:00
end
2018-07-09 20:04:33 +02:00
}
include_examples "UnpackStrategy::detect"
2018-07-01 23:35:29 +02:00
end
end
2018-07-09 20:04:33 +02:00
describe GzipUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.gz" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["container"]
end
describe Bzip2UnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.bz2" }
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["container"]
end
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
describe TarUnpackStrategy do
let(:path) { TEST_FIXTURE_DIR/"cask/container.tar.gz" }
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["container"]
2018-07-01 23:35:29 +02:00
2018-07-09 20:04:33 +02:00
context "when TAR archive is corrupted" do
let(:path) {
(mktmpdir/"test.tar").tap do |path|
FileUtils.touch path
2018-07-01 23:35:29 +02:00
end
2018-07-09 20:04:33 +02:00
}
include_examples "UnpackStrategy::detect"
2018-07-01 23:35:29 +02:00
end
end
2018-07-09 20:04:33 +02:00
describe GitUnpackStrategy do
let(:repo) {
mktmpdir.tap do |repo|
system "git", "-C", repo, "init"
FileUtils.touch repo/"test"
system "git", "-C", repo, "add", "test"
system "git", "-C", repo, "commit", "-m", "Add `test` file."
end
}
let(:path) { repo }
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: [".git", "test"]
end
2018-07-01 23:35:29 +02:00
describe SubversionUnpackStrategy do
2018-07-09 20:04:33 +02:00
let(:repo) {
mktmpdir.tap do |repo|
system "svnadmin", "create", repo
2018-07-01 23:35:29 +02:00
end
2018-07-09 20:04:33 +02:00
}
let(:working_copy) {
mktmpdir.tap do |working_copy|
system "svn", "checkout", "file://#{repo}", working_copy
FileUtils.touch working_copy/"test"
system "svn", "add", working_copy/"test"
system "svn", "commit", working_copy, "-m", "Add `test` file."
end
}
let(:path) { working_copy }
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["test"]
end
describe CvsUnpackStrategy do
let(:repo) {
mktmpdir.tap do |repo|
FileUtils.touch repo/"test"
(repo/"CVS").mkpath
end
}
let(:path) { repo }
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["CVS", "test"]
end
describe BazaarUnpackStrategy do
let(:repo) {
mktmpdir.tap do |repo|
FileUtils.touch repo/"test"
(repo/".bzr").mkpath
end
}
let(:path) { repo }
include_examples "UnpackStrategy::detect"
include_examples "#extract", children: ["test"]
end
describe MercurialUnpackStrategy do
let(:repo) {
mktmpdir.tap do |repo|
(repo/".hg").mkpath
end
}
let(:path) { repo }
include_examples "UnpackStrategy::detect"
2018-07-01 23:35:29 +02:00
end