diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-28 21:08:56 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-28 21:08:56 +0000 |
commit | c1924b863ad66503edbaa3325949bce6b023b737 (patch) | |
tree | d6ab8e583d5cdb0849e10677c6223f4efbeca993 /spec | |
parent | 6315ed9630fb1c6ade3114beb762cd1568d79219 (diff) | |
download | gitlab-ce-c1924b863ad66503edbaa3325949bce6b023b737.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 138 insertions, 57 deletions
diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index a180dd5edc1..dd729651a61 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -251,7 +251,7 @@ describe('IDE store file actions', () => { describe('success', () => { beforeEach(() => { - mock.onGet(`${RELATIVE_URL_ROOT}/test/test/7297abc/${localFile.path}`).replyOnce( + mock.onGet(`${RELATIVE_URL_ROOT}/test/test/-/7297abc/${localFile.path}`).replyOnce( 200, { blame_path: 'blame_path', @@ -273,7 +273,7 @@ describe('IDE store file actions', () => { .dispatch('getFileData', { path: localFile.path }) .then(() => { expect(service.getFileData).toHaveBeenCalledWith( - `${RELATIVE_URL_ROOT}/test/test/7297abc/${localFile.path}`, + `${RELATIVE_URL_ROOT}/test/test/-/7297abc/${localFile.path}`, ); done(); @@ -345,7 +345,7 @@ describe('IDE store file actions', () => { localFile.path = 'new-shiny-file'; store.state.entries[localFile.path] = localFile; - mock.onGet(`${RELATIVE_URL_ROOT}/test/test/7297abc/old-dull-file`).replyOnce( + mock.onGet(`${RELATIVE_URL_ROOT}/test/test/-/7297abc/old-dull-file`).replyOnce( 200, { blame_path: 'blame_path', @@ -376,7 +376,7 @@ describe('IDE store file actions', () => { describe('error', () => { beforeEach(() => { - mock.onGet(`${RELATIVE_URL_ROOT}/test/test/7297abc/${localFile.path}`).networkError(); + mock.onGet(`${RELATIVE_URL_ROOT}/test/test/-/7297abc/${localFile.path}`).networkError(); }); it('dispatches error action', () => { diff --git a/spec/frontend/repository/log_tree_spec.js b/spec/frontend/repository/log_tree_spec.js index 4271a038680..8da2f39f71f 100644 --- a/spec/frontend/repository/log_tree_spec.js +++ b/spec/frontend/repository/log_tree_spec.js @@ -71,7 +71,7 @@ describe('fetchLogsTree', () => { it('calls axios get', () => fetchLogsTree(client, '', '0', resolver).then(() => { - expect(axios.get).toHaveBeenCalledWith('/gitlab-org/gitlab-foss/refs/master/logs_tree/', { + expect(axios.get).toHaveBeenCalledWith('/gitlab-org/gitlab-foss/-/refs/master/logs_tree/', { params: { format: 'json', offset: '0' }, }); })); diff --git a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb index c2816f35cec..fc9266f75fb 100644 --- a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb +++ b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb @@ -114,6 +114,24 @@ describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cache do pipeline_status.load_status pipeline_status.load_status end + + it 'handles Gitaly unavailable exceptions gracefully' do + allow(pipeline_status).to receive(:commit).and_raise(GRPC::Unavailable) + + expect(Gitlab::ErrorTracking).to receive(:track_exception).with( + an_instance_of(GRPC::Unavailable), project_id: project.id + ) + expect { pipeline_status.load_status }.not_to raise_error + end + + it 'handles Gitaly timeout exceptions gracefully' do + allow(pipeline_status).to receive(:commit).and_raise(GRPC::DeadlineExceeded) + + expect(Gitlab::ErrorTracking).to receive(:track_exception).with( + an_instance_of(GRPC::DeadlineExceeded), project_id: project.id + ) + expect { pipeline_status.load_status }.not_to raise_error + end end describe "#load_from_project", :clean_gitlab_redis_cache do diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index a46381fcedf..ef26676a6e4 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -190,23 +190,23 @@ describe 'project routing' do end it 'to #archive_alternative' do - expect(get('/gitlab/gitlabhq/repository/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', append_sha: true) + expect(get('/gitlab/gitlabhq/-/repository/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', append_sha: true) end it 'to #archive_deprecated' do - expect(get('/gitlab/gitlabhq/repository/master/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master', append_sha: true) + expect(get('/gitlab/gitlabhq/-/repository/master/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'master', append_sha: true) end it 'to #archive_deprecated format:zip' do - expect(get('/gitlab/gitlabhq/repository/master/archive.zip')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'zip', id: 'master', append_sha: true) + expect(get('/gitlab/gitlabhq/-/repository/master/archive.zip')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'zip', id: 'master', append_sha: true) end it 'to #archive_deprecated format:tar.bz2' do - expect(get('/gitlab/gitlabhq/repository/master/archive.tar.bz2')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'tar.bz2', id: 'master', append_sha: true) + expect(get('/gitlab/gitlabhq/-/repository/master/archive.tar.bz2')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', format: 'tar.bz2', id: 'master', append_sha: true) end it 'to #archive_deprecated with "/" in route' do - expect(get('/gitlab/gitlabhq/repository/improve/awesome/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'improve/awesome', append_sha: true) + expect(get('/gitlab/gitlabhq/-/repository/improve/awesome/archive')).to route_to('projects/repositories#archive', namespace_id: 'gitlab', project_id: 'gitlabhq', id: 'improve/awesome', append_sha: true) end end @@ -269,7 +269,7 @@ describe 'project routing' do # logs_file_project_ref GET /:project_id/refs/:id/logs_tree/:path(.:format) refs#logs_tree describe Projects::RefsController, 'routing' do it 'to #switch' do - expect(get('/gitlab/gitlabhq/refs/switch')).to route_to('projects/refs#switch', namespace_id: 'gitlab', project_id: 'gitlabhq') + expect(get('/gitlab/gitlabhq/-/refs/switch')).to route_to('projects/refs#switch', namespace_id: 'gitlab', project_id: 'gitlabhq') end it 'to #logs_tree' do @@ -695,16 +695,16 @@ describe 'project routing' do # project_compare /:project_id/compare/:from...:to(.:format) compare#show {from: /.+/, to: /.+/, id: /[^\/]+/, project_id: /[^\/]+/} describe Projects::CompareController, 'routing' do it 'to #index' do - expect(get('/gitlab/gitlabhq/compare')).to route_to('projects/compare#index', namespace_id: 'gitlab', project_id: 'gitlabhq') + expect(get('/gitlab/gitlabhq/-/compare')).to route_to('projects/compare#index', namespace_id: 'gitlab', project_id: 'gitlabhq') end it 'to #compare' do - expect(post('/gitlab/gitlabhq/compare')).to route_to('projects/compare#create', namespace_id: 'gitlab', project_id: 'gitlabhq') + expect(post('/gitlab/gitlabhq/-/compare')).to route_to('projects/compare#create', namespace_id: 'gitlab', project_id: 'gitlabhq') end it 'to #show' do - expect(get('/gitlab/gitlabhq/compare/master...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'master', to: 'stable') - expect(get('/gitlab/gitlabhq/compare/issue/1234...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable') + expect(get('/gitlab/gitlabhq/-/compare/master...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'master', to: 'stable') + expect(get('/gitlab/gitlabhq/-/compare/issue/1234...stable')).to route_to('projects/compare#show', namespace_id: 'gitlab', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable') end end diff --git a/spec/services/error_tracking/base_service_spec.rb b/spec/services/error_tracking/base_service_spec.rb new file mode 100644 index 00000000000..68deb2e2a73 --- /dev/null +++ b/spec/services/error_tracking/base_service_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe ErrorTracking::BaseService do + describe '#compose_response' do + let(:project) { double('project') } + let(:user) { double('user') } + let(:service) { described_class.new(project, user) } + + it 'returns bad_request error when response has an error key' do + data = { error: 'Unexpected Error' } + + result = service.send(:compose_response, data) + + expect(result[:status]).to be(:error) + expect(result[:message]).to be('Unexpected Error') + expect(result[:http_status]).to be(:bad_request) + end + + it 'returns server error when response has missing key error_type' do + data = { error: 'Unexpected Error', error_type: ErrorTracking::ProjectErrorTrackingSetting::SENTRY_API_ERROR_TYPE_MISSING_KEYS } + + result = service.send(:compose_response, data) + + expect(result[:status]).to be(:error) + expect(result[:message]).to be('Unexpected Error') + expect(result[:http_status]).to be(:internal_server_error) + end + + it 'returns no content when response is nil' do + data = nil + + result = service.send(:compose_response, data) + + expect(result[:status]).to be(:error) + expect(result[:message]).to be('Not ready. Try again later') + expect(result[:http_status]).to be(:no_content) + end + + context 'when result has no errors key' do + let(:data) { { thing: :cat } } + + it 'raises NotImplementedError' do + expect { service.send(:compose_response, data) } + .to raise_error(NotImplementedError) + end + + context 'when parse_response is implemented' do + before do + expect(service).to receive(:parse_response) do |response| + { animal: response[:thing] } + end + end + + it 'returns successful response' do + result = service.send(:compose_response, data) + + expect(result[:animal]).to eq(:cat) + expect(result[:status]).to eq(:success) + end + + it 'returns successful response with changes from passed block' do + result = service.send(:compose_response, data) do + data[:thing] = :fish + end + + expect(result[:animal]).to eq(:fish) + expect(result[:status]).to eq(:success) + end + end + end + end +end diff --git a/spec/services/error_tracking/list_issues_service_spec.rb b/spec/services/error_tracking/list_issues_service_spec.rb index 1e39146fd18..5f6e071e10d 100644 --- a/spec/services/error_tracking/list_issues_service_spec.rb +++ b/spec/services/error_tracking/list_issues_service_spec.rb @@ -20,21 +20,31 @@ describe ErrorTracking::ListIssuesService do describe '#execute' do context 'with authorized user' do - context 'when list_sentry_issues returns issues' do - let(:issues) { [:list, :of, :issues] } - - before do - expect(error_tracking_setting) - .to receive(:list_sentry_issues) - .with(list_sentry_issues_args) - .and_return(issues: issues, pagination: {}) - end + let(:issues) { [] } + + described_class::ISSUE_STATUS_VALUES.each do |status| + it "returns the issues with #{status} issue_status" do + params[:issue_status] = status + list_sentry_issues_args[:issue_status] = status + expect_list_sentry_issues_with(list_sentry_issues_args) - it 'returns the issues' do expect(result).to eq(status: :success, pagination: {}, issues: issues) end end + it 'returns the issues with no issue_status' do + expect_list_sentry_issues_with(list_sentry_issues_args) + + expect(result).to eq(status: :success, pagination: {}, issues: issues) + end + + it 'returns bad request for an issue_status not on the whitelist' do + params[:issue_status] = 'assigned' + + expect(error_tracking_setting).not_to receive(:list_sentry_issues) + expect(result).to eq(message: "Bad Request: Invalid issue_status", status: :error, http_status: :bad_request) + end + include_examples 'error tracking service data not ready', :list_sentry_issues include_examples 'error tracking service sentry error handling', :list_sentry_issues include_examples 'error tracking service http status handling', :list_sentry_issues @@ -52,3 +62,10 @@ describe ErrorTracking::ListIssuesService do end end end + +def expect_list_sentry_issues_with(list_sentry_issues_args) + expect(error_tracking_setting) + .to receive(:list_sentry_issues) + .with(list_sentry_issues_args) + .and_return(issues: [], pagination: {}) +end diff --git a/spec/services/error_tracking/list_projects_service_spec.rb b/spec/services/error_tracking/list_projects_service_spec.rb index ddd369d45f2..565610c64ac 100644 --- a/spec/services/error_tracking/list_projects_service_spec.rb +++ b/spec/services/error_tracking/list_projects_service_spec.rb @@ -63,32 +63,6 @@ describe ErrorTracking::ListProjectsService do end end - context 'sentry client raises exception' do - context 'Sentry::Client::Error' do - before do - expect(error_tracking_setting).to receive(:list_sentry_projects) - .and_raise(Sentry::Client::Error, 'Sentry response status code: 500') - end - - it 'returns error response' do - expect(result[:message]).to eq('Sentry response status code: 500') - expect(result[:http_status]).to eq(:bad_request) - end - end - - context 'Sentry::Client::MissingKeysError' do - before do - expect(error_tracking_setting).to receive(:list_sentry_projects) - .and_raise(Sentry::Client::MissingKeysError, 'Sentry API response is missing keys. key not found: "id"') - end - - it 'returns error response' do - expect(result[:message]).to eq('Sentry API response is missing keys. key not found: "id"') - expect(result[:http_status]).to eq(:internal_server_error) - end - end - end - context 'with invalid url' do let(:params) do ActionController::Parameters.new( diff --git a/spec/support/shared_examples/models/mentionable_shared_examples.rb b/spec/support/shared_examples/models/mentionable_shared_examples.rb index 0e8ee6f66f5..0c55e9de045 100644 --- a/spec/support/shared_examples/models/mentionable_shared_examples.rb +++ b/spec/support/shared_examples/models/mentionable_shared_examples.rb @@ -229,17 +229,16 @@ RSpec.shared_examples 'mentions in description' do |mentionable_type| context 'when mentionable description contains mentions' do let(:user) { create(:user) } - let(:user2) { create(:user) } let(:group) { create(:group) } - let(:mentionable_desc) { "#{user.to_reference} #{user2.to_reference} #{user.to_reference} some description #{group.to_reference(full: true)} and #{user2.to_reference} @all" } + let(:mentionable_desc) { "#{user.to_reference} some description #{group.to_reference(full: true)} and @all" } let(:mentionable) { create(mentionable_type, description: mentionable_desc) } it 'stores mentions' do add_member(user) expect(mentionable.user_mentions.count).to eq 1 - expect(mentionable.referenced_users).to match_array([user, user2]) + expect(mentionable.referenced_users).to match_array([user]) expect(mentionable.referenced_projects(user)).to match_array([mentionable.project].compact) # epic.project is nil, and we want empty [] expect(mentionable.referenced_groups(user)).to match_array([group]) end @@ -250,9 +249,8 @@ end RSpec.shared_examples 'mentions in notes' do |mentionable_type| context 'when mentionable notes contain mentions' do let(:user) { create(:user) } - let(:user2) { create(:user) } let(:group) { create(:group) } - let(:note_desc) { "#{user.to_reference} #{user2.to_reference} #{user.to_reference} and #{group.to_reference(full: true)} and #{user2.to_reference} @all" } + let(:note_desc) { "#{user.to_reference} and #{group.to_reference(full: true)} and @all" } let!(:mentionable) { note.noteable } before do @@ -263,7 +261,7 @@ RSpec.shared_examples 'mentions in notes' do |mentionable_type| it 'returns all mentionable mentions' do expect(mentionable.user_mentions.count).to eq 1 - expect(mentionable.referenced_users).to eq [user, user2] + expect(mentionable.referenced_users).to eq [user] expect(mentionable.referenced_projects(user)).to eq [mentionable.project].compact # epic.project is nil, and we want empty [] expect(mentionable.referenced_groups(user)).to eq [group] end |