2017-10-30 08:55:18 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Clusters::CreateService do
|
|
|
|
let(:access_token) { 'xxx' }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:result) { described_class.new(project, user, params).execute(access_token) }
|
|
|
|
|
2017-10-31 14:59:40 -04:00
|
|
|
context 'when provider is gcp' do
|
|
|
|
context 'when correct params' do
|
|
|
|
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'
|
|
|
|
}
|
2017-10-30 08:55:18 -04:00
|
|
|
}
|
2017-10-31 14:59:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a cluster object and performs a worker' do
|
|
|
|
expect(ClusterProvisionWorker).to receive(:perform_async)
|
|
|
|
|
|
|
|
expect { result }
|
|
|
|
.to change { Clusters::Cluster.count }.by(1)
|
|
|
|
.and change { Clusters::Providers::Gcp.count }.by(1)
|
|
|
|
|
|
|
|
expect(result.name).to eq('test-cluster')
|
|
|
|
expect(result.user).to eq(user)
|
|
|
|
expect(result.project).to eq(project)
|
|
|
|
expect(result.provider.gcp_project_id).to eq('gcp-project')
|
|
|
|
expect(result.provider.zone).to eq('us-central1-a')
|
|
|
|
expect(result.provider.num_nodes).to eq(1)
|
|
|
|
expect(result.provider.machine_type).to eq('machine_type-a')
|
|
|
|
expect(result.provider.access_token).to eq(access_token)
|
2017-11-02 14:37:32 -04:00
|
|
|
expect(result.platform).to be_nil
|
2017-10-31 14:59:40 -04:00
|
|
|
end
|
2017-10-30 08:55:18 -04:00
|
|
|
end
|
|
|
|
|
2017-10-31 14:59:40 -04:00
|
|
|
context 'when invalid params' do
|
|
|
|
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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an error' do
|
|
|
|
expect(ClusterProvisionWorker).not_to receive(:perform_async)
|
|
|
|
expect { result }.to change { Clusters::Cluster.count }.by(0)
|
|
|
|
expect(result.errors[:"provider_gcp.gcp_project_id"]).to be_present
|
|
|
|
end
|
2017-10-30 08:55:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|