1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
require 'spec_helper'
describe GoogleApi::CloudPlatform::Client do
let(:token) { 'token' }
let(:client) { described_class.new(token, nil) }
describe '.session_key_for_second_redirect_uri' do
subject { described_class.session_key_for_second_redirect_uri(secure: secure) }
context 'when pass a postfix' do
let(:secure) { SecureRandom.hex }
it 'creates a required session key' do
key, _ = described_class.session_key_for_second_redirect_uri(secure: secure)
expect(key).to eq("cloud_platform_second_redirect_uri_#{secure}")
end
end
context 'when pass a postfix' do
let(:secure) { nil }
it 'creates a new session key' do
key, secure = described_class.session_key_for_second_redirect_uri
expect(key).to include('cloud_platform_second_redirect_uri_')
expect(secure).not_to be_nil
end
end
end
describe '#validate_token' do
subject { client.validate_token(expires_at) }
let(:expires_at) { 1.hour.since.utc.strftime('%s') }
context 'when token is nil' do
let(:token) { nil }
it { is_expected.to be_falsy }
end
context 'when expires_at is nil' do
let(:expires_at) { nil }
it { is_expected.to be_falsy }
end
context 'when expires in 1 hour' do
it { is_expected.to be_truthy }
end
context 'when expires in 10 minutes' do
let(:expires_at) { 5.minutes.since.utc.strftime('%s') }
it { is_expected.to be_falsy }
end
end
describe '#projects_zones_clusters_get' do
subject { client.projects_zones_clusters_get(spy, spy, spy) }
let(:gke_cluster) { double }
before do
allow_any_instance_of(Google::Apis::ContainerV1::ContainerService)
.to receive(:get_zone_cluster).and_return(gke_cluster)
end
it { is_expected.to eq(gke_cluster) }
end
describe '#projects_zones_clusters_create' do
subject do
client.projects_zones_clusters_create(
spy, spy, cluster_name, cluster_size, machine_type: machine_type)
end
let(:cluster_name) { 'test-cluster' }
let(:cluster_size) { 1 }
let(:machine_type) { 'n1-standard-4' }
let(:operation) { double }
before do
allow_any_instance_of(Google::Apis::ContainerV1::ContainerService)
.to receive(:create_cluster).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(
{
"cluster": {
"name": cluster_name,
"initial_node_count": cluster_size,
"node_config": {
"machine_type": machine_type
}
}
} )
subject
end
end
describe '#projects_zones_operations' do
subject { client.projects_zones_operations(spy, spy, spy) }
let(:operation) { double }
before do
allow_any_instance_of(Google::Apis::ContainerV1::ContainerService)
.to receive(:get_zone_operation).and_return(operation)
end
it { is_expected.to eq(operation) }
end
describe '#parse_operation_id' do
subject { client.parse_operation_id(self_link) }
context 'when expected url' do
let(:self_link) do
'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123'
end
it { is_expected.to eq('ope-123') }
end
context 'when unexpected url' do
let(:self_link) { '???' }
it { is_expected.to be_nil }
end
end
end
|