diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/request_profiler/profile_spec.rb | 59 | ||||
-rw-r--r-- | spec/lib/gitlab/request_profiler_spec.rb | 41 |
2 files changed, 93 insertions, 7 deletions
diff --git a/spec/lib/gitlab/request_profiler/profile_spec.rb b/spec/lib/gitlab/request_profiler/profile_spec.rb new file mode 100644 index 00000000000..b37ee558e1a --- /dev/null +++ b/spec/lib/gitlab/request_profiler/profile_spec.rb @@ -0,0 +1,59 @@ +require 'fast_spec_helper' + +describe Gitlab::RequestProfiler::Profile do + let(:profile) { described_class.new(filename) } + + describe '.new' do + context 'using old filename' do + let(:filename) { '|api|v4|version.txt_1562854738.html' } + + it 'returns valid data' do + expect(profile).to be_valid + expect(profile.request_path).to eq('/api/v4/version.txt') + expect(profile.time).to eq(Time.at(1562854738).utc) + expect(profile.type).to eq('html') + end + end + + context 'using new filename' do + let(:filename) { '|api|v4|version.txt_1563547949_execution.html' } + + it 'returns valid data' do + expect(profile).to be_valid + expect(profile.request_path).to eq('/api/v4/version.txt') + expect(profile.profile_mode).to eq('execution') + expect(profile.time).to eq(Time.at(1563547949).utc) + expect(profile.type).to eq('html') + end + end + end + + describe '#content_type' do + context 'when using html file' do + let(:filename) { '|api|v4|version.txt_1562854738_memory.html' } + + it 'returns valid data' do + expect(profile).to be_valid + expect(profile.content_type).to eq('text/html') + end + end + + context 'when using text file' do + let(:filename) { '|api|v4|version.txt_1562854738_memory.txt' } + + it 'returns valid data' do + expect(profile).to be_valid + expect(profile.content_type).to eq('text/plain') + end + end + + context 'when file is unknown' do + let(:filename) { '|api|v4|version.txt_1562854738_memory.xxx' } + + it 'returns valid data' do + expect(profile).not_to be_valid + expect(profile.content_type).to be_nil + end + end + end +end diff --git a/spec/lib/gitlab/request_profiler_spec.rb b/spec/lib/gitlab/request_profiler_spec.rb index fd8cbf39bce..498c045b6cd 100644 --- a/spec/lib/gitlab/request_profiler_spec.rb +++ b/spec/lib/gitlab/request_profiler_spec.rb @@ -13,15 +13,42 @@ describe Gitlab::RequestProfiler do end end - describe '.remove_all_profiles' do - it 'removes Gitlab::RequestProfiler::PROFILES_DIR directory' do - dir = described_class::PROFILES_DIR - FileUtils.mkdir_p(dir) + context 'with temporary PROFILES_DIR' do + let(:tmpdir) { Dir.mktmpdir('profiler-test') } + let(:profile_name) { '|api|v4|version.txt_1562854738_memory.html' } + let(:profile_path) { File.join(tmpdir, profile_name) } - expect(Dir.exist?(dir)).to be true + before do + stub_const('Gitlab::RequestProfiler::PROFILES_DIR', tmpdir) + FileUtils.touch(profile_path) + end + + after do + FileUtils.rm_rf(tmpdir) + end + + describe '.remove_all_profiles' do + it 'removes Gitlab::RequestProfiler::PROFILES_DIR directory' do + described_class.remove_all_profiles + + expect(Dir.exist?(tmpdir)).to be false + end + end + + describe '.all' do + subject { described_class.all } + + it 'returns all profiles' do + expect(subject.map(&:name)).to contain_exactly(profile_name) + end + end + + describe '.find' do + subject { described_class.find(profile_name) } - described_class.remove_all_profiles - expect(Dir.exist?(dir)).to be false + it 'returns all profiles' do + expect(subject.name).to eq(profile_name) + end end end end |