summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-13 18:09:27 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-13 18:09:27 +0000
commit5248c5e2212b8e42b28b23e6839d69db0006829b (patch)
treef989d4b4cd06fc5dc28c024a5f230b42b0af179b /spec/lib/gitlab
parent0d55697d64b5f053bbd0f69da2962e7478097de3 (diff)
downloadgitlab-ce-5248c5e2212b8e42b28b23e6839d69db0006829b.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/auth/auth_finders_spec.rb4
-rw-r--r--spec/lib/gitlab/email/handler/service_desk_handler_spec.rb7
-rw-r--r--spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb121
-rw-r--r--spec/lib/gitlab/github_gists_import/representation/gist_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/page_counter_spec.rb12
-rw-r--r--spec/lib/gitlab/graphql/limit/field_call_count_spec.rb9
6 files changed, 145 insertions, 10 deletions
diff --git a/spec/lib/gitlab/auth/auth_finders_spec.rb b/spec/lib/gitlab/auth/auth_finders_spec.rb
index 9283c31a207..484b4702497 100644
--- a/spec/lib/gitlab/auth/auth_finders_spec.rb
+++ b/spec/lib/gitlab/auth/auth_finders_spec.rb
@@ -69,7 +69,7 @@ RSpec.describe Gitlab::Auth::AuthFinders do
expect(subject).to eq(user)
expect(@current_authenticated_job).to eq job
expect(subject).to be_from_ci_job_token
- expect(subject.ci_job_token_scope.source_project).to eq(job.project)
+ expect(subject.ci_job_token_scope.current_project).to eq(job.project)
end
end
@@ -100,7 +100,7 @@ RSpec.describe Gitlab::Auth::AuthFinders do
expect(subject).to eq(user)
expect(@current_authenticated_job).to eq job
expect(subject).to be_from_ci_job_token
- expect(subject.ci_job_token_scope.source_project).to eq(job.project)
+ expect(subject.ci_job_token_scope.current_project).to eq(job.project)
end
else
it 'returns nil' do
diff --git a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb
index 0cfd81216dc..7bba0775668 100644
--- a/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb
+++ b/spec/lib/gitlab/email/handler/service_desk_handler_spec.rb
@@ -3,6 +3,7 @@
require 'spec_helper'
RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
+ include ServiceDeskHelper
include_context 'email shared context'
before do
@@ -184,12 +185,6 @@ RSpec.describe Gitlab::Email::Handler::ServiceDeskHandler do
context 'and template is present' do
let_it_be(:settings) { create(:service_desk_setting, project: project) }
- def set_template_file(file_name, content)
- file_path = ".gitlab/issue_templates/#{file_name}.md"
- project.repository.create_file(user, file_path, content, message: 'message', branch_name: 'master')
- settings.update!(issue_template_key: file_name)
- end
-
it 'appends template text to issue description' do
set_template_file('service_desk', 'text from template')
diff --git a/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb b/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb
new file mode 100644
index 00000000000..704999a99a9
--- /dev/null
+++ b/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb
@@ -0,0 +1,121 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::GithubGistsImport::Importer::GistsImporter, feature_category: :importer do
+ subject(:result) { described_class.new(user, token).execute }
+
+ let_it_be(:user) { create(:user) }
+ let(:client) { instance_double('Gitlab::GithubImport::Client', rate_limit_resets_in: 5) }
+ let(:token) { 'token' }
+ let(:page_counter) { instance_double('Gitlab::GithubImport::PageCounter', current: 1, set: true, expire!: true) }
+ let(:page) { instance_double('Gitlab::GithubImport::Client::Page', objects: [gist], number: 1) }
+ let(:url) { 'https://gist.github.com/foo/bar.git' }
+ let(:waiter) { Gitlab::JobWaiter.new(0, 'some-job-key') }
+
+ let(:gist) do
+ {
+ id: '055b70',
+ git_pull_url: url,
+ files: {
+ 'random.txt': {
+ filename: 'random.txt',
+ type: 'text/plain',
+ language: 'Text',
+ raw_url: 'https://gist.githubusercontent.com/user_name/055b70/raw/66a7be0d/random.txt',
+ size: 166903
+ }
+ },
+ public: false,
+ created_at: '2022-09-06T11:38:18Z',
+ updated_at: '2022-09-06T11:38:18Z',
+ description: 'random text'
+ }
+ end
+
+ let(:gist_hash) do
+ {
+ id: '055b70',
+ import_url: url,
+ files: {
+ 'random.txt': {
+ filename: 'random.txt',
+ type: 'text/plain',
+ language: 'Text',
+ raw_url: 'https://gist.githubusercontent.com/user_name/055b70/raw/66a7be0d/random.txt',
+ size: 166903
+ }
+ },
+ public: false,
+ created_at: '2022-09-06T11:38:18Z',
+ updated_at: '2022-09-06T11:38:18Z',
+ title: 'random text'
+ }
+ end
+
+ let(:gist_represent) { instance_double('Gitlab::GithubGistsImport::Representation::Gist', to_hash: gist_hash) }
+
+ describe '#execute' do
+ before do
+ allow(Gitlab::GithubImport::Client)
+ .to receive(:new)
+ .with(token, parallel: true)
+ .and_return(client)
+
+ allow(Gitlab::GithubImport::PageCounter)
+ .to receive(:new)
+ .with(user, :gists, 'github-gists-importer')
+ .and_return(page_counter)
+
+ allow(client)
+ .to receive(:each_page)
+ .with(:gists, nil, { page: 1 })
+ .and_yield(page)
+
+ allow(Gitlab::GithubGistsImport::Representation::Gist)
+ .to receive(:from_api_response)
+ .with(gist)
+ .and_return(gist_represent)
+
+ allow(Gitlab::JobWaiter)
+ .to receive(:new)
+ .and_return(waiter)
+ end
+
+ context 'when success' do
+ it 'spread parallel import' do
+ expect(Gitlab::GithubGistsImport::ImportGistWorker)
+ .to receive(:bulk_perform_in)
+ .with(
+ 1.second,
+ [[user.id, gist_hash, waiter.key]],
+ batch_delay: 1.minute,
+ batch_size: 1000
+ )
+
+ expect(result.waiter).to be_an_instance_of(Gitlab::JobWaiter)
+ expect(result.waiter.jobs_remaining).to eq(1)
+ end
+ end
+
+ context 'when failure' do
+ it 'returns an error' do
+ expect(Gitlab::GithubGistsImport::ImportGistWorker)
+ .to receive(:bulk_perform_in)
+ .and_raise(StandardError, 'Error Message')
+
+ expect(result.error).to be_an_instance_of(StandardError)
+ end
+ end
+
+ context 'when rate limit reached' do
+ it 'returns an error' do
+ expect(Gitlab::GithubGistsImport::ImportGistWorker)
+ .to receive(:bulk_perform_in)
+ .and_raise(Gitlab::GithubImport::RateLimitError)
+
+ expect(result.error).to be_an_instance_of(Gitlab::GithubImport::RateLimitError)
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb b/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb
index f36fbc637d0..480aefb2c74 100644
--- a/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb
+++ b/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubGistsImport::Representation::Gist do
+RSpec.describe Gitlab::GithubGistsImport::Representation::Gist, feature_category: :importer do
shared_examples 'a Gist' do
it 'returns an instance of Gist' do
expect(gist).to be_an_instance_of(described_class)
diff --git a/spec/lib/gitlab/github_import/page_counter_spec.rb b/spec/lib/gitlab/github_import/page_counter_spec.rb
index 568bc8cbbef..511b19c00e5 100644
--- a/spec/lib/gitlab/github_import/page_counter_spec.rb
+++ b/spec/lib/gitlab/github_import/page_counter_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache do
+RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache, feature_category: :importer do
let(:project) { double(:project, id: 1) }
let(:counter) { described_class.new(project, :issues) }
@@ -16,6 +16,16 @@ RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache do
expect(described_class.new(project, :issues).current).to eq(2)
end
+
+ context 'when gists import' do
+ let(:user) { instance_double('User', id: 2) }
+
+ it 'uses gists specific key' do
+ result = described_class.new(user, :gists, 'github-gists-importer')
+
+ expect(result.cache_key).to eq('github-gists-importer/page-counter/2/gists')
+ end
+ end
end
describe '#set' do
diff --git a/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb b/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb
index 5858986dfc8..afcfb063af3 100644
--- a/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb
+++ b/spec/lib/gitlab/graphql/limit/field_call_count_spec.rb
@@ -36,6 +36,15 @@ RSpec.describe Gitlab::Graphql::Limit::FieldCallCount do
expect(resolve_value).to be_an_instance_of(Gitlab::Graphql::Errors::LimitError)
end
+ it 'does not return an error when the field is called multiple times in separte queries' do
+ query_1 = GraphQL::Query.new(GitlabSchema)
+ query_2 = GraphQL::Query.new(GitlabSchema)
+
+ resolve_field(field, { value: 'foo' }, object_type: owner, query: query_1)
+
+ expect { resolve_field(field, { value: 'foo' }, object_type: owner, query: query_2) }.not_to raise_error
+ end
+
context 'when limit is not specified' do
let(:field) do
::Types::BaseField.new(name: 'value', type: GraphQL::Types::String, null: true, owner: owner) do