2019-08-19 08:52:07 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-03-25 08:07:52 -04:00
|
|
|
require 'fast_spec_helper'
|
2019-08-19 08:52:07 -04:00
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Prometheus::CleanupMultiprocDirService do
|
2022-03-25 08:07:52 -04:00
|
|
|
describe '#execute' do
|
2019-08-19 08:52:07 -04:00
|
|
|
let(:metrics_multiproc_dir) { Dir.mktmpdir }
|
|
|
|
let(:metrics_file_path) { File.join(metrics_multiproc_dir, 'counter_puma_master-0.db') }
|
|
|
|
|
2022-03-25 08:07:52 -04:00
|
|
|
subject(:service) { described_class.new(metrics_dir_arg).execute }
|
|
|
|
|
2019-08-19 08:52:07 -04:00
|
|
|
before do
|
|
|
|
FileUtils.touch(metrics_file_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
2022-03-25 08:07:52 -04:00
|
|
|
FileUtils.rm_rf(metrics_multiproc_dir)
|
2019-08-19 08:52:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `multiprocess_files_dir` is defined' do
|
2022-03-25 08:07:52 -04:00
|
|
|
let(:metrics_dir_arg) { metrics_multiproc_dir }
|
2019-08-19 08:52:07 -04:00
|
|
|
|
|
|
|
it 'removes old metrics' do
|
2022-03-25 08:07:52 -04:00
|
|
|
expect { service }
|
2019-08-19 08:52:07 -04:00
|
|
|
.to change { File.exist?(metrics_file_path) }
|
|
|
|
.from(true)
|
|
|
|
.to(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when `multiprocess_files_dir` is not defined' do
|
2022-03-25 08:07:52 -04:00
|
|
|
let(:metrics_dir_arg) { nil }
|
2019-08-19 08:52:07 -04:00
|
|
|
|
|
|
|
it 'does not remove any files' do
|
2022-03-25 08:07:52 -04:00
|
|
|
expect { service }
|
2019-08-19 08:52:07 -04:00
|
|
|
.not_to change { File.exist?(metrics_file_path) }
|
|
|
|
.from(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|