debian-mirror-gitlab/spec/lib/gitlab/background_migration/populate_cluster_kubernetes_namespace_table_spec.rb

95 lines
3.5 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, :migration, schema: 20181022173835 do
2019-03-02 22:35:43 +05:30
include MigrationHelpers::ClusterHelpers
2018-12-13 13:39:08 +05:30
let(:migration) { described_class.new }
2019-03-02 22:35:43 +05:30
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) }
2018-12-13 13:39:08 +05:30
before do
2019-03-02 22:35:43 +05:30
create_cluster_project_list(10)
2018-12-13 13:39:08 +05:30
end
shared_examples 'consistent kubernetes namespace attributes' do
2019-07-07 11:18:12 +05:30
it 'populates namespace and service account information' do
2019-03-02 22:35:43 +05:30
migration.perform
2018-12-13 13:39:08 +05:30
clusters_with_namespace.each do |cluster|
2019-03-02 22:35:43 +05:30
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)
2018-12-13 13:39:08 +05:30
namespace = "#{project.path}-#{project.id}"
expect(kubernetes_namespace).to be_present
2019-03-02 22:35:43 +05:30
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)
2018-12-13 13:39:08 +05:30
expect(kubernetes_namespace.namespace).to eq(namespace)
expect(kubernetes_namespace.service_account_name).to eq("#{namespace}-service-account")
end
end
end
context 'when no Clusters::Project has a Clusters::KubernetesNamespace' do
2019-03-02 22:35:43 +05:30
let(:cluster_projects) { cluster_projects_table.all }
2018-12-13 13:39:08 +05:30
2019-07-07 11:18:12 +05:30
it 'creates a Clusters::KubernetesNamespace per Clusters::Project' do
2018-12-13 13:39:08 +05:30
expect do
2019-03-02 22:35:43 +05:30
migration.perform
end.to change(Clusters::KubernetesNamespace, :count).by(cluster_projects_table.count)
2018-12-13 13:39:08 +05:30
end
it_behaves_like 'consistent kubernetes namespace attributes' do
2019-03-02 22:35:43 +05:30
let(:clusters_with_namespace) { clusters_table.all }
2018-12-13 13:39:08 +05:30
end
end
context 'when every Clusters::Project has Clusters::KubernetesNamespace' do
before do
2019-03-02 22:35:43 +05:30
create_kubernetes_namespace(clusters_table.all)
2018-12-13 13:39:08 +05:30
end
2019-07-07 11:18:12 +05:30
it 'does not create any Clusters::KubernetesNamespace' do
2018-12-13 13:39:08 +05:30
expect do
2019-03-02 22:35:43 +05:30
migration.perform
2018-12-13 13:39:08 +05:30
end.not_to change(Clusters::KubernetesNamespace, :count)
end
end
context 'when only some Clusters::Project have Clusters::KubernetesNamespace related' do
2019-03-02 22:35:43 +05:30
let(:with_kubernetes_namespace) { clusters_table.first(6) }
let(:with_no_kubernetes_namespace) { clusters_table.last(4) }
2018-12-13 13:39:08 +05:30
before do
2019-03-02 22:35:43 +05:30
create_kubernetes_namespace(with_kubernetes_namespace)
2018-12-13 13:39:08 +05:30
end
it 'creates limited number of Clusters::KubernetesNamespace' do
expect do
2019-03-02 22:35:43 +05:30
migration.perform
2018-12-13 13:39:08 +05:30
end.to change(Clusters::KubernetesNamespace, :count).by(with_no_kubernetes_namespace.count)
end
2019-07-07 11:18:12 +05:30
it 'does not modify clusters with Clusters::KubernetesNamespace' do
2019-03-02 22:35:43 +05:30
migration.perform
2018-12-13 13:39:08 +05:30
with_kubernetes_namespace.each do |cluster|
2019-03-02 22:35:43 +05:30
kubernetes_namespace = cluster_kubernetes_namespaces_table.where(cluster_id: cluster.id)
expect(kubernetes_namespace.count).to eq(1)
2018-12-13 13:39:08 +05:30
end
end
it_behaves_like 'consistent kubernetes namespace attributes' do
let(:clusters_with_namespace) { with_no_kubernetes_namespace }
end
end
end