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
Boxiang Sun
gitlab-ce
Commits
98cf3a0b
Commit
98cf3a0b
authored
Jun 05, 2018
by
Dennis Tang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update tests
parent
3ba9a372
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
142 deletions
+164
-142
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+95
-0
spec/controllers/projects/clusters/user_controller_spec.rb
spec/controllers/projects/clusters/user_controller_spec.rb
+57
-0
spec/controllers/projects/clusters_controller_spec.rb
spec/controllers/projects/clusters_controller_spec.rb
+12
-142
No files found.
spec/controllers/projects/clusters/gcp_controller_spec.rb
0 → 100644
View file @
98cf3a0b
require
'spec_helper'
describe
Projects
::
Clusters
::
GcpController
do
include
AccessMatchersForController
include
GoogleApi
::
CloudPlatformHelpers
set
(
:project
)
{
create
(
:project
)
}
describe
'POST create'
do
let
(
:params
)
do
{
cluster:
{
name:
'new-cluster'
,
provider_gcp_attributes:
{
gcp_project_id:
'111'
}
}
}
end
before
do
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:projects_zones_clusters_create
)
do
OpenStruct
.
new
(
self_link:
'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123'
,
status:
'RUNNING'
)
end
end
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when access token is valid'
do
before
do
stub_google_api_validate_token
end
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
context
'when access token is expired'
do
before
do
stub_google_api_expired_token
end
it
'redirects to new clusters form'
do
puts
described_class
expect
(
go
).
to
redirect_to
(
new_project_cluster_path
(
project
))
end
end
context
'when access token is not stored in session'
do
it
'redirects to new clusters form'
do
expect
(
go
).
to
redirect_to
(
new_project_cluster_path
(
project
))
end
end
end
describe
'security'
do
before
do
allow_any_instance_of
(
described_class
)
.
to
receive
(
:token_in_session
).
and_return
(
'token'
)
allow_any_instance_of
(
described_class
)
.
to
receive
(
:expires_at_in_session
).
and_return
(
1
.
hour
.
since
.
to_i
.
to_s
)
allow
(
WaitForClusterCreationWorker
).
to
receive
(
:perform_in
).
and_return
(
nil
)
end
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
end
spec/controllers/projects/clusters/user_controller_spec.rb
0 → 100644
View file @
98cf3a0b
require
'spec_helper'
describe
Projects
::
Clusters
::
UserController
do
include
AccessMatchersForController
set
(
:project
)
{
create
(
:project
)
}
describe
'POST create'
do
let
(
:params
)
do
{
cluster:
{
name:
'new-cluster'
,
platform_kubernetes_attributes:
{
api_url:
'http://my-url'
,
token:
'test'
,
namespace:
'aaa'
}
}
}
end
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when creates a cluster'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Platforms
::
Kubernetes
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
clusters
.
first
))
expect
(
project
.
clusters
.
first
).
to
be_user
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
end
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
end
spec/controllers/projects/clusters_controller_spec.rb
View file @
98cf3a0b
...
...
@@ -3,6 +3,7 @@ require 'spec_helper'
describe
Projects
::
ClustersController
do
include
AccessMatchersForController
include
GoogleApi
::
CloudPlatformHelpers
include
ClustersHelper
set
(
:project
)
{
create
(
:project
)
}
...
...
@@ -75,12 +76,13 @@ describe Projects::ClustersController do
end
describe
'GET new'
do
describe
'functionality for
new
cluster'
do
describe
'functionality for
gcp
cluster'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
@project
=
project
end
context
'when omniauth has been configured'
do
...
...
@@ -93,10 +95,10 @@ describe Projects::ClustersController do
allow
(
SecureRandom
).
to
receive
(
:hex
).
and_return
(
key
)
end
it
'has authorize_url'
do
it
'has
gcp_
authorize_url'
do
go
expect
(
assigns
(
:authorize_url
)
).
to
include
(
key
)
expect
(
gcp_authorize_url
).
to
include
(
key
)
expect
(
session
[
session_key_for_redirect_uri
]).
to
eq
(
new_project_cluster_path
(
project
))
end
end
...
...
@@ -106,10 +108,10 @@ describe Projects::ClustersController do
stub_omniauth_setting
(
providers:
[])
end
it
'does not have authorize_url'
do
it
'does not have
gcp_
authorize_url'
do
go
expect
(
assigns
(
:authorize_url
)
).
to
be_nil
expect
(
gcp_authorize_url
).
to
be_nil
end
end
...
...
@@ -121,7 +123,7 @@ describe Projects::ClustersController do
it
'has new object'
do
go
expect
(
assigns
(
:
new
_cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
expect
(
assigns
(
:
gcp
_cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
end
end
...
...
@@ -130,15 +132,15 @@ describe Projects::ClustersController do
stub_google_api_expired_token
end
it
{
expect
(
@
valid_gcp_token
).
to
be_falsey
}
it
{
expect
(
valid_gcp_token
).
to
be_falsey
}
end
context
'when access token is not stored in session'
do
it
{
expect
(
@
valid_gcp_token
).
to
be_falsey
}
it
{
expect
(
valid_gcp_token
).
to
be_falsey
}
end
end
describe
'functionality for
existing
cluster'
do
describe
'functionality for
user
cluster'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
...
...
@@ -149,7 +151,7 @@ describe Projects::ClustersController do
it
'has new object'
do
go
expect
(
assigns
(
:
existing
_cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
expect
(
assigns
(
:
user
_cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
end
end
...
...
@@ -169,138 +171,6 @@ describe Projects::ClustersController do
end
end
describe
'POST create for new cluster'
do
let
(
:params
)
do
{
type:
'new'
,
cluster:
{
name:
'new-cluster'
,
provider_gcp_attributes:
{
gcp_project_id:
'gcp-project-12345'
}
}
}
end
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when access token is valid'
do
before
do
stub_google_api_validate_token
end
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
context
'when access token is expired'
do
before
do
stub_google_api_expired_token
end
it
{
expect
(
@valid_gcp_token
).
to
be_falsey
}
end
context
'when access token is not stored in session'
do
it
{
expect
(
@valid_gcp_token
).
to
be_falsey
}
end
end
describe
'security'
do
before
do
allow_any_instance_of
(
described_class
)
.
to
receive
(
:token_in_session
).
and_return
(
'token'
)
allow_any_instance_of
(
described_class
)
.
to
receive
(
:expires_at_in_session
).
and_return
(
1
.
hour
.
since
.
to_i
.
to_s
)
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:projects_zones_clusters_create
)
do
OpenStruct
.
new
(
self_link:
'projects/gcp-project-12345/zones/us-central1-a/operations/ope-123'
,
status:
'RUNNING'
)
end
allow
(
WaitForClusterCreationWorker
).
to
receive
(
:perform_in
).
and_return
(
nil
)
end
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
describe
'POST create for existing cluster'
do
let
(
:params
)
do
{
type:
'existing'
,
cluster:
{
name:
'new-cluster'
,
platform_kubernetes_attributes:
{
api_url:
'http://my-url'
,
token:
'test'
,
namespace:
'aaa'
}
}
}
end
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
context
'when creates a cluster'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
.
and
change
{
Clusters
::
Platforms
::
Kubernetes
.
count
}
expect
(
response
).
to
redirect_to
(
project_cluster_path
(
project
,
project
.
clusters
.
first
))
expect
(
project
.
clusters
.
first
).
to
be_user
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
end
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
post
:create
,
params
.
merge
(
namespace_id:
project
.
namespace
,
project_id:
project
)
end
end
describe
'GET status'
do
let
(
:cluster
)
{
create
(
:cluster
,
:providing_by_gcp
,
projects:
[
project
])
}
...
...
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