Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-10-31 11:47:48 +0300
committerShinya Maeda <shinya@gitlab.com>2017-10-31 11:47:48 +0300
commit6a65e2f5f94781a69f3f7fb329483ead6bc81fd9 (patch)
tree166567d712cfb4337058ca65d6dbd71cb299aa13 /spec/support/google_api/cloud_platform_helpers.rb
parent944149ec1602e72215283a77ab0b72dabd7ce8b8 (diff)
specs for controller. Improved validation
Diffstat (limited to 'spec/support/google_api/cloud_platform_helpers.rb')
-rw-r--r--spec/support/google_api/cloud_platform_helpers.rb150
1 files changed, 150 insertions, 0 deletions
diff --git a/spec/support/google_api/cloud_platform_helpers.rb b/spec/support/google_api/cloud_platform_helpers.rb
new file mode 100644
index 00000000000..ef73add3991
--- /dev/null
+++ b/spec/support/google_api/cloud_platform_helpers.rb
@@ -0,0 +1,150 @@
+module GoogleApi
+ module CloudPlatformHelpers
+ def stub_google_api_validate_token
+ request.session[GoogleApi::CloudPlatform::Client.session_key_for_token] = 'token'
+ request.session[GoogleApi::CloudPlatform::Client.session_key_for_expires_at] = 1.hour.since.to_i.to_s
+ end
+
+ def stub_google_api_expired_token
+ request.session[GoogleApi::CloudPlatform::Client.session_key_for_token] = 'token'
+ request.session[GoogleApi::CloudPlatform::Client.session_key_for_expires_at] = 1.hour.ago.to_i.to_s
+ end
+
+ def stub_cloud_platform_get_zone_cluster(project_id, zone, cluster_id, **options)
+ WebMock.stub_request(:get, cloud_platform_get_zone_cluster_url(project_id, zone, cluster_id))
+ .to_return(cloud_platform_response(cloud_platform_cluster_body(options)))
+ end
+
+ def stub_cloud_platform_get_zone_cluster_error(project_id, zone, cluster_id)
+ WebMock.stub_request(:get, cloud_platform_get_zone_cluster_url(project_id, zone, cluster_id))
+ .to_return(status: [500, "Internal Server Error"])
+ end
+
+ def stub_cloud_platform_create_cluster(project_id, zone, **options)
+ WebMock.stub_request(:post, cloud_platform_create_cluster_url(project_id, zone))
+ .to_return(cloud_platform_response(cloud_platform_operation_body(options)))
+ end
+
+ def stub_cloud_platform_create_cluster_error(project_id, zone)
+ WebMock.stub_request(:post, cloud_platform_create_cluster_url(project_id, zone))
+ .to_return(status: [500, "Internal Server Error"])
+ end
+
+ def stub_cloud_platform_get_zone_operation(project_id, zone, operation_id, **options)
+ WebMock.stub_request(:get, cloud_platform_get_zone_operation_url(project_id, zone, operation_id))
+ .to_return(cloud_platform_response(cloud_platform_operation_body(options)))
+ end
+
+ def stub_cloud_platform_get_zone_operation_error(project_id, zone, operation_id)
+ WebMock.stub_request(:get, cloud_platform_get_zone_operation_url(project_id, zone, operation_id))
+ .to_return(status: [500, "Internal Server Error"])
+ end
+
+ def cloud_platform_get_zone_cluster_url(project_id, zone, cluster_id)
+ "https://container.googleapis.com/v1/projects/#{project_id}/zones/#{zone}/clusters/#{cluster_id}"
+ end
+
+ def cloud_platform_create_cluster_url(project_id, zone)
+ "https://container.googleapis.com/v1/projects/#{project_id}/zones/#{zone}/clusters"
+ end
+
+ def cloud_platform_get_zone_operation_url(project_id, zone, operation_id)
+ "https://container.googleapis.com/v1/projects/#{project_id}/zones/#{zone}/operations/#{operation_id}"
+ end
+
+ def cloud_platform_response(body)
+ { status: 200, headers: { 'Content-Type' => 'application/json' }, body: body.to_json }
+ end
+
+ def load_sample_cert
+ pem_file = File.expand_path(Rails.root.join('spec/fixtures/clusters/sample_cert.pem'))
+ Base64.encode64(File.read(pem_file))
+ end
+
+ def cloud_platform_cluster_body(**options)
+ {
+ "name": options[:name] || 'string',
+ "description": options[:description] || 'string',
+ "initialNodeCount": options[:initialNodeCount] || 'number',
+ # "nodeConfig": {,
+ # object(NodeConfig),
+ # },,
+ "masterAuth": {
+ "username": options[:username] || 'string',
+ "password": options[:password] || 'string',
+ # "clientCertificateConfig": {
+ # object(ClientCertificateConfig)
+ # },
+ "clusterCaCertificate": options[:clusterCaCertificate] || load_sample_cert,
+ "clientCertificate": options[:clientCertificate] || 'string',
+ "clientKey": options[:clientKey] || 'string'
+ },
+ "loggingService": options[:loggingService] || 'string',
+ "monitoringService": options[:monitoringService] || 'string',
+ "network": options[:network] || 'string',
+ "clusterIpv4Cidr": options[:clusterIpv4Cidr] || 'string',
+ # "addonsConfig": {,
+ # object(AddonsConfig),
+ # },,
+ "subnetwork": options[:subnetwork] || 'string',
+ # "nodePools": [,
+ # {,
+ # object(NodePool),
+ # },
+ # ],,
+ # "locations": [,
+ # string,
+ # ],,
+ "enableKubernetesAlpha": options[:enableKubernetesAlpha] || 'boolean',
+ # "resourceLabels": {,
+ # string: string,,
+ # ...,
+ # },,
+ "labelFingerprint": options[:labelFingerprint] || 'string',
+ # "legacyAbac": {,
+ # object(LegacyAbac),
+ # },
+ # "networkPolicy": {,
+ # object(NetworkPolicy),
+ # },
+ # "ipAllocationPolicy": {,
+ # object(IPAllocationPolicy),
+ # },
+ # "masterAuthorizedNetworksConfig": {,
+ # object(MasterAuthorizedNetworksConfig),
+ # },
+ "selfLink": options[:selfLink] || 'string',
+ "zone": options[:zone] || 'string',
+ "endpoint": options[:endpoint] || 'string',
+ "initialClusterVersion": options[:initialClusterVersion] || 'string',
+ "currentMasterVersion": options[:currentMasterVersion] || 'string',
+ "currentNodeVersion": options[:currentNodeVersion] || 'string',
+ "createTime": options[:createTime] || 'string',
+ "status": options[:status] || 'RUNNING',
+ "statusMessage": options[:statusMessage] || 'string',
+ "nodeIpv4CidrSize": options[:nodeIpv4CidrSize] || 'number',
+ "servicesIpv4Cidr": options[:servicesIpv4Cidr] || 'string',
+ # "instanceGroupUrls": [,
+ # string,
+ # ],,
+ "currentNodeCount": options[:currentNodeCount] || 'number',
+ "expireTime": options[:expireTime] || 'string'
+ }
+ end
+
+ def cloud_platform_operation_body(**options)
+ {
+ "name": options[:name] || 'operation-1234567891234-1234567',
+ "zone": options[:zone] || 'us-central1-a',
+ "operationType": options[:operationType] || 'CREATE_CLUSTER',
+ "status": options[:status] || 'PENDING',
+ "detail": options[:detail] || 'detail',
+ "statusMessage": options[:statusMessage] || '',
+ "selfLink": options[:selfLink] || 'https://container.googleapis.com/v1/projects/123456789101/zones/us-central1-a/operations/operation-1234567891234-1234567',
+ "targetLink": options[:targetLink] || 'https://container.googleapis.com/v1/projects/123456789101/zones/us-central1-a/clusters/test-cluster',
+ "startTime": options[:startTime] || '2017-09-13T16:49:13.055601589Z',
+ "endTime": options[:endTime] || ''
+ }
+ end
+ end
+end