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-10-01 15:05:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 15:05:59 +0300
commit9e27f0d920cc3891fa7644c5cc0bc280c519fb20 (patch)
tree9784dd99270f2009159b19077412bf83d13123a4 /spec/lib/gitlab
parent1bab0ba591263cd739af2d2c7c3f1b03678a59b6 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r--spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb44
-rw-r--r--spec/lib/gitlab/ci/status/composite_spec.rb61
-rw-r--r--spec/lib/gitlab/import_export/project_tree_restorer_spec.rb11
-rw-r--r--spec/lib/gitlab/import_export/relation_factory_spec.rb2
4 files changed, 118 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb b/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb
new file mode 100644
index 00000000000..d94a312f605
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/migrate_pages_metadata_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::BackgroundMigration::MigratePagesMetadata, :migration, schema: 20190919040324 do
+ let(:projects) { table(:projects) }
+
+ subject(:migrate_pages_metadata) { described_class.new }
+
+ describe '#perform_on_relation' do
+ let(:namespaces) { table(:namespaces) }
+ let(:builds) { table(:ci_builds) }
+ let(:pages_metadata) { table(:project_pages_metadata) }
+
+ it 'marks specified projects with successful pages deployment' do
+ namespace = namespaces.create!(name: 'gitlab', path: 'gitlab-org')
+ not_migrated_with_pages = projects.create!(namespace_id: namespace.id, name: 'Not Migrated With Pages')
+ builds.create!(project_id: not_migrated_with_pages.id, type: 'GenericCommitStatus', status: 'success', stage: 'deploy', name: 'pages:deploy')
+
+ migrated = projects.create!(namespace_id: namespace.id, name: 'Migrated')
+ pages_metadata.create!(project_id: migrated.id, deployed: true)
+
+ not_migrated_no_pages = projects.create!(namespace_id: namespace.id, name: 'Not Migrated No Pages')
+ project_not_in_relation_scope = projects.create!(namespace_id: namespace.id, name: 'Other')
+
+ projects_relation = projects.where(id: [not_migrated_with_pages, not_migrated_no_pages, migrated])
+
+ migrate_pages_metadata.perform_on_relation(projects_relation)
+
+ expect(pages_metadata.find_by_project_id(not_migrated_with_pages.id).deployed).to eq(true)
+ expect(pages_metadata.find_by_project_id(not_migrated_no_pages.id).deployed).to eq(false)
+ expect(pages_metadata.find_by_project_id(migrated.id).deployed).to eq(true)
+ expect(pages_metadata.find_by_project_id(project_not_in_relation_scope.id)).to be_nil
+ end
+ end
+
+ describe '#perform' do
+ it 'creates relation and delegates to #perform_on_relation' do
+ expect(migrate_pages_metadata).to receive(:perform_on_relation).with(projects.where(id: 3..5))
+
+ migrate_pages_metadata.perform(3, 5)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/ci/status/composite_spec.rb b/spec/lib/gitlab/ci/status/composite_spec.rb
new file mode 100644
index 00000000000..1725d954b92
--- /dev/null
+++ b/spec/lib/gitlab/ci/status/composite_spec.rb
@@ -0,0 +1,61 @@
+require 'spec_helper'
+
+describe Gitlab::Ci::Status::Composite do
+ set(:pipeline) { create(:ci_pipeline) }
+
+ before(:all) do
+ @statuses = HasStatus::STATUSES_ENUM.map do |status, idx|
+ [status, create(:ci_build, pipeline: pipeline, status: status, importing: true)]
+ end.to_h
+
+ @statuses_with_allow_failure = HasStatus::STATUSES_ENUM.map do |status, idx|
+ [status, create(:ci_build, pipeline: pipeline, status: status, allow_failure: true, importing: true)]
+ end.to_h
+ end
+
+ describe '#status' do
+ shared_examples 'compares composite with SQL status' do
+ it 'returns exactly the same result' do
+ builds = Ci::Build.where(id: all_statuses)
+
+ expect(composite_status.status).to eq(builds.legacy_status)
+ expect(composite_status.warnings?).to eq(builds.failed_but_allowed.any?)
+ end
+ end
+
+ shared_examples 'validate all combinations' do |perms|
+ HasStatus::STATUSES_ENUM.keys.combination(perms).each do |statuses|
+ context "with #{statuses.join(",")}" do
+ it_behaves_like 'compares composite with SQL status' do
+ let(:all_statuses) do
+ statuses.map { |status| @statuses[status] }
+ end
+
+ let(:composite_status) do
+ described_class.new(all_statuses)
+ end
+ end
+
+ HasStatus::STATUSES_ENUM.each do |allow_failure_status, _|
+ context "and allow_failure #{allow_failure_status}" do
+ it_behaves_like 'compares composite with SQL status' do
+ let(:all_statuses) do
+ statuses.map { |status| @statuses[status] } +
+ [@statuses_with_allow_failure[allow_failure_status]]
+ end
+
+ let(:composite_status) do
+ described_class.new(all_statuses)
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+
+ it_behaves_like 'validate all combinations', 0
+ it_behaves_like 'validate all combinations', 1
+ it_behaves_like 'validate all combinations', 2
+ end
+end
diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
index fcc79279b6f..c619a2ab237 100644
--- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
@@ -96,6 +96,17 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect(Ci::Pipeline.where(ref: nil)).not_to be_empty
end
+ it 'restores pipeline for merge request' do
+ pipeline = Ci::Pipeline.find_by_sha('048721d90c449b244b7b4c53a9186b04330174ec')
+
+ expect(pipeline).to be_valid
+ expect(pipeline.tag).to be_falsey
+ expect(pipeline.source).to eq('merge_request_event')
+ expect(pipeline.merge_request.id).to be > 0
+ expect(pipeline.merge_request.target_branch).to eq('feature')
+ expect(pipeline.merge_request.source_branch).to eq('feature_conflict')
+ end
+
it 'preserves updated_at on issues' do
issue = Issue.where(description: 'Aliquam enim illo et possimus.').first
diff --git a/spec/lib/gitlab/import_export/relation_factory_spec.rb b/spec/lib/gitlab/import_export/relation_factory_spec.rb
index a31f77484d8..51b2fd06b46 100644
--- a/spec/lib/gitlab/import_export/relation_factory_spec.rb
+++ b/spec/lib/gitlab/import_export/relation_factory_spec.rb
@@ -3,12 +3,14 @@ require 'spec_helper'
describe Gitlab::ImportExport::RelationFactory do
let(:project) { create(:project) }
let(:members_mapper) { double('members_mapper').as_null_object }
+ let(:merge_requests_mapping) { {} }
let(:user) { create(:admin) }
let(:excluded_keys) { [] }
let(:created_object) do
described_class.create(relation_sym: relation_sym,
relation_hash: relation_hash,
members_mapper: members_mapper,
+ merge_requests_mapping: merge_requests_mapping,
user: user,
project: project,
excluded_keys: excluded_keys)