summaryrefslogtreecommitdiff
path: root/spec/services
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-11-01 03:59:40 +0900
committerShinya Maeda <shinya@gitlab.com>2017-11-01 03:59:40 +0900
commit253bf69dda460869741bc6c9d864c789055b8013 (patch)
tree38fc90dbd0c76bf11c2845aa86130be5c051ef3b /spec/services
parent6a65e2f5f94781a69f3f7fb329483ead6bc81fd9 (diff)
downloadgitlab-ce-253bf69dda460869741bc6c9d864c789055b8013.tar.gz
specs for feature
Diffstat (limited to 'spec/services')
-rw-r--r--spec/services/clusters/create_service_spec.rb149
1 files changed, 107 insertions, 42 deletions
diff --git a/spec/services/clusters/create_service_spec.rb b/spec/services/clusters/create_service_spec.rb
index 14f88d3f0f5..b33578d6acd 100644
--- a/spec/services/clusters/create_service_spec.rb
+++ b/spec/services/clusters/create_service_spec.rb
@@ -6,57 +6,122 @@ describe Clusters::CreateService do
let(:user) { create(:user) }
let(:result) { described_class.new(project, user, params).execute(access_token) }
- context 'when correct params' do
- let(:params) do
- {
- name: 'test-cluster',
- platform_type: :kubernetes,
- provider_type: :gcp,
- platform_kubernetes_attributes: {
- namespace: 'custom-namespace'
- },
- provider_gcp_attributes: {
- gcp_project_id: 'gcp-project',
- zone: 'us-central1-a',
- num_nodes: 1,
- machine_type: 'machine_type-a'
+ context 'when provider is gcp' do
+ context 'when correct params' do
+ let(:params) do
+ {
+ name: 'test-cluster',
+ platform_type: :kubernetes,
+ provider_type: :gcp,
+ platform_kubernetes_attributes: {
+ namespace: 'custom-namespace'
+ },
+ provider_gcp_attributes: {
+ gcp_project_id: 'gcp-project',
+ zone: 'us-central1-a',
+ num_nodes: 1,
+ machine_type: 'machine_type-a'
+ }
}
- }
+ 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::Platforms::Kubernetes.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)
+ expect(result.platform.namespace).to eq('custom-namespace')
+ expect(result.platform.valid?).to be_falsey
+ end
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)
- 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)
- expect(result.platform.namespace).to eq('custom-namespace')
+ context 'when invalid params' do
+ let(:params) do
+ {
+ name: 'test-cluster',
+ platform_type: :kubernetes,
+ provider_type: :gcp,
+ platform_kubernetes_attributes: {
+ namespace: 'custom-namespace'
+ },
+ 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
end
end
- context 'when invalid params' do
- let(:params) do
- {
- name: 'test-cluster',
- platform_type: :kubernetes,
- provider_type: :user,
- provider_gcp_attributes: {
- gcp_project_id: 'gcp-project',
- zone: 'us-central1-a',
- num_nodes: 'ABC'
+ context 'when provider is user' do
+ context 'when correct params' do
+ let(:params) do
+ {
+ name: 'test-cluster',
+ platform_type: :kubernetes,
+ provider_type: :user,
+ platform_kubernetes_attributes: {
+ namespace: 'custom-namespace',
+ api_url: 'https://111.111.111.111',
+ token: 'token'
+ }
}
- }
+ 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::Platforms::Kubernetes.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).to be_nil
+ expect(result.platform.namespace).to eq('custom-namespace')
+ expect(result.platform.valid?).to be_truthy
+ end
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.num_nodes"]).to be_present
+ context 'when invalid params' do
+ let(:params) do
+ {
+ name: 'test-cluster',
+ platform_type: :kubernetes,
+ provider_type: :user,
+ platform_kubernetes_attributes: {
+ namespace: 'custom-namespace',
+ api_url: '!!!!!',
+ token: 'token'
+ }
+ }
+ 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[:"platform_kubernetes.api_url"]).to be_present
+ end
end
end
end