diff options
Diffstat (limited to 'spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb')
-rw-r--r-- | spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb b/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb index 8e3cb36d313..812e0cc6947 100644 --- a/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb +++ b/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb @@ -2,92 +2,88 @@ require 'spec_helper' -# rubocop:disable RSpec/FactoriesInMigrationSpecs describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, :migration, schema: 20181022173835 do + include MigrationHelpers::ClusterHelpers + let(:migration) { described_class.new } - let(:clusters) { create_list(:cluster, 10, :project, :provided_by_gcp) } + let(:clusters_table) { table(:clusters) } + let(:cluster_projects_table) { table(:cluster_projects) } + let(:cluster_kubernetes_namespaces_table) { table(:clusters_kubernetes_namespaces) } + let(:projects_table) { table(:projects) } + let(:namespaces_table) { table(:namespaces) } + let(:provider_gcp_table) { table(:cluster_providers_gcp) } + let(:platform_kubernetes_table) { table(:cluster_platforms_kubernetes) } before do - clusters + create_cluster_project_list(10) end shared_examples 'consistent kubernetes namespace attributes' do it 'should populate namespace and service account information' do - subject + migration.perform clusters_with_namespace.each do |cluster| - project = cluster.project - cluster_project = cluster.cluster_projects.first + cluster_project = cluster_projects_table.find_by(cluster_id: cluster.id) + project = projects_table.find(cluster_project.project_id) + kubernetes_namespace = cluster_kubernetes_namespaces_table.find_by(cluster_id: cluster.id) namespace = "#{project.path}-#{project.id}" - kubernetes_namespace = cluster.reload.kubernetes_namespace expect(kubernetes_namespace).to be_present - expect(kubernetes_namespace.cluster_project).to eq(cluster_project) - expect(kubernetes_namespace.project).to eq(cluster_project.project) - expect(kubernetes_namespace.cluster).to eq(cluster_project.cluster) + expect(kubernetes_namespace.cluster_project_id).to eq(cluster_project.id) + expect(kubernetes_namespace.project_id).to eq(cluster_project.project_id) + expect(kubernetes_namespace.cluster_id).to eq(cluster_project.cluster_id) expect(kubernetes_namespace.namespace).to eq(namespace) expect(kubernetes_namespace.service_account_name).to eq("#{namespace}-service-account") end end end - subject { migration.perform } - context 'when no Clusters::Project has a Clusters::KubernetesNamespace' do - let(:cluster_projects) { Clusters::Project.all } + let(:cluster_projects) { cluster_projects_table.all } it 'should create a Clusters::KubernetesNamespace per Clusters::Project' do expect do - subject - end.to change(Clusters::KubernetesNamespace, :count).by(cluster_projects.count) + migration.perform + end.to change(Clusters::KubernetesNamespace, :count).by(cluster_projects_table.count) end it_behaves_like 'consistent kubernetes namespace attributes' do - let(:clusters_with_namespace) { clusters } + let(:clusters_with_namespace) { clusters_table.all } end end context 'when every Clusters::Project has Clusters::KubernetesNamespace' do before do - clusters.each do |cluster| - create(:cluster_kubernetes_namespace, - cluster_project: cluster.cluster_projects.first, - cluster: cluster, - project: cluster.project) - end + create_kubernetes_namespace(clusters_table.all) end it 'should not create any Clusters::KubernetesNamespace' do expect do - subject + migration.perform end.not_to change(Clusters::KubernetesNamespace, :count) end end context 'when only some Clusters::Project have Clusters::KubernetesNamespace related' do - let(:with_kubernetes_namespace) { clusters.first(6) } - let(:with_no_kubernetes_namespace) { clusters.last(4) } + let(:with_kubernetes_namespace) { clusters_table.first(6) } + let(:with_no_kubernetes_namespace) { clusters_table.last(4) } before do - with_kubernetes_namespace.each do |cluster| - create(:cluster_kubernetes_namespace, - cluster_project: cluster.cluster_projects.first, - cluster: cluster, - project: cluster.project) - end + create_kubernetes_namespace(with_kubernetes_namespace) end it 'creates limited number of Clusters::KubernetesNamespace' do expect do - subject + migration.perform end.to change(Clusters::KubernetesNamespace, :count).by(with_no_kubernetes_namespace.count) end it 'should not modify clusters with Clusters::KubernetesNamespace' do - subject + migration.perform with_kubernetes_namespace.each do |cluster| - expect(cluster.kubernetes_namespaces.count).to eq(1) + kubernetes_namespace = cluster_kubernetes_namespaces_table.where(cluster_id: cluster.id) + expect(kubernetes_namespace.count).to eq(1) end end @@ -96,4 +92,3 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, : end end end -# rubocop:enable RSpec/FactoriesInMigrationSpecs |