diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-09-07 16:23:45 +1200 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-09-14 16:26:51 +1200 |
commit | 2e47e1f80e000fb717f89effef983bf22c9e2f4d (patch) | |
tree | b926b4c3656ba3b7d5ce2d82001d94f48d7ed541 | |
parent | ab6d74da9a31095c17ee4f7fedc0f27a37dde3c1 (diff) | |
download | gitlab-ce-2e47e1f80e000fb717f89effef983bf22c9e2f4d.tar.gz |
Teach GoogleApi::CloudPlatform::Client#projects_zones_clusters_create about legacy_abac argument
Fix spec warning: removing `initialize' may cause serious problems
Actually verify that `service.create_cluster` is called with expected
request_body and other args
-rw-r--r-- | app/services/clusters/gcp/provision_service.rb | 4 | ||||
-rw-r--r-- | lib/google_api/cloud_platform/client.rb | 4 | ||||
-rw-r--r-- | spec/lib/google_api/cloud_platform/client_spec.rb | 47 |
3 files changed, 44 insertions, 11 deletions
diff --git a/app/services/clusters/gcp/provision_service.rb b/app/services/clusters/gcp/provision_service.rb index ab1bf9c64f6..0d8b39a552b 100644 --- a/app/services/clusters/gcp/provision_service.rb +++ b/app/services/clusters/gcp/provision_service.rb @@ -27,7 +27,9 @@ module Clusters provider.zone, provider.cluster.name, provider.num_nodes, - machine_type: provider.machine_type) + machine_type: provider.machine_type, + legacy_abac: true + ) unless operation.status == 'PENDING' || operation.status == 'RUNNING' return provider.make_errored!("Operation status is unexpected; #{operation.status_message}") diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb index 36859b4d025..77b6610286f 100644 --- a/lib/google_api/cloud_platform/client.rb +++ b/lib/google_api/cloud_platform/client.rb @@ -50,7 +50,7 @@ module GoogleApi service.get_zone_cluster(project_id, zone, cluster_id, options: user_agent_header) end - def projects_zones_clusters_create(project_id, zone, cluster_name, cluster_size, machine_type:) + def projects_zones_clusters_create(project_id, zone, cluster_name, cluster_size, machine_type:, legacy_abac:) service = Google::Apis::ContainerV1::ContainerService.new service.authorization = access_token @@ -63,7 +63,7 @@ module GoogleApi "machine_type": machine_type }, "legacy_abac": { - "enabled": true + "enabled": legacy_abac } } } diff --git a/spec/lib/google_api/cloud_platform/client_spec.rb b/spec/lib/google_api/cloud_platform/client_spec.rb index 27cb3198e5b..e2134dc279c 100644 --- a/spec/lib/google_api/cloud_platform/client_spec.rb +++ b/spec/lib/google_api/cloud_platform/client_spec.rb @@ -66,25 +66,30 @@ describe GoogleApi::CloudPlatform::Client do describe '#projects_zones_clusters_create' do subject do client.projects_zones_clusters_create( - spy, spy, cluster_name, cluster_size, machine_type: machine_type) + project_id, zone, cluster_name, cluster_size, machine_type: machine_type, legacy_abac: legacy_abac) end + let(:project_id) { 'project-123' } + let(:zone) { 'us-central1-a' } let(:cluster_name) { 'test-cluster' } let(:cluster_size) { 1 } let(:machine_type) { 'n1-standard-2' } + let(:legacy_abac) { true } + let(:create_cluster_request_body) { double('Google::Apis::ContainerV1::CreateClusterRequest') } let(:operation) { double } before do allow_any_instance_of(Google::Apis::ContainerV1::ContainerService) - .to receive(:create_cluster).with(any_args, options: user_agent_options) + .to receive(:create_cluster).with(any_args) .and_return(operation) end - it { is_expected.to eq(operation) } - it 'sets corresponded parameters' do - expect_any_instance_of(Google::Apis::ContainerV1::CreateClusterRequest) - .to receive(:initialize).with( + expect_any_instance_of(Google::Apis::ContainerV1::ContainerService) + .to receive(:create_cluster).with(project_id, zone, create_cluster_request_body, options: user_agent_options) + + expect(Google::Apis::ContainerV1::CreateClusterRequest) + .to receive(:new).with( { "cluster": { "name": cluster_name, @@ -96,9 +101,35 @@ describe GoogleApi::CloudPlatform::Client do "enabled": true } } - } ) + } ).and_return(create_cluster_request_body) + + expect(subject).to eq operation + end + + context 'create without legacy_abac' do + let(:legacy_abac) { false } + + it 'sets corresponded parameters' do + expect_any_instance_of(Google::Apis::ContainerV1::ContainerService) + .to receive(:create_cluster).with(project_id, zone, create_cluster_request_body, options: user_agent_options) + + expect(Google::Apis::ContainerV1::CreateClusterRequest) + .to receive(:new).with( + { + "cluster": { + "name": cluster_name, + "initial_node_count": cluster_size, + "node_config": { + "machine_type": machine_type + }, + "legacy_abac": { + "enabled": false + } + } + } ).and_return(create_cluster_request_body) - subject + expect(subject).to eq operation + end end end |