diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 18:08:56 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-05 18:08:56 +0300 |
commit | 61265b9f01c7db3d4f6e1266d165b1c85be7b9e7 (patch) | |
tree | b6589df984e18e3b008a155c8d9ffcae75cf7c91 /spec/lib/gitlab | |
parent | 5460c19548d3d3d2ff764ceff05c2b72aa2d3a32 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/bulk_import/client_spec.rb | 95 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 10 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_wiki_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/gl_repository/identifier_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/gl_repository/repo_type_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/gl_repository_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/repo_path_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/search/recent_issues_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/search/recent_merge_requests_spec.rb | 6 |
9 files changed, 129 insertions, 34 deletions
diff --git a/spec/lib/gitlab/bulk_import/client_spec.rb b/spec/lib/gitlab/bulk_import/client_spec.rb new file mode 100644 index 00000000000..a6f8dd6d194 --- /dev/null +++ b/spec/lib/gitlab/bulk_import/client_spec.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BulkImport::Client do + include ImportSpecHelper + + let(:uri) { 'http://gitlab.example' } + let(:token) { 'token' } + let(:resource) { 'resource' } + + subject { described_class.new(uri: uri, token: token) } + + describe '#get' do + let(:response_double) { double(code: 200, success?: true, parsed_response: {}) } + + shared_examples 'performs network request' do + it 'performs network request' do + expect(Gitlab::HTTP).to receive(:get).with(*expected_args).and_return(response_double) + + subject.get(resource) + end + end + + describe 'parsed response' do + it 'returns parsed response' do + response_double = double(code: 200, success?: true, parsed_response: [{ id: 1 }, { id: 2 }]) + + allow(Gitlab::HTTP).to receive(:get).and_return(response_double) + + expect(subject.get(resource)).to eq(response_double.parsed_response) + end + end + + describe 'request query' do + include_examples 'performs network request' do + let(:expected_args) do + [ + anything, + hash_including( + query: { + page: described_class::DEFAULT_PAGE, + per_page: described_class::DEFAULT_PER_PAGE + } + ) + ] + end + end + end + + describe 'request headers' do + include_examples 'performs network request' do + let(:expected_args) do + [ + anything, + hash_including( + headers: { + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer #{token}" + } + ) + ] + end + end + end + + describe 'request uri' do + include_examples 'performs network request' do + let(:expected_args) do + ['http://gitlab.example:80/api/v4/resource', anything] + end + end + end + + context 'error handling' do + context 'when error occurred' do + it 'raises ConnectionError' do + allow(Gitlab::HTTP).to receive(:get).and_raise(Errno::ECONNREFUSED) + + expect { subject.get(resource) }.to raise_exception(described_class::ConnectionError) + end + end + + context 'when response is not success' do + it 'raises ConnectionError' do + response_double = double(code: 503, success?: false) + + allow(Gitlab::HTTP).to receive(:get).and_return(response_double) + + expect { subject.get(resource) }.to raise_exception(described_class::ConnectionError) + end + end + end + end +end diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index 85567ab2e55..3d60cc93bab 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -428,14 +428,12 @@ RSpec.describe Gitlab::GitAccess do end context 'when the project repository does not exist' do - it 'returns not found' do + before do project.add_guest(user) - repo = project.repository - Gitlab::GitalyClient::StorageSettings.allow_disk_access { FileUtils.rm_rf(repo.path) } - - # Sanity check for rm_rf - expect(repo.exists?).to eq(false) + allow(project.repository).to receive(:exists?).and_return(false) + end + it 'returns not found' do expect { pull_access_check }.to raise_error(Gitlab::GitAccess::NotFoundError, 'A repository for this project does not exist yet.') end end diff --git a/spec/lib/gitlab/git_access_wiki_spec.rb b/spec/lib/gitlab/git_access_wiki_spec.rb index 688089f4862..b78d99269d3 100644 --- a/spec/lib/gitlab/git_access_wiki_spec.rb +++ b/spec/lib/gitlab/git_access_wiki_spec.rb @@ -3,17 +3,17 @@ require 'spec_helper' RSpec.describe Gitlab::GitAccessWiki do - let(:access) { described_class.new(user, project, 'web', authentication_abilities: authentication_abilities, redirected_path: redirected_path) } - let_it_be(:project) { create(:project, :wiki_repo) } let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :wiki_repo) } + let_it_be(:wiki) { create(:project_wiki, project: project) } let(:changes) { ['6f6d7e7ed 570e7b2ab refs/heads/master'] } + let(:authentication_abilities) { %i[read_project download_code push_code] } let(:redirected_path) { nil } - let(:authentication_abilities) do - [ - :read_project, - :download_code, - :push_code - ] + + let(:access) do + described_class.new(user, wiki, 'web', + authentication_abilities: authentication_abilities, + redirected_path: redirected_path) end describe '#push_access_check' do @@ -64,7 +64,7 @@ RSpec.describe Gitlab::GitAccessWiki do context 'when the repository does not exist' do before do - allow(project.wiki).to receive(:repository).and_return(double('Repository', exists?: false)) + allow(wiki.repository).to receive(:exists?).and_return(false) end it_behaves_like 'not-found git access' do diff --git a/spec/lib/gitlab/gl_repository/identifier_spec.rb b/spec/lib/gitlab/gl_repository/identifier_spec.rb index e95aaaa6690..e0622e30e7a 100644 --- a/spec/lib/gitlab/gl_repository/identifier_spec.rb +++ b/spec/lib/gitlab/gl_repository/identifier_spec.rb @@ -35,14 +35,14 @@ RSpec.describe Gitlab::GlRepository::Identifier do it_behaves_like 'parsing gl_repository identifier' do let(:record_id) { project.id } let(:identifier) { "wiki-#{record_id}" } - let(:expected_container) { project } + let(:expected_container) { project.wiki } let(:expected_type) { Gitlab::GlRepository::WIKI } end it_behaves_like 'parsing gl_repository identifier' do let(:record_id) { project.id } let(:identifier) { "project-#{record_id}-wiki" } - let(:expected_container) { project } + let(:expected_container) { project.wiki } let(:expected_type) { Gitlab::GlRepository::WIKI } end end @@ -87,7 +87,8 @@ RSpec.describe Gitlab::GlRepository::Identifier do 'project-wibble-wiki', 'wiki-1-project', 'snippet', - 'project-1-wiki-bar' + 'project-1-wiki-bar', + 'project-1-project' ] end @@ -96,10 +97,5 @@ RSpec.describe Gitlab::GlRepository::Identifier do expect { described_class.parse(identifier) }.to raise_error(described_class::InvalidIdentifier) end end - - it 'raises InvalidIdentifier on project-1-project' do - pending 'https://gitlab.com/gitlab-org/gitlab/-/issues/219192' - expect { described_class.parse('project-1-project') }.to raise_error(described_class::InvalidIdentifier) - end end end diff --git a/spec/lib/gitlab/gl_repository/repo_type_spec.rb b/spec/lib/gitlab/gl_repository/repo_type_spec.rb index 3fa636a1cf0..629e6c96858 100644 --- a/spec/lib/gitlab/gl_repository/repo_type_spec.rb +++ b/spec/lib/gitlab/gl_repository/repo_type_spec.rb @@ -41,12 +41,14 @@ RSpec.describe Gitlab::GlRepository::RepoType do end describe Gitlab::GlRepository::WIKI do + let(:wiki) { project.wiki } + it_behaves_like 'a repo type' do - let(:expected_id) { project.id } + let(:expected_id) { wiki.project.id } let(:expected_identifier) { "wiki-#{expected_id}" } let(:expected_suffix) { '.wiki' } - let(:expected_container) { project } - let(:expected_repository) { ::Repository.new(project.wiki.full_path, project, shard: project.wiki.repository_storage, disk_path: project.wiki.disk_path, repo_type: Gitlab::GlRepository::WIKI) } + let(:expected_container) { wiki } + let(:expected_repository) { ::Repository.new(wiki.full_path, wiki, shard: wiki.repository_storage, disk_path: wiki.disk_path, repo_type: Gitlab::GlRepository::WIKI) } end it 'knows its type' do diff --git a/spec/lib/gitlab/gl_repository_spec.rb b/spec/lib/gitlab/gl_repository_spec.rb index 3733d545155..05914f92c01 100644 --- a/spec/lib/gitlab/gl_repository_spec.rb +++ b/spec/lib/gitlab/gl_repository_spec.rb @@ -12,7 +12,7 @@ RSpec.describe ::Gitlab::GlRepository do end it 'parses a project wiki gl_repository' do - expect(described_class.parse("wiki-#{project.id}")).to eq([project, project, Gitlab::GlRepository::WIKI]) + expect(described_class.parse("wiki-#{project.id}")).to eq([project.wiki, project, Gitlab::GlRepository::WIKI]) end it 'parses a snippet gl_repository' do diff --git a/spec/lib/gitlab/repo_path_spec.rb b/spec/lib/gitlab/repo_path_spec.rb index 05f32459164..912efa6a5db 100644 --- a/spec/lib/gitlab/repo_path_spec.rb +++ b/spec/lib/gitlab/repo_path_spec.rb @@ -18,7 +18,7 @@ RSpec.describe ::Gitlab::RepoPath do end it 'parses a full wiki project path' do - expect(described_class.parse(project.wiki.repository.full_path)).to eq([project, project, Gitlab::GlRepository::WIKI, nil]) + expect(described_class.parse(project.wiki.repository.full_path)).to eq([project.wiki, project, Gitlab::GlRepository::WIKI, nil]) end it 'parses a personal snippet repository path' do @@ -36,7 +36,7 @@ RSpec.describe ::Gitlab::RepoPath do end it 'parses a relative wiki path' do - expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project, project, Gitlab::GlRepository::WIKI, nil]) + expect(described_class.parse(project.full_path + '.wiki.git')).to eq([project.wiki, project, Gitlab::GlRepository::WIKI, nil]) end it 'parses a relative path starting with /' do @@ -49,7 +49,7 @@ RSpec.describe ::Gitlab::RepoPath do end it 'parses a relative wiki path' do - expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project, project, Gitlab::GlRepository::WIKI, redirect_route]) + expect(described_class.parse(redirect.path + '.wiki.git')).to eq([project.wiki, project, Gitlab::GlRepository::WIKI, redirect_route]) end it 'parses a relative path starting with /' do diff --git a/spec/lib/gitlab/search/recent_issues_spec.rb b/spec/lib/gitlab/search/recent_issues_spec.rb index 19a41d2aa38..c6d93173dc0 100644 --- a/spec/lib/gitlab/search/recent_issues_spec.rb +++ b/spec/lib/gitlab/search/recent_issues_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' RSpec.describe ::Gitlab::Search::RecentIssues do - def create_item(content:, project:) - create(:issue, title: content, project: project) + let(:parent_type) { :project } + + def create_item(content:, parent:) + create(:issue, title: content, project: parent) end it_behaves_like 'search recent items' diff --git a/spec/lib/gitlab/search/recent_merge_requests_spec.rb b/spec/lib/gitlab/search/recent_merge_requests_spec.rb index c6678ce0342..1da3e1425d9 100644 --- a/spec/lib/gitlab/search/recent_merge_requests_spec.rb +++ b/spec/lib/gitlab/search/recent_merge_requests_spec.rb @@ -3,8 +3,10 @@ require 'spec_helper' RSpec.describe ::Gitlab::Search::RecentMergeRequests do - def create_item(content:, project:) - create(:merge_request, :unique_branches, title: content, target_project: project, source_project: project) + let(:parent_type) { :project } + + def create_item(content:, parent:) + create(:merge_request, :unique_branches, title: content, target_project: parent, source_project: parent) end it_behaves_like 'search recent items' |