debian-mirror-gitlab/spec/lib/prometheus/cleanup_multiproc_dir_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2022-06-21 17:19:12 +05:30
require 'fast_spec_helper'
2022-10-11 01:57:18 +05:30
require 'tmpdir'
2019-12-04 20:38:33 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe Prometheus::CleanupMultiprocDirService do
2022-06-21 17:19:12 +05:30
describe '#execute' do
2019-12-04 20:38:33 +05:30
let(:metrics_multiproc_dir) { Dir.mktmpdir }
let(:metrics_file_path) { File.join(metrics_multiproc_dir, 'counter_puma_master-0.db') }
2022-06-21 17:19:12 +05:30
subject(:service) { described_class.new(metrics_dir_arg).execute }
2019-12-04 20:38:33 +05:30
before do
FileUtils.touch(metrics_file_path)
end
after do
2022-06-21 17:19:12 +05:30
FileUtils.rm_rf(metrics_multiproc_dir)
2019-12-04 20:38:33 +05:30
end
context 'when `multiprocess_files_dir` is defined' do
2022-06-21 17:19:12 +05:30
let(:metrics_dir_arg) { metrics_multiproc_dir }
2019-12-04 20:38:33 +05:30
it 'removes old metrics' do
2022-06-21 17:19:12 +05:30
expect { service }
2019-12-04 20:38:33 +05:30
.to change { File.exist?(metrics_file_path) }
.from(true)
.to(false)
end
end
context 'when `multiprocess_files_dir` is not defined' do
2022-06-21 17:19:12 +05:30
let(:metrics_dir_arg) { nil }
2019-12-04 20:38:33 +05:30
it 'does not remove any files' do
2022-06-21 17:19:12 +05:30
expect { service }
2019-12-04 20:38:33 +05:30
.not_to change { File.exist?(metrics_file_path) }
.from(true)
end
end
end
end