aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/cli/cleanup_spec.rb
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-05 06:31:36 +0100
committerMarkus Reiter2017-03-05 23:08:14 +0100
commit9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2 (patch)
tree43e99a683329471c1dc965dcc92daccb57df7e8d /Library/Homebrew/test/cask/cli/cleanup_spec.rb
parent67ec76d1492fbb03959a782a85c4fb985d6a5884 (diff)
downloadbrew-9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2.tar.bz2
Move Cask specs into `brew tests`.
Diffstat (limited to 'Library/Homebrew/test/cask/cli/cleanup_spec.rb')
-rw-r--r--Library/Homebrew/test/cask/cli/cleanup_spec.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/Library/Homebrew/test/cask/cli/cleanup_spec.rb b/Library/Homebrew/test/cask/cli/cleanup_spec.rb
new file mode 100644
index 000000000..f8578e80d
--- /dev/null
+++ b/Library/Homebrew/test/cask/cli/cleanup_spec.rb
@@ -0,0 +1,93 @@
+describe Hbc::CLI::Cleanup, :cask do
+ let(:cache_location) { Pathname.new(Dir.mktmpdir).realpath }
+ let(:cleanup_outdated) { false }
+
+ subject { described_class.new(cache_location, cleanup_outdated) }
+
+ after do
+ cache_location.rmtree
+ end
+
+ describe "cleanup" do
+ it "removes cached downloads of given casks" do
+ cleaned_up_cached_download = "caffeine"
+
+ cached_downloads = [
+ cache_location.join("#{cleaned_up_cached_download}--latest.zip"),
+ cache_location.join("transmission--2.61.dmg"),
+ ]
+
+ cached_downloads.each(&FileUtils.method(:touch))
+
+ cleanup_size = Hbc::Utils.size_in_bytes(cached_downloads[0])
+
+ expect {
+ subject.cleanup(cleaned_up_cached_download)
+ }.to output(<<-EOS.undent).to_stdout
+ ==> Removing cached downloads for #{cleaned_up_cached_download}
+ #{cached_downloads[0]}
+ ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space.
+ EOS
+
+ expect(cached_downloads[0].exist?).to eq(false)
+ expect(cached_downloads[1].exist?).to eq(true)
+ end
+ end
+
+ describe "cleanup!" do
+ it "removes cached downloads" do
+ cached_download = cache_location.join("SomeDownload.dmg")
+ FileUtils.touch(cached_download)
+ cleanup_size = subject.disk_cleanup_size
+
+ expect {
+ subject.cleanup!
+ }.to output(<<-EOS.undent).to_stdout
+ ==> Removing cached downloads
+ #{cached_download}
+ ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space.
+ EOS
+
+ expect(cached_download.exist?).to eq(false)
+ end
+
+ # TODO: uncomment when unflaky.
+ # it "does not removed locked files" do
+ # cached_download = cache_location.join("SomeDownload.dmg")
+ # FileUtils.touch(cached_download)
+ # cleanup_size = subject.disk_cleanup_size
+ #
+ # File.new(cached_download).flock(File::LOCK_EX)
+ #
+ # expect(Hbc::Utils).to be_file_locked(cached_download)
+ #
+ # expect {
+ # subject.cleanup!
+ # }.to output(<<-EOS.undent).to_stdout
+ # ==> Removing cached downloads
+ # skipping: #{cached_download} is locked
+ # ==> This operation has freed approximately #{disk_usage_readable(cleanup_size)} of disk space.
+ # EOS
+ #
+ # expect(cached_download.exist?).to eq(true)
+ # end
+
+ context "when cleanup_outdated is specified" do
+ let(:cleanup_outdated) { true }
+
+ it "does not remove cache files newer than 10 days old" do
+ cached_download = cache_location.join("SomeNewDownload.dmg")
+ FileUtils.touch(cached_download)
+
+ expect {
+ subject.cleanup!
+ }.to output(<<-EOS.undent).to_stdout
+ ==> Removing cached downloads older than 10 days old
+ Nothing to do
+ EOS
+
+ expect(cached_download.exist?).to eq(true)
+ end
+ end
+ end
+end