Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 15:07:43 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-16 15:07:43 +0300
commitd10a462fedbd7794a83abdba9b4526600f71de5b (patch)
tree4dbd21cb89013d9e07b05bac5101cd13585a8be5 /spec/lib/gitlab
parent13867d66e92c2fd8962a126db4fbdc32891343c9 (diff)
Add latest changes from gitlab-org/gitlab@masterogolowinski-master-patch-80898
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb46
-rw-r--r--spec/lib/gitlab/ci/config_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb86
-rw-r--r--spec/lib/gitlab/diff/highlight_cache_spec.rb25
-rw-r--r--spec/lib/gitlab/diff/highlight_spec.rb4
-rw-r--r--spec/lib/gitlab/error_tracking_spec.rb (renamed from spec/lib/gitlab/sentry_spec.rb)14
-rw-r--r--spec/lib/gitlab/file_detector_spec.rb16
-rw-r--r--spec/lib/gitlab/gitaly_client_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/gpg_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/avatar_restorer_spec.rb10
-rw-r--r--spec/lib/gitlab/import_export/avatar_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/file_importer_spec.rb16
-rw-r--r--spec/lib/gitlab/import_export/fork_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/lfs_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/merge_request_parser_spec.rb8
-rw-r--r--spec/lib/gitlab/import_export/reader_spec.rb19
-rw-r--r--spec/lib/gitlab/import_export/repo_restorer_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/repo_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/shared_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/uploads_manager_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/uploads_restorer_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/uploads_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/mail_room/mail_room_spec.rb106
-rw-r--r--spec/lib/gitlab/metrics/instrumentation_spec.rb8
-rw-r--r--spec/lib/gitlab/query_limiting/middleware_spec.rb5
-rw-r--r--spec/lib/gitlab/sanitizers/svg_spec.rb4
-rw-r--r--spec/lib/gitlab/sherlock/transaction_spec.rb5
-rw-r--r--spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb4
-rw-r--r--spec/lib/gitlab/slash_commands/run_spec.rb35
32 files changed, 385 insertions, 80 deletions
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb
index 6e077aa00d7..cc1ee63ff04 100644
--- a/spec/lib/gitlab/ci/config/entry/job_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb
@@ -461,7 +461,8 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:unspecified) { double('unspecified', 'specified?' => false) }
let(:default) { double('default', '[]' => unspecified) }
- let(:deps) { double('deps', 'default' => default, '[]' => unspecified) }
+ let(:workflow) { double('workflow', 'has_rules?' => false) }
+ let(:deps) { double('deps', 'default' => default, '[]' => unspecified, 'workflow' => workflow) }
context 'when job config overrides default config' do
before do
@@ -492,6 +493,49 @@ describe Gitlab::Ci::Config::Entry::Job do
expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push')
end
end
+
+ context 'with workflow rules' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:name, :has_workflow_rules?, :only, :rules, :result) do
+ "uses default only" | false | nil | nil | { refs: %w[branches tags] }
+ "uses user only" | false | %w[branches] | nil | { refs: %w[branches] }
+ "does not define only" | false | nil | [] | nil
+ "does not define only" | true | nil | nil | nil
+ "uses user only" | true | %w[branches] | nil | { refs: %w[branches] }
+ "does not define only" | true | nil | [] | nil
+ end
+
+ with_them do
+ let(:config) { { script: 'ls', rules: rules, only: only }.compact }
+
+ it "#{name}" do
+ expect(workflow).to receive(:has_rules?) { has_workflow_rules? }
+
+ entry.compose!(deps)
+
+ expect(entry.only_value).to eq(result)
+ end
+ end
+ end
+
+ context 'when workflow rules is used' do
+ context 'when rules are used' do
+ let(:config) { { script: 'ls', cache: { key: 'test' }, rules: [] } }
+
+ it 'does not define only' do
+ expect(entry).not_to be_only_defined
+ end
+ end
+
+ context 'when rules are not used' do
+ let(:config) { { script: 'ls', cache: { key: 'test' }, only: [] } }
+
+ it 'does not define only' do
+ expect(entry).not_to be_only_defined
+ end
+ end
+ end
end
context 'when composed' do
diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb
index b039c572677..63a36995284 100644
--- a/spec/lib/gitlab/ci/config_spec.rb
+++ b/spec/lib/gitlab/ci/config_spec.rb
@@ -157,7 +157,7 @@ describe Gitlab::Ci::Config do
describe '.new' do
it 'raises error' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { config }.to raise_error(
described_class::ConfigError,
@@ -367,7 +367,7 @@ describe Gitlab::Ci::Config do
end
it 'raises error TimeoutError' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { config }.to raise_error(
described_class::ConfigError,
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 6083aac44f5..f61b28b06c8 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -28,6 +28,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"]
@@ -120,6 +121,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: { script: ["rspec"] },
interruptible: true,
allow_failure: false,
@@ -281,8 +283,7 @@ module Gitlab
when: "on_success",
yaml_variables: [],
options: { script: ["rspec"] },
- only: { refs: ["branches"] },
- except: {} }] },
+ only: { refs: ["branches"] } }] },
{ name: "deploy",
index: 3,
builds:
@@ -293,8 +294,7 @@ module Gitlab
when: "on_success",
yaml_variables: [],
options: { script: ["cap prod"] },
- only: { refs: ["tags"] },
- except: {} }] },
+ only: { refs: ["tags"] } }] },
{ name: ".post",
index: 4,
builds: [] }]
@@ -631,6 +631,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -662,6 +663,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -691,6 +693,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -716,6 +719,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -1230,6 +1234,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -1527,6 +1532,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "build1",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1538,6 +1544,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "build1", artifacts: true },
@@ -1565,6 +1572,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "build1",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1576,6 +1584,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "parallel 1/2", artifacts: false },
@@ -1599,6 +1608,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "parallel 1/2", artifacts: true },
@@ -1626,6 +1636,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "build1", artifacts: true },
@@ -1733,6 +1744,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "normal_job",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1778,6 +1790,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "job1",
+ only: { refs: %w[branches tags] },
options: {
script: ["execute-script-for-job"]
},
@@ -1789,6 +1802,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "job2",
+ only: { refs: %w[branches tags] },
options: {
script: ["execute-script-for-job"]
},
@@ -2235,6 +2249,70 @@ module Gitlab
it { is_expected.to be_nil }
end
end
+
+ describe '.new_with_validation_errors' do
+ subject { Gitlab::Ci::YamlProcessor.new_with_validation_errors(content) }
+
+ context 'when the YAML could not be parsed' do
+ let(:content) { YAML.dump('invalid: yaml: test') }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Invalid configuration format'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the tags parameter is invalid' do
+ let(:content) { YAML.dump({ rspec: { script: 'test', tags: 'mysql' } }) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['jobs:rspec:tags config should be an array of strings'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the configuration contains multiple keyword-syntax errors' do
+ let(:content) { YAML.dump({ rspec: { script: 'test', bad_tags: 'mysql', rules: { wrong: 'format' } } }) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['jobs:rspec config contains unknown keys: bad_tags', 'jobs:rspec rules should be an array of hashes'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when YAML content is empty' do
+ let(:content) { '' }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Please provide content of .gitlab-ci.yml'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the YAML contains an unknown alias' do
+ let(:content) { 'steps: *bad_alias' }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Unknown alias: bad_alias'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the YAML is valid' do
+ let(:content) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(true)
+ expect(subject.errors).to be_empty
+ expect(subject.content).to be_present
+ end
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb
index 7daf086843b..c73ec84e332 100644
--- a/spec/lib/gitlab/diff/highlight_cache_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb
@@ -79,10 +79,8 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
end
end
- describe '#write_if_empty' do
+ shared_examples 'caches missing entries' do
it 'filters the key/value list of entries to be caches for each invocation' do
- paths = merge_request.diffs.diff_files.select(&:text?).map(&:file_path)
-
expect(cache).to receive(:write_to_redis_hash)
.with(hash_including(*paths))
.once
@@ -96,6 +94,12 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
cache.write_if_empty
end
+ end
+
+ describe '#write_if_empty' do
+ it_behaves_like 'caches missing entries' do
+ let(:paths) { merge_request.diffs.raw_diff_files.select(&:text?).map(&:file_path) }
+ end
context 'different diff_collections for the same diffable' do
before do
@@ -109,6 +113,21 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
.to change { Gitlab::Redis::Cache.with { |r| r.hgetall(cache_key) } }
end
end
+
+ context 'when cache initialized with MergeRequestDiffBatch' do
+ let(:merge_request_diff_batch) do
+ Gitlab::Diff::FileCollection::MergeRequestDiffBatch.new(
+ merge_request.merge_request_diff,
+ 1,
+ 10,
+ diff_options: nil)
+ end
+
+ it_behaves_like 'caches missing entries' do
+ let(:cache) { described_class.new(merge_request_diff_batch) }
+ let(:paths) { merge_request_diff_batch.raw_diff_files.select(&:text?).map(&:file_path) }
+ end
+ end
end
describe '#write_to_redis_hash' do
diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb
index 1a14f6d4f67..ff4ec75358e 100644
--- a/spec/lib/gitlab/diff/highlight_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_spec.rb
@@ -105,7 +105,7 @@ describe Gitlab::Diff::Highlight do
end
it 'keeps the original rich line' do
- allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
code = %q{+ raise RuntimeError, "System commands must be given as an array of strings"}
@@ -114,7 +114,7 @@ describe Gitlab::Diff::Highlight do
end
it 'reports to Sentry if configured' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original
expect { subject }. to raise_exception(RangeError)
end
diff --git a/spec/lib/gitlab/sentry_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb
index 6d05241e72d..08718bc92a1 100644
--- a/spec/lib/gitlab/sentry_spec.rb
+++ b/spec/lib/gitlab/error_tracking_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Sentry do
+describe Gitlab::ErrorTracking do
let(:exception) { RuntimeError.new('boom') }
let(:issue_url) { 'http://gitlab.com/gitlab-org/gitlab-foss/issues/1' }
@@ -76,8 +76,8 @@ describe Gitlab::Sentry do
)
end
- it 'calls Gitlab::Sentry::Logger.error with formatted payload' do
- expect(Gitlab::Sentry::Logger).to receive(:error)
+ it 'calls Gitlab::ErrorTracking::Logger.error with formatted payload' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error)
.with(a_hash_including(*expected_payload_includes))
described_class.track_and_raise_for_dev_exception(
@@ -97,8 +97,8 @@ describe Gitlab::Sentry do
.to raise_error(RuntimeError)
end
- it 'calls Gitlab::Sentry::Logger.error with formatted payload' do
- expect(Gitlab::Sentry::Logger).to receive(:error)
+ it 'calls Gitlab::ErrorTracking::Logger.error with formatted payload' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error)
.with(a_hash_including(*expected_payload_includes))
expect do
@@ -134,8 +134,8 @@ describe Gitlab::Sentry do
)
end
- it 'calls Gitlab::Sentry::Logger.error with formatted payload' do
- expect(Gitlab::Sentry::Logger).to receive(:error)
+ it 'calls Gitlab::ErrorTracking::Logger.error with formatted payload' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error)
.with(a_hash_including(*expected_payload_includes))
described_class.track_exception(
diff --git a/spec/lib/gitlab/file_detector_spec.rb b/spec/lib/gitlab/file_detector_spec.rb
index f3a9f706e86..23f7deba7f7 100644
--- a/spec/lib/gitlab/file_detector_spec.rb
+++ b/spec/lib/gitlab/file_detector_spec.rb
@@ -82,5 +82,21 @@ describe Gitlab::FileDetector do
it 'returns nil for an unknown file' do
expect(described_class.type_of('foo.txt')).to be_nil
end
+
+ it 'returns the type of an OpenAPI spec if file name is correct' do
+ openapi_types = [
+ 'openapi.yml', 'openapi.yaml', 'openapi.json',
+ 'swagger.yml', 'swagger.yaml', 'swagger.json',
+ 'gitlab_swagger.yml', 'openapi_gitlab.yml',
+ 'OpenAPI.YML', 'openapi.Yaml', 'openapi.JSON',
+ 'openapi.gitlab.yml', 'gitlab.openapi.yml'
+ ]
+
+ openapi_types.each do |type_name|
+ expect(described_class.type_of(type_name)).to eq(:openapi)
+ end
+
+ expect(described_class.type_of('openapiyml')).to be_nil
+ end
end
end
diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb
index b7ad6cebf81..0d9719a5663 100644
--- a/spec/lib/gitlab/gitaly_client_spec.rb
+++ b/spec/lib/gitlab/gitaly_client_spec.rb
@@ -86,7 +86,7 @@ describe Gitlab::GitalyClient do
describe '.stub_certs' do
it 'skips certificates if OpenSSLError is raised and report it' do
- expect(Gitlab::Sentry)
+ expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(
a_kind_of(OpenSSL::X509::CertificateError),
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
index 7065b3f9bcb..877b4d4bbaf 100644
--- a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
@@ -301,7 +301,7 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi
it 'ignores Git command errors when creating a branch' do
expect(project.repository).to receive(:add_branch).and_raise(Gitlab::Git::CommandError)
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
mr = insert_git_data
diff --git a/spec/lib/gitlab/gpg_spec.rb b/spec/lib/gitlab/gpg_spec.rb
index c073d86b4a5..27a3010eeed 100644
--- a/spec/lib/gitlab/gpg_spec.rb
+++ b/spec/lib/gitlab/gpg_spec.rb
@@ -182,14 +182,14 @@ describe Gitlab::Gpg do
expected_tmp_dir = nil
expect(described_class).to receive(:cleanup_tmp_dir).and_raise(expected_exception)
- allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
described_class.using_tmp_keychain do
expected_tmp_dir = described_class.current_home_dir
FileUtils.touch(File.join(expected_tmp_dir, 'dummy.file'))
end
- expect(Gitlab::Sentry).to have_received(:track_and_raise_for_dev_exception).with(
+ expect(Gitlab::ErrorTracking).to have_received(:track_and_raise_for_dev_exception).with(
expected_exception,
issue_url: 'https://gitlab.com/gitlab-org/gitlab/issues/20918',
tmp_dir: expected_tmp_dir, contents: ['dummy.file']
diff --git a/spec/lib/gitlab/import_export/avatar_restorer_spec.rb b/spec/lib/gitlab/import_export/avatar_restorer_spec.rb
index 77f551eeca1..662e1a5eaab 100644
--- a/spec/lib/gitlab/import_export/avatar_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/avatar_restorer_spec.rb
@@ -14,8 +14,9 @@ describe Gitlab::ImportExport::AvatarRestorer do
context 'with avatar' do
before do
- allow_any_instance_of(described_class).to receive(:avatar_export_file)
- .and_return(uploaded_image_temp_path)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:avatar_export_file).and_return(uploaded_image_temp_path)
+ end
end
it 'restores a project avatar' do
@@ -33,8 +34,9 @@ describe Gitlab::ImportExport::AvatarRestorer do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p("#{tmpdir}/a/b")
- allow_any_instance_of(described_class).to receive(:avatar_export_path)
- .and_return("#{tmpdir}/a")
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:avatar_export_path).and_return("#{tmpdir}/a")
+ end
expect(described_class.new(project: project, shared: shared).restore).to be true
end
diff --git a/spec/lib/gitlab/import_export/avatar_saver_spec.rb b/spec/lib/gitlab/import_export/avatar_saver_spec.rb
index a84406f9784..d2349e47c0a 100644
--- a/spec/lib/gitlab/import_export/avatar_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/avatar_saver_spec.rb
@@ -10,7 +10,9 @@ describe Gitlab::ImportExport::AvatarSaver do
before do
FileUtils.mkdir_p("#{shared.export_path}/avatar/")
- allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:export_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport::Shared) do |instance|
+ allow(instance).to receive(:export_path).and_return(export_path)
+ end
end
after do
diff --git a/spec/lib/gitlab/import_export/file_importer_spec.rb b/spec/lib/gitlab/import_export/file_importer_spec.rb
index 737bedab844..7c54c5f2da1 100644
--- a/spec/lib/gitlab/import_export/file_importer_spec.rb
+++ b/spec/lib/gitlab/import_export/file_importer_spec.rb
@@ -18,9 +18,15 @@ describe Gitlab::ImportExport::FileImporter do
stub_const('Gitlab::ImportExport::FileImporter::MAX_RETRIES', 0)
stub_uploads_object_storage(FileUploader)
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(storage_path)
- allow_any_instance_of(Gitlab::ImportExport::CommandLineUtil).to receive(:untar_zxf).and_return(true)
- allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:relative_archive_path).and_return('test')
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(storage_path)
+ end
+ allow_next_instance_of(Gitlab::ImportExport::CommandLineUtil) do |instance|
+ allow(instance).to receive(:untar_zxf).and_return(true)
+ end
+ allow_next_instance_of(Gitlab::ImportExport::Shared) do |instance|
+ allow(instance).to receive(:relative_archive_path).and_return('test')
+ end
allow(SecureRandom).to receive(:hex).and_return('abcd')
setup_files
end
@@ -69,7 +75,9 @@ describe Gitlab::ImportExport::FileImporter do
context 'error' do
before do
- allow_any_instance_of(described_class).to receive(:wait_for_archived_file).and_raise(StandardError)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:wait_for_archived_file).and_raise(StandardError)
+ end
described_class.import(importable: build(:project), archive_file: '', shared: shared)
end
diff --git a/spec/lib/gitlab/import_export/fork_spec.rb b/spec/lib/gitlab/import_export/fork_spec.rb
index 10197330527..09e4f62c686 100644
--- a/spec/lib/gitlab/import_export/fork_spec.rb
+++ b/spec/lib/gitlab/import_export/fork_spec.rb
@@ -32,7 +32,9 @@ describe 'forked project import' do
end
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
saver.save
repo_saver.save
diff --git a/spec/lib/gitlab/import_export/lfs_saver_spec.rb b/spec/lib/gitlab/import_export/lfs_saver_spec.rb
index 89493c3bf27..a8ff7867410 100644
--- a/spec/lib/gitlab/import_export/lfs_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/lfs_saver_spec.rb
@@ -10,7 +10,9 @@ describe Gitlab::ImportExport::LfsSaver do
subject(:saver) { described_class.new(project: project, shared: shared) }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(shared.export_path)
end
diff --git a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
index e7f039d7a6f..c437efede4c 100644
--- a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
+++ b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
@@ -35,9 +35,11 @@ describe Gitlab::ImportExport::MergeRequestParser do
end
it 'parses a MR that has no source branch' do
- allow_any_instance_of(described_class).to receive(:branch_exists?).and_call_original
- allow_any_instance_of(described_class).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
- allow_any_instance_of(described_class).to receive(:fork_merge_request?).and_return(true)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:branch_exists?).and_call_original
+ allow(instance).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
+ allow(instance).to receive(:fork_merge_request?).and_return(true)
+ end
allow(Gitlab::GitalyClient).to receive(:migrate).and_call_original
allow(Gitlab::GitalyClient).to receive(:migrate).with(:fetch_ref).and_return([nil, 0])
diff --git a/spec/lib/gitlab/import_export/reader_spec.rb b/spec/lib/gitlab/import_export/reader_spec.rb
index 802c00bed74..e37ad281eb5 100644
--- a/spec/lib/gitlab/import_export/reader_spec.rb
+++ b/spec/lib/gitlab/import_export/reader_spec.rb
@@ -9,19 +9,18 @@ describe Gitlab::ImportExport::Reader do
subject { described_class.new(shared: shared).project_tree }
it 'delegates to AttributesFinder#find_root' do
- expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
- .to receive(:find_root)
- .with(:project)
+ expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
+ expect(instance).to receive(:find_root).with(:project)
+ end
subject
end
context 'when exception raised' do
before do
- expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
- .to receive(:find_root)
- .with(:project)
- .and_raise(StandardError)
+ expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
+ expect(instance).to receive(:find_root).with(:project).and_raise(StandardError)
+ end
end
it { is_expected.to be false }
@@ -38,9 +37,9 @@ describe Gitlab::ImportExport::Reader do
subject { described_class.new(shared: shared).group_members_tree }
it 'delegates to AttributesFinder#find_root' do
- expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
- .to receive(:find_root)
- .with(:group_members)
+ expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
+ expect(instance).to receive(:find_root).with(:group_members)
+ end
subject
end
diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb
index 4f8075d9704..a61d966bdfa 100644
--- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb
@@ -20,7 +20,9 @@ describe Gitlab::ImportExport::RepoRestorer do
end
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
bundler.save
end
diff --git a/spec/lib/gitlab/import_export/repo_saver_spec.rb b/spec/lib/gitlab/import_export/repo_saver_spec.rb
index 54dbefdb535..fc1f782bfdd 100644
--- a/spec/lib/gitlab/import_export/repo_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/repo_saver_spec.rb
@@ -12,7 +12,9 @@ describe Gitlab::ImportExport::RepoSaver do
before do
project.add_maintainer(user)
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
end
after do
diff --git a/spec/lib/gitlab/import_export/saver_spec.rb b/spec/lib/gitlab/import_export/saver_spec.rb
index 450ae2a2083..a59cf7a1260 100644
--- a/spec/lib/gitlab/import_export/saver_spec.rb
+++ b/spec/lib/gitlab/import_export/saver_spec.rb
@@ -11,7 +11,9 @@ describe Gitlab::ImportExport::Saver do
subject { described_class.new(exportable: project, shared: shared) }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(shared.export_path)
FileUtils.touch("#{shared.export_path}/tmp.bundle")
diff --git a/spec/lib/gitlab/import_export/shared_spec.rb b/spec/lib/gitlab/import_export/shared_spec.rb
index 9a2339e576a..8c16243576d 100644
--- a/spec/lib/gitlab/import_export/shared_spec.rb
+++ b/spec/lib/gitlab/import_export/shared_spec.rb
@@ -49,7 +49,7 @@ describe Gitlab::ImportExport::Shared do
it 'updates the import JID' do
import_state = create(:import_state, project: project, jid: 'jid-test')
- expect(Gitlab::Sentry)
+ expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
.with(error, hash_including(import_jid: import_state.jid))
diff --git a/spec/lib/gitlab/import_export/uploads_manager_spec.rb b/spec/lib/gitlab/import_export/uploads_manager_spec.rb
index 04a94954187..e6d6ba840be 100644
--- a/spec/lib/gitlab/import_export/uploads_manager_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_manager_spec.rb
@@ -12,7 +12,9 @@ describe Gitlab::ImportExport::UploadsManager do
subject(:manager) { described_class.new(project: project, shared: shared) }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(shared.export_path)
end
diff --git a/spec/lib/gitlab/import_export/uploads_restorer_spec.rb b/spec/lib/gitlab/import_export/uploads_restorer_spec.rb
index 5c456d6f3b1..077ece87b31 100644
--- a/spec/lib/gitlab/import_export/uploads_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_restorer_spec.rb
@@ -8,7 +8,9 @@ describe Gitlab::ImportExport::UploadsRestorer do
let(:shared) { project.import_export_shared }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(File.join(shared.export_path, 'uploads/random'))
FileUtils.touch(File.join(shared.export_path, 'uploads/random', 'dummy.txt'))
end
diff --git a/spec/lib/gitlab/import_export/uploads_saver_spec.rb b/spec/lib/gitlab/import_export/uploads_saver_spec.rb
index 98b00cceada..8a36caef316 100644
--- a/spec/lib/gitlab/import_export/uploads_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_saver_spec.rb
@@ -9,7 +9,9 @@ describe Gitlab::ImportExport::UploadsSaver do
let(:shared) { project.import_export_shared }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
end
after do
diff --git a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb
index 9c6bbff48b7..59a59223d8d 100644
--- a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb
@@ -13,7 +13,9 @@ describe Gitlab::ImportExport::WikiRepoSaver do
before do
project.add_maintainer(user)
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
project_wiki.wiki
project_wiki.create_page("index", "test content")
end
diff --git a/spec/lib/gitlab/mail_room/mail_room_spec.rb b/spec/lib/gitlab/mail_room/mail_room_spec.rb
new file mode 100644
index 00000000000..cb3e214d38b
--- /dev/null
+++ b/spec/lib/gitlab/mail_room/mail_room_spec.rb
@@ -0,0 +1,106 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::MailRoom do
+ let(:default_port) { 143 }
+ let(:default_config) do
+ {
+ enabled: false,
+ port: default_port,
+ ssl: false,
+ start_tls: false,
+ mailbox: 'inbox',
+ idle_timeout: 60,
+ log_path: Rails.root.join('log', 'mail_room_json.log').to_s
+ }
+ end
+
+ before do
+ described_class.reset_config!
+ allow(File).to receive(:exist?).and_return true
+ end
+
+ describe '#config' do
+ context 'if the yml file cannot be found' do
+ before do
+ allow(File).to receive(:exist?).and_return false
+ end
+
+ it 'returns an empty hash' do
+ expect(described_class.config).to be_empty
+ end
+ end
+
+ before do
+ allow(described_class).to receive(:load_from_yaml).and_return(default_config)
+ end
+
+ it 'sets up config properly' do
+ expected_result = default_config
+
+ expect(described_class.config).to match expected_result
+ end
+
+ context 'when a config value is missing from the yml file' do
+ it 'overwrites missing values with the default' do
+ stub_config(port: nil)
+
+ expect(described_class.config[:port]).to eq default_port
+ end
+ end
+
+ describe 'setting up redis settings' do
+ let(:fake_redis_queues) { double(url: "localhost", sentinels: "yes, them", sentinels?: true) }
+
+ before do
+ allow(Gitlab::Redis::Queues).to receive(:new).and_return(fake_redis_queues)
+ end
+
+ target_proc = proc { described_class.config[:redis_url] }
+
+ it_behaves_like 'only truthy if both enabled and address are truthy', target_proc
+ end
+
+ describe 'setting up the log path' do
+ context 'if the log path is a relative path' do
+ it 'expands the log path to an absolute value' do
+ stub_config(log_path: 'tiny_log.log')
+
+ new_path = Pathname.new(described_class.config[:log_path])
+ expect(new_path.absolute?).to be_truthy
+ end
+ end
+
+ context 'if the log path is absolute path' do
+ it 'leaves the path as-is' do
+ new_path = '/dev/null'
+ stub_config(log_path: new_path)
+
+ expect(described_class.config[:log_path]).to eq new_path
+ end
+ end
+ end
+ end
+
+ describe '#enabled?' do
+ target_proc = proc { described_class.enabled? }
+
+ it_behaves_like 'only truthy if both enabled and address are truthy', target_proc
+ end
+
+ describe '#reset_config?' do
+ it 'resets config' do
+ described_class.instance_variable_set(:@config, { some_stuff: 'hooray' })
+
+ described_class.reset_config!
+
+ expect(described_class.instance_variable_get(:@config)).to be_nil
+ end
+ end
+
+ def stub_config(override_values)
+ modified_config = default_config.merge(override_values)
+ allow(described_class).to receive(:load_from_yaml).and_return(modified_config)
+ end
+end
diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb
index 0e2f274f157..bf84a476df9 100644
--- a/spec/lib/gitlab/metrics/instrumentation_spec.rb
+++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb
@@ -87,7 +87,9 @@ describe Gitlab::Metrics::Instrumentation do
allow(described_class).to receive(:transaction)
.and_return(transaction)
- expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure)
+ expect_next_instance_of(Gitlab::Metrics::MethodCall) do |instance|
+ expect(instance).to receive(:measure)
+ end
@dummy.foo
end
@@ -165,7 +167,9 @@ describe Gitlab::Metrics::Instrumentation do
allow(described_class).to receive(:transaction)
.and_return(transaction)
- expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure)
+ expect_next_instance_of(Gitlab::Metrics::MethodCall) do |instance|
+ expect(instance).to receive(:measure)
+ end
@dummy.new.bar
end
diff --git a/spec/lib/gitlab/query_limiting/middleware_spec.rb b/spec/lib/gitlab/query_limiting/middleware_spec.rb
index fb1c30118c2..f996ea38bb9 100644
--- a/spec/lib/gitlab/query_limiting/middleware_spec.rb
+++ b/spec/lib/gitlab/query_limiting/middleware_spec.rb
@@ -7,8 +7,9 @@ describe Gitlab::QueryLimiting::Middleware do
it 'runs the application with query limiting in place' do
middleware = described_class.new(-> (env) { env })
- expect_any_instance_of(Gitlab::QueryLimiting::Transaction)
- .to receive(:act_upon_results)
+ expect_next_instance_of(Gitlab::QueryLimiting::Transaction) do |instance|
+ expect(instance).to receive(:act_upon_results)
+ end
expect(middleware.call({ number: 10 }))
.to eq({ number: 10 })
diff --git a/spec/lib/gitlab/sanitizers/svg_spec.rb b/spec/lib/gitlab/sanitizers/svg_spec.rb
index a8c7495376d..18fa96a2914 100644
--- a/spec/lib/gitlab/sanitizers/svg_spec.rb
+++ b/spec/lib/gitlab/sanitizers/svg_spec.rb
@@ -14,7 +14,9 @@ describe Gitlab::Sanitizers::SVG do
let(:sanitized) { File.read(sanitized_svg_path) }
it 'delegates sanitization to scrubber' do
- expect_any_instance_of(Gitlab::Sanitizers::SVG::Scrubber).to receive(:scrub).at_least(:once)
+ expect_next_instance_of(Gitlab::Sanitizers::SVG::Scrubber) do |instance|
+ expect(instance).to receive(:scrub).at_least(:once)
+ end
described_class.clean(data)
end
diff --git a/spec/lib/gitlab/sherlock/transaction_spec.rb b/spec/lib/gitlab/sherlock/transaction_spec.rb
index 2245c3ee8e2..728c44df4f3 100644
--- a/spec/lib/gitlab/sherlock/transaction_spec.rb
+++ b/spec/lib/gitlab/sherlock/transaction_spec.rb
@@ -167,8 +167,9 @@ describe Gitlab::Sherlock::Transaction do
allow(Gitlab::Sherlock).to receive(:enable_line_profiler?)
.and_return(true)
- allow_any_instance_of(Gitlab::Sherlock::LineProfiler)
- .to receive(:profile).and_return('cats are amazing', [])
+ allow_next_instance_of(Gitlab::Sherlock::LineProfiler) do |instance|
+ allow(instance).to receive(:profile).and_return('cats are amazing', [])
+ end
retval = transaction.profile_lines { 'cats are amazing' }
diff --git a/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb b/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb
index 0ff694d409b..d5ed939485a 100644
--- a/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb
+++ b/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb
@@ -28,7 +28,9 @@ describe Gitlab::SidekiqMiddleware::CorrelationInjector do
end
it 'injects into payload the correlation id' do
- expect_any_instance_of(described_class).to receive(:call).and_call_original
+ expect_next_instance_of(described_class) do |instance|
+ expect(instance).to receive(:call).and_call_original
+ end
Labkit::Correlation::CorrelationId.use_id('new-correlation-id') do
TestWorker.perform_async(1234)
diff --git a/spec/lib/gitlab/slash_commands/run_spec.rb b/spec/lib/gitlab/slash_commands/run_spec.rb
index 900fae05719..32a23129e3c 100644
--- a/spec/lib/gitlab/slash_commands/run_spec.rb
+++ b/spec/lib/gitlab/slash_commands/run_spec.rb
@@ -56,13 +56,13 @@ describe Gitlab::SlashCommands::Run do
context 'when a pipeline could not be scheduled' do
it 'returns an error' do
- expect_any_instance_of(Gitlab::Chat::Command)
- .to receive(:try_create_pipeline)
- .and_return(nil)
+ expect_next_instance_of(Gitlab::Chat::Command) do |instance|
+ expect(instance).to receive(:try_create_pipeline).and_return(nil)
+ end
- expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
- .to receive(:failed_to_schedule)
- .with('foo')
+ expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
+ expect(instance).to receive(:failed_to_schedule).with('foo')
+ end
command.execute(command: 'foo', arguments: '')
end
@@ -77,17 +77,18 @@ describe Gitlab::SlashCommands::Run do
persisted?: true
)
- expect_any_instance_of(Gitlab::Chat::Command)
- .to receive(:try_create_pipeline)
- .and_return(pipeline)
+ expect_next_instance_of(Gitlab::Chat::Command) do |instance|
+ expect(instance).to receive(:try_create_pipeline).and_return(pipeline)
+ end
expect(Gitlab::Chat::Responder)
.to receive(:responder_for)
.with(build)
.and_return(nil)
- expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
- .to receive(:unsupported_chat_service)
+ expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
+ expect(instance).to receive(:unsupported_chat_service)
+ end
command.execute(command: 'foo', arguments: '')
end
@@ -103,18 +104,18 @@ describe Gitlab::SlashCommands::Run do
persisted?: true
)
- expect_any_instance_of(Gitlab::Chat::Command)
- .to receive(:try_create_pipeline)
- .and_return(pipeline)
+ expect_next_instance_of(Gitlab::Chat::Command) do |instance|
+ expect(instance).to receive(:try_create_pipeline).and_return(pipeline)
+ end
expect(Gitlab::Chat::Responder)
.to receive(:responder_for)
.with(build)
.and_return(responder)
- expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
- .to receive(:in_channel_response)
- .with(responder.scheduled_output)
+ expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
+ expect(instance).to receive(:in_channel_response).with(responder.scheduled_output)
+ end
command.execute(command: 'foo', arguments: '')
end