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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
91426093
Commit
91426093
authored
Dec 16, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expand controller test suite matrix
parent
935a27cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
46 deletions
+111
-46
app/controllers/projects/clusters/gcp_controller.rb
app/controllers/projects/clusters/gcp_controller.rb
+3
-2
app/views/projects/clusters/new.html.haml
app/views/projects/clusters/new.html.haml
+1
-1
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+98
-40
spec/support/google_api/cloud_platform_helpers.rb
spec/support/google_api/cloud_platform_helpers.rb
+6
-0
spec/workers/check_gcp_project_billing_worker_spec.rb
spec/workers/check_gcp_project_billing_worker_spec.rb
+3
-3
No files found.
app/controllers/projects/clusters/gcp_controller.rb
View file @
91426093
class
Projects::Clusters::GcpController
<
Projects
::
ApplicationController
before_action
:authorize_read_cluster!
before_action
:authorize_google_api
,
except:
[
:login
]
before_action
:authorize_google_project_billing
,
only:
[
:check
]
before_action
:authorize_google_project_billing
,
except:
[
:login
,
:check
]
before_action
:authorize_create_cluster!
,
only:
[
:new
,
:create
]
STATUS_POLLING_INTERVAL
=
1
.
minute
.
to_i
def
login
begin
state
=
generate_session_key_redirect
(
gcp_
check
_namespace_project_clusters_path
.
to_s
)
state
=
generate_session_key_redirect
(
gcp_
new
_namespace_project_clusters_path
.
to_s
)
@authorize_url
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
nil
,
callback_google_api_auth_url
,
...
...
@@ -76,6 +76,7 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
unless
redis
.
get
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token_in_session
))
==
'true'
CheckGcpProjectBillingWorker
.
perform_async
(
token_in_session
)
redirect_to
action:
'check'
end
end
end
...
...
app/views/projects/clusters/new.html.haml
View file @
91426093
...
...
@@ -8,6 +8,6 @@
%h4
.prepend-top-0
=
s_
(
'ClusterIntegration|Choose how to set up cluster integration'
)
%p
=
s_
(
'ClusterIntegration|Create a new cluster on Google Kubernetes Engine right from GitLab'
)
=
link_to
s_
(
'ClusterIntegration|Create on GKE'
),
gcp_
check
_namespace_project_clusters_path
(
@project
.
namespace
,
@project
),
class:
'btn append-bottom-20'
=
link_to
s_
(
'ClusterIntegration|Create on GKE'
),
gcp_
new
_namespace_project_clusters_path
(
@project
.
namespace
,
@project
),
class:
'btn append-bottom-20'
%p
=
s_
(
'ClusterIntegration|Enter the details for an existing Kubernetes cluster'
)
=
link_to
s_
(
'ClusterIntegration|Add an existing cluster'
),
user_new_namespace_project_clusters_path
(
@project
.
namespace
,
@project
),
class:
'btn append-bottom-20'
spec/controllers/projects/clusters/gcp_controller_spec.rb
View file @
91426093
...
...
@@ -17,7 +17,6 @@ describe Projects::Clusters::GcpController do
context
'when omniauth has been configured'
do
let
(
:key
)
{
'secret-key'
}
let
(
:session_key_for_redirect_uri
)
do
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_redirect_uri
(
key
)
end
...
...
@@ -30,7 +29,7 @@ describe Projects::Clusters::GcpController do
go
expect
(
assigns
(
:authorize_url
)).
to
include
(
key
)
expect
(
session
[
session_key_for_redirect_uri
]).
to
eq
(
gcp_
check
_project_clusters_path
(
project
))
expect
(
session
[
session_key_for_redirect_uri
]).
to
eq
(
gcp_
new
_project_clusters_path
(
project
))
end
end
...
...
@@ -72,47 +71,54 @@ describe Projects::Clusters::GcpController do
end
describe
'functionality'
do
context
'when redis has wanted billing status'
do
let
(
:token
)
{
'bogustoken'
}
context
'when access token is valid'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
'true'
)
stub_google_api_validate_token
end
it
'should render json with billing status'
do
go
context
'when redis has wanted billing status'
do
let
(
:token
)
{
'bogustoken'
}
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
'true'
)
end
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
.
body
).
to
include_json
(
billing:
'true'
)
it
'should render json with billing status'
do
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
include
(
'billing'
=>
'true'
)
end
end
it
'should not start worker'
do
expect
(
CheckGcpProjectBillingWorker
).
not_to
receive
(
:perform_async
)
context
'when redis does not have billing status'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'should render json with null billing status'
do
go
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
JSON
.
parse
(
response
.
body
)).
to
include
(
'billing'
=>
nil
)
end
end
end
context
'when
redis does not have billing status
'
do
context
'when
access token is expired
'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'should render json with null billing status'
do
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
.
body
).
to
include_json
(
billing:
nil
)
stub_google_api_expired_token
end
it
'should start worker'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_project_clusters_path
(
project
))
}
end
g
o
end
context
'when access token is not stored in session'
d
o
it
{
expect
(
go
).
to
redirect_to
(
gcp_login_project_clusters_path
(
project
))
}
end
end
...
...
@@ -146,10 +152,36 @@ describe Projects::Clusters::GcpController do
stub_google_api_validate_token
end
it
'has new object'
do
go
context
'when google project billing status is true'
do
before
do
stub_google_project_billing_status
end
it
'has new object'
do
go
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
end
end
context
'when google project billing status is not true'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'redirects to check page'
do
allow
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
expect
(
go
).
to
redirect_to
(
gcp_check_project_clusters_path
(
project
))
end
it
'calls gcp project billing check worker'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
go
end
end
end
...
...
@@ -207,14 +239,40 @@ describe Projects::Clusters::GcpController do
stub_google_api_validate_token
end
context
'when creates a cluster on gke'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Providers
::
Gcp
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
clusters
.
first
))
expect
(
project
.
clusters
.
first
).
to
be_gcp
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
context
'when google project billing status is true'
do
before
do
stub_google_project_billing_status
end
context
'when creates a cluster on gke'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Providers
::
Gcp
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
clusters
.
first
))
expect
(
project
.
clusters
.
first
).
to
be_gcp
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
end
end
end
context
'when google project billing status is not true'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'redirects to check page'
do
allow
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
expect
(
go
).
to
redirect_to
(
gcp_check_project_clusters_path
(
project
))
end
it
'calls gcp project billing check worker'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
go
end
end
end
...
...
spec/support/google_api/cloud_platform_helpers.rb
View file @
91426093
...
...
@@ -10,6 +10,12 @@ module GoogleApi
request
.
session
[
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_expires_at
]
=
1
.
hour
.
ago
.
to_i
.
to_s
end
def
stub_google_project_billing_status
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
'true'
)
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
)))
...
...
spec/workers/check_gcp_project_billing_worker_spec.rb
View file @
91426093
...
...
@@ -7,7 +7,7 @@ describe CheckGcpProjectBillingWorker do
context
'when there is no lease'
do
before
do
allow_any_instance_of
(
CheckGcpProjectBillingWorker
).
to
receive
(
:try_obtain_lease_for
).
and_return
(
'randomuuid'
)
allow_any_instance_of
(
described_class
).
to
receive
(
:try_obtain_lease_for
).
and_return
(
'randomuuid'
)
end
it
'calls the service'
do
...
...
@@ -21,7 +21,7 @@ describe CheckGcpProjectBillingWorker do
expect
(
CheckGcpProjectBillingService
).
to
receive_message_chain
(
:new
,
:execute
).
and_return
(
true
)
expect
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
expect
(
redis_double
).
to
receive
(
:set
).
with
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token
),
anything
)
expect
(
redis_double
).
to
receive
(
:set
).
with
(
described_class
.
redis_shared_state_key_for
(
token
),
anything
)
subject
end
...
...
@@ -29,7 +29,7 @@ describe CheckGcpProjectBillingWorker do
context
'when there is a lease'
do
before
do
allow_any_instance_of
(
CheckGcpProjectBillingWorker
).
to
receive
(
:try_obtain_lease_for
).
and_return
(
false
)
allow_any_instance_of
(
described_class
).
to
receive
(
:try_obtain_lease_for
).
and_return
(
false
)
end
it
'does not call the service'
do
...
...
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