2017-10-30 12:55:18 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Clusters::CreateService do
|
|
|
|
let(:access_token) { 'xxx' }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2017-12-05 22:40:24 +00:00
|
|
|
subject { described_class.new(project, user, params).execute(access_token) }
|
2017-10-31 18:59:40 +00:00
|
|
|
|
2017-12-05 22:40:24 +00:00
|
|
|
context 'when provider is gcp' do
|
|
|
|
context 'when project has no clusters' do
|
|
|
|
context 'when correct params' do
|
2018-05-13 12:17:34 +00:00
|
|
|
include_context 'valid cluster create params'
|
2017-12-05 22:40:24 +00:00
|
|
|
|
2018-05-13 12:17:34 +00:00
|
|
|
include_examples 'create cluster service success'
|
2017-12-05 22:40:24 +00:00
|
|
|
end
|
2017-10-31 18:59:40 +00:00
|
|
|
|
2017-12-05 22:40:24 +00:00
|
|
|
context 'when invalid params' do
|
2018-05-13 12:17:34 +00:00
|
|
|
include_context 'invalid cluster create params'
|
2017-12-05 22:40:24 +00:00
|
|
|
|
2018-05-13 12:17:34 +00:00
|
|
|
include_examples 'create cluster service error'
|
2017-11-18 19:18:48 +00:00
|
|
|
end
|
2017-12-05 22:40:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project has a cluster' do
|
2018-05-13 12:17:34 +00:00
|
|
|
include_context 'valid cluster create params'
|
2018-03-21 14:59:40 +00:00
|
|
|
let!(:cluster) { create(:cluster, :provided_by_gcp, :production_environment, projects: [project]) }
|
2017-11-18 19:18:48 +00:00
|
|
|
|
|
|
|
it 'does not create a cluster' do
|
2017-10-31 18:59:40 +00:00
|
|
|
expect(ClusterProvisionWorker).not_to receive(:perform_async)
|
2017-12-05 22:40:24 +00:00
|
|
|
expect { subject }.to raise_error(ArgumentError).and change { Clusters::Cluster.count }.by(0)
|
2017-10-31 18:59:40 +00:00
|
|
|
end
|
2017-10-30 12:55:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|