Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
31c89258
Commit
31c89258
authored
Oct 05, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spec/lib/google_api/auth_spec. spec/lib/google_api/cloud_platform/client_spec
parent
6b07aa5e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
154 additions
and
1 deletion
+154
-1
lib/google_api/cloud_platform/client.rb
lib/google_api/cloud_platform/client.rb
+2
-1
spec/lib/google_api/auth_spec.rb
spec/lib/google_api/auth_spec.rb
+41
-0
spec/lib/google_api/cloud_platform/client_spec.rb
spec/lib/google_api/cloud_platform/client_spec.rb
+111
-0
No files found.
lib/google_api/cloud_platform/client.rb
View file @
31c89258
...
@@ -65,7 +65,8 @@ module GoogleApi
...
@@ -65,7 +65,8 @@ module GoogleApi
end
end
def
parse_operation_id
(
self_link
)
def
parse_operation_id
(
self_link
)
self_link
.
match
(
%r{projects/.*/zones/.*/operations/(.*)}
)[
1
]
m
=
self_link
.
match
(
%r{projects/.*/zones/.*/operations/(.*)}
)
m
[
1
]
if
m
end
end
end
end
end
end
...
...
spec/lib/google_api/auth_spec.rb
0 → 100644
View file @
31c89258
require
'spec_helper'
describe
GoogleApi
::
Auth
do
let
(
:redirect_uri
)
{
'http://localhost:3000/google_api/authorizations/callback'
}
let
(
:redirect_to
)
{
'http://localhost:3000/namaspace/project/clusters'
}
let
(
:client
)
do
GoogleApi
::
CloudPlatform
::
Client
.
new
(
nil
,
redirect_uri
,
state:
redirect_to
)
end
describe
'#authorize_url'
do
subject
{
client
.
authorize_url
}
it
'returns authorize_url'
do
is_expected
.
to
start_with
(
'https://accounts.google.com/o/oauth2'
)
is_expected
.
to
include
(
URI
.
encode
(
redirect_uri
,
URI
::
PATTERN
::
RESERVED
))
is_expected
.
to
include
(
URI
.
encode
(
redirect_to
,
URI
::
PATTERN
::
RESERVED
))
end
end
describe
'#get_token'
do
let
(
:token
)
do
double
.
tap
do
|
dbl
|
allow
(
dbl
).
to
receive
(
:token
).
and_return
(
'token'
)
allow
(
dbl
).
to
receive
(
:expires_at
).
and_return
(
'expires_at'
)
end
end
before
do
allow_any_instance_of
(
OAuth2
::
Strategy
::
AuthCode
)
.
to
receive
(
:get_token
).
and_return
(
token
)
end
it
'returns token and expires_at'
do
token
,
expires_at
=
client
.
get_token
(
'xxx'
)
expect
(
token
).
to
eq
(
'token'
)
expect
(
expires_at
).
to
eq
(
'expires_at'
)
end
end
end
spec/lib/google_api/cloud_platform/client_spec.rb
0 → 100644
View file @
31c89258
require
'spec_helper'
describe
GoogleApi
::
CloudPlatform
::
Client
do
let
(
:token
)
{
'token'
}
let
(
:client
)
{
described_class
.
new
(
token
,
nil
)
}
describe
'#validate_token'
do
subject
{
client
.
validate_token
(
expires_at
)
}
let
(
:expires_at
)
{
1
.
hour
.
since
.
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
.
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment