diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 21:09:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 21:09:54 +0300 |
commit | f697dc5e76dfc5894df006d53b2b7e751653cf05 (patch) | |
tree | 1387cd225039e611f3683f96b318bb17d4c422cb /spec/lib/gitlab/background_migration | |
parent | 874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/background_migration')
-rw-r--r-- | spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb b/spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb new file mode 100644 index 00000000000..fdabc8e8f7c --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeployments, :migration, schema: 20200227140242 do + subject { described_class.new } + + describe '#perform' do + it 'backfills deployment_cluster for all deployments in the given range with a non-null cluster_id' do + deployment_clusters = table(:deployment_clusters) + + namespace = table(:namespaces).create(name: 'the-namespace', path: 'the-path') + project = table(:projects).create(name: 'the-project', namespace_id: namespace.id) + environment = table(:environments).create(name: 'the-environment', project_id: project.id, slug: 'slug') + cluster = table(:clusters).create(name: 'the-cluster') + + deployment_data = { cluster_id: cluster.id, project_id: project.id, environment_id: environment.id, ref: 'abc', tag: false, sha: 'sha', status: 1 } + expected_deployment_1 = create_deployment(**deployment_data) + create_deployment(**deployment_data, cluster_id: nil) # no cluster_id + expected_deployment_2 = create_deployment(**deployment_data) + out_of_range_deployment = create_deployment(**deployment_data, cluster_id: cluster.id) # expected to be out of range + + # to test "ON CONFLICT DO NOTHING" + existing_record_for_deployment_2 = deployment_clusters.create( + deployment_id: expected_deployment_2.id, + cluster_id: expected_deployment_2.cluster_id, + kubernetes_namespace: 'production' + ) + + subject.perform(expected_deployment_1.id, out_of_range_deployment.id - 1) + + expect(deployment_clusters.all.pluck(:deployment_id, :cluster_id, :kubernetes_namespace)).to contain_exactly( + [expected_deployment_1.id, cluster.id, nil], + [expected_deployment_2.id, cluster.id, existing_record_for_deployment_2.kubernetes_namespace] + ) + end + + def create_deployment(**data) + @iid ||= 0 + @iid += 1 + table(:deployments).create(iid: @iid, **data) + end + end +end |