Commit 7eeada80 authored by Shinya Maeda's avatar Shinya Maeda

Add env_scope tests

parent 8e6ffe35
......@@ -88,6 +88,7 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
provider_type: Cluster.provider_types[:user],
platform_type: Cluster.platform_types[:kubernetes],
projects: [kubernetes_service.project],
environment_scope: '*', # KubernetesService is considered as a default cluster
platform_kubernetes_attributes: {
api_url: kubernetes_service.api_url,
ca_cert: kubernetes_service.ca_pem,
......
......@@ -113,6 +113,38 @@ describe MigrateKubernetesServiceToNewClustersArchitectures, :migration do
end
end
context 'when production cluster has already been existsed' do
let(:project) { create(:project) }
let!(:cluster) { create(:cluster, :provided_by_gcp, environment_scope: 'production/*', projects: [project]) }
let!(:kubernetes_service) { create(:kubernetes_service, api_url: 'https://debug.kube.com', active: true, project: project) }
it 'migrates the KubernetesService to Platform::Kubernetes' do
expect{ migrate! }.to change { Clusters::Cluster.count }.by(1)
kubernetes_service.reload
project.clusters.last.tap do |cluster|
expect(cluster.platform_kubernetes.api_url).to eq(kubernetes_service.api_url)
expect(cluster.platform_kubernetes.ca_pem).to eq(kubernetes_service.ca_pem)
expect(cluster.platform_kubernetes.token).to eq(kubernetes_service.token)
expect(kubernetes_service).not_to be_active
expect(kubernetes_service.properties['migrated']).to be_truthy
end
end
end
context 'when default cluster has already been existsed' do
let(:project) { create(:project) }
let!(:cluster) { create(:cluster, :provided_by_gcp, environment_scope: '*', projects: [project]) }
let!(:kubernetes_service) { create(:kubernetes_service, api_url: 'https://debug.kube.com', active: true, project: project) }
it 'does not migrate the KubernetesService' do # Because environment_scope is duplicated
expect{ migrate! }.not_to change { Clusters::Cluster.count }
expect(kubernetes_service).to be_active
expect(kubernetes_service.properties['migrated']).to be_falsy
end
end
context 'when KubernetesService does not exist' do
let!(:project) { create(:project) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment