2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-30 08:55:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Clusters::CreateService do
|
|
|
|
let(:access_token) { 'xxx' }
|
2018-10-22 16:12:26 -04:00
|
|
|
let(:project) { create(:project) }
|
2017-10-30 08:55:18 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2018-10-18 21:42:30 -04:00
|
|
|
subject { described_class.new(user, params).execute(access_token: access_token) }
|
2017-10-31 14:59:40 -04:00
|
|
|
|
2018-10-22 16:12:26 -04:00
|
|
|
context 'when provider is gcp' do
|
|
|
|
context 'when project has no clusters' do
|
|
|
|
context 'when correct params' do
|
2018-10-18 21:42:30 -04:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
name: 'test-cluster',
|
|
|
|
provider_type: :gcp,
|
|
|
|
provider_gcp_attributes: {
|
|
|
|
gcp_project_id: 'gcp-project',
|
|
|
|
zone: 'us-central1-a',
|
|
|
|
num_nodes: 1,
|
|
|
|
machine_type: 'machine_type-a',
|
|
|
|
legacy_abac: 'true'
|
|
|
|
},
|
|
|
|
clusterable: project
|
|
|
|
}
|
|
|
|
end
|
2017-12-05 17:40:24 -05:00
|
|
|
|
2018-10-22 16:12:26 -04:00
|
|
|
include_examples 'create cluster service success'
|
2017-12-05 17:40:24 -05:00
|
|
|
end
|
2017-10-31 14:59:40 -04:00
|
|
|
|
2018-10-22 16:12:26 -04:00
|
|
|
context 'when invalid params' do
|
2018-10-18 21:42:30 -04:00
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
name: 'test-cluster',
|
|
|
|
provider_type: :gcp,
|
|
|
|
provider_gcp_attributes: {
|
|
|
|
gcp_project_id: '!!!!!!!',
|
|
|
|
zone: 'us-central1-a',
|
|
|
|
num_nodes: 1,
|
|
|
|
machine_type: 'machine_type-a'
|
|
|
|
},
|
|
|
|
clusterable: project
|
|
|
|
}
|
|
|
|
end
|
2017-12-05 17:40:24 -05:00
|
|
|
|
2018-10-22 16:12:26 -04:00
|
|
|
include_examples 'create cluster service error'
|
2018-10-16 04:05:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-22 16:12:26 -04:00
|
|
|
context 'when project has a cluster' do
|
|
|
|
include_context 'valid cluster create params'
|
|
|
|
let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
|
2018-10-16 04:05:04 -04:00
|
|
|
|
2018-10-22 16:12:26 -04:00
|
|
|
it 'does not create a cluster' do
|
|
|
|
expect(ClusterProvisionWorker).not_to receive(:perform_async)
|
|
|
|
expect { subject }.to raise_error(ArgumentError).and change { Clusters::Cluster.count }.by(0)
|
2017-10-31 14:59:40 -04:00
|
|
|
end
|
2017-10-30 08:55:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|