debian-mirror-gitlab/spec/controllers/admin/requests_profiles_controller_spec.rb

73 lines
1.7 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Admin::RequestsProfilesController do
2019-12-21 20:55:43 +05:30
let_it_be(:admin) { create(:admin) }
2019-02-15 15:39:39 +05:30
before do
sign_in(admin)
end
describe '#show' do
let(:tmpdir) { Dir.mktmpdir('profiler-test') }
let(:test_file) { File.join(tmpdir, basename) }
2019-10-12 21:52:04 +05:30
subject do
get :show, params: { name: basename }
2019-02-15 15:39:39 +05:30
end
before do
stub_const('Gitlab::RequestProfiler::PROFILES_DIR', tmpdir)
2019-10-12 21:52:04 +05:30
File.write(test_file, sample_data)
2019-02-15 15:39:39 +05:30
end
after do
2019-10-12 21:52:04 +05:30
FileUtils.rm_rf(tmpdir)
2019-02-15 15:39:39 +05:30
end
2019-10-12 21:52:04 +05:30
context 'when loading HTML profile' do
2020-05-24 23:13:21 +05:30
let(:basename) { "profile_#{Time.current.to_i}_execution.html" }
2019-10-12 21:52:04 +05:30
let(:sample_data) do
'<html> <body> <h1>Heading</h1> <p>paragraph.</p> </body> </html>'
end
it 'renders the data' do
subject
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-10-12 21:52:04 +05:30
expect(response.body).to eq(sample_data)
end
end
context 'when loading TXT profile' do
2020-05-24 23:13:21 +05:30
let(:basename) { "profile_#{Time.current.to_i}_memory.txt" }
2019-10-12 21:52:04 +05:30
let(:sample_data) do
<<~TXT
Total allocated: 112096396 bytes (1080431 objects)
Total retained: 10312598 bytes (53567 objects)
TXT
end
it 'renders the data' do
subject
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-10-12 21:52:04 +05:30
expect(response.body).to eq(sample_data)
end
end
context 'when loading PDF profile' do
2020-05-24 23:13:21 +05:30
let(:basename) { "profile_#{Time.current.to_i}_anything.pdf" }
2019-10-12 21:52:04 +05:30
let(:sample_data) { 'mocked pdf content' }
2019-02-15 15:39:39 +05:30
2019-10-12 21:52:04 +05:30
it 'fails to render the data' do
expect { subject }.to raise_error(ActionController::UrlGenerationError, /No route matches.*unmatched constraints:/)
end
2019-02-15 15:39:39 +05:30
end
end
end