Added tests for cleaning up old files in HOMEBREW_CACHE

This commit is contained in:
mansimarkaur 2017-08-05 06:06:33 +05:30
parent 265d43444b
commit 134539aa55

View File

@ -64,24 +64,18 @@ describe Homebrew::Cleanup do
end end
specify "::update_disk_cleanup_size" do specify "::update_disk_cleanup_size" do
shutup do described_class.instance_eval("@disk_cleanup_size = 0")
described_class.instance_eval("@disk_cleanup_size = 0") described_class.update_disk_cleanup_size(128)
described_class.update_disk_cleanup_size(128)
end
expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128) expect(described_class.instance_variable_get("@disk_cleanup_size")).to eq(128)
end end
specify "::disk_cleanup_size" do specify "::disk_cleanup_size" do
shutup do described_class.instance_eval("@disk_cleanup_size = 0")
described_class.instance_eval("@disk_cleanup_size = 0")
end
expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size")) expect(described_class.disk_cleanup_size).to eq(described_class.instance_variable_get("@disk_cleanup_size"))
end end
specify "::unremovable_kegs" do specify "::unremovable_kegs" do
shutup do described_class.unremovable_kegs
described_class.unremovable_kegs
end
expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([]) expect(described_class.instance_variable_get("@unremovable_kegs")).to eq([])
end end
@ -173,9 +167,7 @@ describe Homebrew::Cleanup do
FileUtils.touch svn FileUtils.touch svn
allow(ARGV).to receive(:value).with("prune").and_return("all") allow(ARGV).to receive(:value).with("prune").and_return("all")
begin begin
shutup do described_class.cleanup_cache
described_class.cleanup_cache
end
expect(git).not_to exist expect(git).not_to exist
expect(gist).to exist expect(gist).to exist
expect(svn).not_to exist expect(svn).not_to exist
@ -186,14 +178,41 @@ describe Homebrew::Cleanup do
end end
end end
it "raises error when formula name is ambiguous" do context "cleaning old files in HOMEBREW_CACHE" do
bottle = (HOMEBREW_CACHE/"foo-0.2.bottle.gz") before(:each) do
FileUtils.touch bottle @bottle = (HOMEBREW_CACHE/"testball-0.0.1.bottle.tar.gz")
(HOMEBREW_CELLAR/"foo/foo-0.2").mkpath @testball = (HOMEBREW_CACHE/"testball-0.0.1")
begin FileUtils.touch(@bottle)
described_class.cleanup_cache FileUtils.touch(@testball)
ensure (HOMEBREW_CELLAR/"testball"/"0.0.1").mkpath
FileUtils.rm_rf(bottle) FileUtils.touch(CoreTap.instance.formula_dir/"testball.rb")
end
after(:each) do
FileUtils.rm_rf(@bottle)
FileUtils.rm_rf(@testball)
FileUtils.rm_rf(HOMEBREW_CELLAR/"testball")
FileUtils.rm_rf(CoreTap.instance.formula_dir/"testball.rb")
end
it "cleans up file if outdated" do
allow(Utils::Bottles).to receive(:file_outdated?).with(any_args).and_return(true)
described_class.cleanup_cache
expect(@bottle).not_to exist
expect(@testball).not_to exist
end
it "cleans up file if ARGV has -s and formula not installed" do
ARGV << "-s"
described_class.cleanup_cache
expect(@bottle).not_to exist
expect(@testball).not_to exist
end
it "cleans up file if stale" do
puts described_class.cleanup_cache
expect(@bottle).not_to exist
expect(@testball).not_to exist
end end
end end
end end