Commit 2e47e1f8 authored by Thong Kuah's avatar Thong Kuah

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
parent ab6d74da
...@@ -27,7 +27,9 @@ module Clusters ...@@ -27,7 +27,9 @@ module Clusters
provider.zone, provider.zone,
provider.cluster.name, provider.cluster.name,
provider.num_nodes, provider.num_nodes,
machine_type: provider.machine_type) machine_type: provider.machine_type,
legacy_abac: true
)
unless operation.status == 'PENDING' || operation.status == 'RUNNING' unless operation.status == 'PENDING' || operation.status == 'RUNNING'
return provider.make_errored!("Operation status is unexpected; #{operation.status_message}") return provider.make_errored!("Operation status is unexpected; #{operation.status_message}")
......
...@@ -50,7 +50,7 @@ module GoogleApi ...@@ -50,7 +50,7 @@ module GoogleApi
service.get_zone_cluster(project_id, zone, cluster_id, options: user_agent_header) service.get_zone_cluster(project_id, zone, cluster_id, options: user_agent_header)
end 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 = Google::Apis::ContainerV1::ContainerService.new
service.authorization = access_token service.authorization = access_token
...@@ -63,7 +63,7 @@ module GoogleApi ...@@ -63,7 +63,7 @@ module GoogleApi
"machine_type": machine_type "machine_type": machine_type
}, },
"legacy_abac": { "legacy_abac": {
"enabled": true "enabled": legacy_abac
} }
} }
} }
......
...@@ -66,25 +66,30 @@ describe GoogleApi::CloudPlatform::Client do ...@@ -66,25 +66,30 @@ describe GoogleApi::CloudPlatform::Client do
describe '#projects_zones_clusters_create' do describe '#projects_zones_clusters_create' do
subject do subject do
client.projects_zones_clusters_create( 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 end
let(:project_id) { 'project-123' }
let(:zone) { 'us-central1-a' }
let(:cluster_name) { 'test-cluster' } let(:cluster_name) { 'test-cluster' }
let(:cluster_size) { 1 } let(:cluster_size) { 1 }
let(:machine_type) { 'n1-standard-2' } let(:machine_type) { 'n1-standard-2' }
let(:legacy_abac) { true }
let(:create_cluster_request_body) { double('Google::Apis::ContainerV1::CreateClusterRequest') }
let(:operation) { double } let(:operation) { double }
before do before do
allow_any_instance_of(Google::Apis::ContainerV1::ContainerService) 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) .and_return(operation)
end end
it { is_expected.to eq(operation) }
it 'sets corresponded parameters' do it 'sets corresponded parameters' do
expect_any_instance_of(Google::Apis::ContainerV1::CreateClusterRequest) expect_any_instance_of(Google::Apis::ContainerV1::ContainerService)
.to receive(:initialize).with( .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": { "cluster": {
"name": cluster_name, "name": cluster_name,
...@@ -96,9 +101,35 @@ describe GoogleApi::CloudPlatform::Client do ...@@ -96,9 +101,35 @@ describe GoogleApi::CloudPlatform::Client do
"enabled": true "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
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment