diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-10 21:07:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-10 21:07:43 +0300 |
commit | 6f0f893bd87535b61e0ecb1ce069eaa7fcb9e5be (patch) | |
tree | 8af92b29c838e9af2fd70f9a4a2314a08f4af922 /spec/migrations | |
parent | 8b1228b0d409d7751f01d9fb72ebfbbf62399486 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb | 23 | ||||
-rw-r--r-- | spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb | 134 |
2 files changed, 157 insertions, 0 deletions
diff --git a/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb b/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb new file mode 100644 index 00000000000..b0d2aea7015 --- /dev/null +++ b/spec/migrations/20200107172020_add_timestamp_softwarelicensespolicy_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20200107172020_add_timestamp_softwarelicensespolicy.rb') + +describe AddTimestampSoftwarelicensespolicy, :migration do + let(:software_licenses_policy) { table(:software_license_policies) } + let(:projects) { table(:projects) } + let(:licenses) { table(:software_licenses) } + + before do + projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1) + licenses.create!(name: 'MIT') + software_licenses_policy.create!(project_id: projects.first.id, software_license_id: licenses.first.id) + end + + it 'creates timestamps' do + migrate! + + expect(software_licenses_policy.first.created_at).to be_nil + expect(software_licenses_policy.first.updated_at).to be_nil + end +end diff --git a/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb b/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb new file mode 100644 index 00000000000..74f6d56a2eb --- /dev/null +++ b/spec/migrations/patch_prometheus_services_for_shared_cluster_applications_spec.rb @@ -0,0 +1,134 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20191220102807_patch_prometheus_services_for_shared_cluster_applications.rb') + +describe PatchPrometheusServicesForSharedClusterApplications, :migration, :sidekiq do + include MigrationHelpers::PrometheusServiceHelpers + + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:services) { table(:services) } + let(:clusters) { table(:clusters) } + let(:cluster_groups) { table(:cluster_groups) } + let(:clusters_applications_prometheus) { table(:clusters_applications_prometheus) } + let(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') } + + let(:application_statuses) do + { + errored: -1, + installed: 3, + updated: 5 + } + end + + let(:cluster_types) do + { + instance_type: 1, + group_type: 2 + } + end + + describe '#up' do + let!(:project_with_missing_service) { projects.create!(name: 'gitlab', path: 'gitlab-ce', namespace_id: namespace.id) } + let(:project_with_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } + let(:project_with_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } + let(:project_with_manual_active_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } + let(:project_with_manual_inactive_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } + let(:project_with_active_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } + let(:project_with_inactive_not_prometheus_service) { projects.create!(name: 'gitlab', path: 'gitlab-ee', namespace_id: namespace.id) } + + before do + services.create(service_params_for(project_with_inactive_service.id, active: false)) + services.create(service_params_for(project_with_active_service.id, active: true)) + services.create(service_params_for(project_with_active_not_prometheus_service.id, active: true, type: 'other')) + services.create(service_params_for(project_with_inactive_not_prometheus_service.id, active: false, type: 'other')) + services.create(service_params_for(project_with_manual_inactive_service.id, active: false, properties: { some: 'data' }.to_json)) + services.create(service_params_for(project_with_manual_active_service.id, active: true, properties: { some: 'data' }.to_json)) + end + + shared_examples 'patch prometheus services post migration' do + context 'prometheus application is installed on the cluster' do + it 'schedules a background migration' do + clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:installed], version: '123') + + Sidekiq::Testing.fake! do + Timecop.freeze do + background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id], + ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id], + ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id], + ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]] + + migrate! + + enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] } + expect(enqueued_migrations).to match_array(background_migrations) + end + end + end + end + + context 'prometheus application was recently updated on the cluster' do + it 'schedules a background migration' do + clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:updated], version: '123') + + Sidekiq::Testing.fake! do + Timecop.freeze do + background_migrations = [["ActivatePrometheusServicesForSharedClusterApplications", project_with_missing_service.id], + ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_service.id], + ["ActivatePrometheusServicesForSharedClusterApplications", project_with_active_not_prometheus_service.id], + ["ActivatePrometheusServicesForSharedClusterApplications", project_with_inactive_not_prometheus_service.id]] + + migrate! + + enqueued_migrations = BackgroundMigrationWorker.jobs.map { |job| job['args'] } + expect(enqueued_migrations).to match_array(background_migrations) + end + end + end + end + + context 'prometheus application failed to install on the cluster' do + it 'does not schedule a background migration' do + clusters_applications_prometheus.create(cluster_id: cluster.id, status: application_statuses[:errored], version: '123') + + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(BackgroundMigrationWorker.jobs.size).to eq 0 + end + end + end + end + + context 'prometheus application is NOT installed on the cluster' do + it 'does not schedule a background migration' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(BackgroundMigrationWorker.jobs.size).to eq 0 + end + end + end + end + end + + context 'Cluster is group_type' do + let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:group_type]) } + + before do + cluster_groups.create(group_id: namespace.id, cluster_id: cluster.id) + end + + it_behaves_like 'patch prometheus services post migration' + end + + context 'Cluster is instance_type' do + let(:cluster) { clusters.create(name: 'cluster', cluster_type: cluster_types[:instance_type]) } + + it_behaves_like 'patch prometheus services post migration' + end + end +end |