diff options
author | Thong Kuah <tkuah@gitlab.com> | 2018-09-07 07:23:45 +0300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2018-09-14 07:26:51 +0300 |
commit | 2e47e1f80e000fb717f89effef983bf22c9e2f4d (patch) | |
tree | b926b4c3656ba3b7d5ce2d82001d94f48d7ed541 /spec/lib/google_api/cloud_platform | |
parent | ab6d74da9a31095c17ee4f7fedc0f27a37dde3c1 (diff) |
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
Diffstat (limited to 'spec/lib/google_api/cloud_platform')
-rw-r--r-- | spec/lib/google_api/cloud_platform/client_spec.rb | 47 |
1 files changed, 39 insertions, 8 deletions
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 |