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
51588269
Commit
51588269
authored
Oct 02, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial take on tests
parent
af2a8cd2
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
74 additions
and
82 deletions
+74
-82
app/models/project_services/mock_deployment_service.rb
app/models/project_services/mock_deployment_service.rb
+1
-1
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+15
-5
app/serializers/rollout_status_serializer.rb
app/serializers/rollout_status_serializer.rb
+0
-3
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+7
-57
spec/ee/spec/models/project_services/kubernetes_service_spec.rb
...e/spec/models/project_services/kubernetes_service_spec.rb
+1
-0
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
+9
-3
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+1
-0
spec/serializers/environment_entity_spec.rb
spec/serializers/environment_entity_spec.rb
+6
-5
spec/serializers/environment_serializer_spec.rb
spec/serializers/environment_serializer_spec.rb
+3
-3
spec/serializers/rollout_status_entity_spec.rb
spec/serializers/rollout_status_entity_spec.rb
+23
-5
spec/support/kubernetes_helpers.rb
spec/support/kubernetes_helpers.rb
+8
-0
No files found.
app/models/project_services/mock_deployment_service.rb
View file @
51588269
...
...
@@ -35,6 +35,6 @@ class MockDeploymentService < DeploymentService
end
def
rollout_status_deployments
[
OpenStruct
.
new
(
instances:
rollout_status_instances
)
]
[
OpenStruct
.
new
(
instances:
rollout_status_instances
)
]
end
end
app/serializers/environment_entity.rb
View file @
51588269
...
...
@@ -9,11 +9,9 @@ class EnvironmentEntity < Grape::Entity
expose
:last_deployment
,
using:
DeploymentEntity
expose
:stop_action?
expose
:rollout_status
,
if:
->
(
environment
,
_
)
{
can?
(
request
.
current_user
,
:read_deploy_board
,
environment
.
project
)
},
using:
RolloutStatusEntity
expose
:rollout_status
,
if:
->
(
*
)
{
can_read_deploy_board?
},
using:
RolloutStatusEntity
expose
:metrics_path
,
if:
->
(
environment
,
_
)
{
environment
.
has_metrics?
}
do
|
environment
|
expose
:metrics_path
,
if:
->
(
*
)
{
environment
.
has_metrics?
}
do
|
environment
|
metrics_project_environment_path
(
environment
.
project
,
environment
)
end
...
...
@@ -25,7 +23,7 @@ class EnvironmentEntity < Grape::Entity
stop_project_environment_path
(
environment
.
project
,
environment
)
end
expose
:terminal_path
,
if:
->
(
environment
,
_
)
{
environment
.
deployment_service_ready?
}
do
|
environment
|
expose
:terminal_path
,
if:
->
(
*
)
{
environment
.
deployment_service_ready?
}
do
|
environment
|
can?
(
request
.
current_user
,
:admin_environment
,
environment
.
project
)
&&
terminal_project_environment_path
(
environment
.
project
,
environment
)
end
...
...
@@ -35,4 +33,16 @@ class EnvironmentEntity < Grape::Entity
end
expose
:created_at
,
:updated_at
private
alias_method
:environment
,
:object
def
current_user
request
.
current_user
end
def
can_read_deploy_board?
can?
(
current_user
,
:read_deploy_board
,
environment
.
project
)
end
end
app/serializers/rollout_status_serializer.rb
deleted
100644 → 0
View file @
af2a8cd2
class
RolloutStatusSerializer
<
BaseSerializer
entity
RolloutStatusEntity
end
spec/controllers/projects/environments_controller_spec.rb
View file @
51588269
require
'spec_helper'
describe
Projects
::
EnvironmentsController
do
include
KubernetesHelpers
set
(
:user
)
{
create
(
:user
)
}
set
(
:project
)
{
create
(
:project
)
}
...
...
@@ -26,6 +28,7 @@ describe Projects::EnvironmentsController do
context
'when requesting JSON response for folders'
do
before
do
allow_any_instance_of
(
Environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
allow_any_instance_of
(
Environment
).
to
receive
(
:rollout_status
).
and_return
(
kube_deployment_rollout_status
)
create
(
:environment
,
project:
project
,
name:
'staging/review-1'
,
...
...
@@ -52,11 +55,11 @@ describe Projects::EnvironmentsController do
it
'responds with a payload describing available environments'
do
expect
(
environments
.
count
).
to
eq
2
expect
(
environments
.
first
[
'name'
]).
to
eq
'production'
expect
(
environments
.
first
[
'latest'
][
'rollout_status
_path
'
]).
to
be_present
expect
(
environments
.
first
[
'latest'
][
'rollout_status'
]).
to
be_present
expect
(
environments
.
second
[
'name'
]).
to
eq
'staging'
expect
(
environments
.
second
[
'size'
]).
to
eq
2
expect
(
environments
.
second
[
'latest'
][
'name'
]).
to
eq
'staging/review-2'
expect
(
environments
.
second
[
'latest'
][
'rollout_status
_path
'
]).
to
be_present
expect
(
environments
.
second
[
'latest'
][
'rollout_status'
]).
to
be_present
end
it
'contains values describing environment scopes sizes'
do
...
...
@@ -96,8 +99,8 @@ describe Projects::EnvironmentsController do
end
it
'does not return the rollout_status_path attribute'
do
expect
(
environments
.
first
[
'latest'
][
'rollout_status
_path'
]).
to
be_blank
expect
(
environments
.
second
[
'latest'
][
'rollout_status
_path'
]).
to
be_blank
expect
(
environments
.
first
[
'latest'
][
'rollout_status
'
]).
not_to
be_present
expect
(
environments
.
second
[
'latest'
][
'rollout_status
'
]).
not_to
be_present
end
end
end
...
...
@@ -289,59 +292,6 @@ describe Projects::EnvironmentsController do
end
end
describe
'GET #status'
do
context
'without deployment service'
do
it
'returns 404'
do
get
:status
,
environment_params
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
'with deployment service'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
let
(
:environment
)
{
create
(
:environment
,
name:
'production'
,
project:
project
)
}
before
do
stub_licensed_features
(
deploy_board:
true
)
allow_any_instance_of
(
Environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
end
it
'returns 204 until the rollout status is present'
do
expect_any_instance_of
(
Environment
)
.
to
receive
(
:rollout_status
)
.
and_return
(
nil
)
get
:status
,
environment_params
expect
(
response
.
status
).
to
eq
(
204
)
expect
(
response
.
headers
[
'Poll-Interval'
]).
to
eq
(
"3000"
)
end
it
'returns the rollout status when present'
do
expect_any_instance_of
(
Environment
)
.
to
receive
(
:rollout_status
)
.
and_return
(
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
new
([]))
get
:status
,
environment_params
expect
(
response
.
status
).
to
eq
(
200
)
end
end
context
'when license does not has the GitLab_DeployBoard add-on'
do
before
do
stub_licensed_features
(
deploy_board:
false
)
end
it
'does not return any data'
do
get
:status
,
environment_params
expect
(
response
).
to
have_http_status
(
:not_found
)
end
end
end
describe
'GET #metrics'
do
before
do
allow
(
controller
).
to
receive
(
:environment
).
and_return
(
environment
)
...
...
spec/ee/spec/models/project_services/kubernetes_service_spec.rb
View file @
51588269
...
...
@@ -9,6 +9,7 @@ describe KubernetesService, models: true, use_clean_rails_memory_store_caching:
describe
'#rollout_status'
do
let
(
:environment
)
{
build
(
:environment
,
project:
project
,
name:
"env"
,
slug:
"env-000000"
)
}
subject
(
:rollout_status
)
{
service
.
rollout_status
(
environment
)
}
context
'with valid deployments'
do
...
...
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
View file @
51588269
...
...
@@ -94,15 +94,21 @@ describe Gitlab::Kubernetes::RolloutStatus do
end
end
describe
'#
vali
d?'
do
describe
'#
foun
d?'
do
context
'when the specs are passed'
do
it
{
is_expected
.
to
be_
vali
d
}
it
{
is_expected
.
to
be_
foun
d
}
end
context
'when no specs are passed'
do
let
(
:specs
)
{
specs_none
}
it
{
is_expected
.
not_to
be_
vali
d
}
it
{
is_expected
.
not_to
be_
foun
d
}
end
end
describe
'.loading_rollout'
do
subject
{
described_class
.
loading_rollout
}
it
{
is_expected
.
to
be_loading
}
end
end
spec/models/environment_spec.rb
View file @
51588269
...
...
@@ -385,6 +385,7 @@ describe Environment do
describe
'#rollout_status'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
subject
{
environment
.
rollout_status
}
context
'when the environment has rollout status'
do
...
...
spec/serializers/environment_entity_spec.rb
View file @
51588269
require
'spec_helper'
describe
EnvironmentEntity
do
include
KubernetesHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:environment
)
{
create
(
:environment
)
}
...
...
@@ -50,12 +52,11 @@ describe EnvironmentEntity do
before
do
stub_licensed_features
(
deploy_board:
true
)
allow
(
environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
allow
(
environment
).
to
receive
(
:rollout_status
).
and_return
(
kube_deployment_rollout_status
)
end
it
'exposes rollout_status_path'
do
expected
=
'/'
+
[
environment
.
project
.
full_path
,
'environments'
,
environment
.
id
,
'status.json'
].
join
(
'/'
)
expect
(
subject
[
:rollout_status_path
]).
to
eq
(
expected
)
it
'exposes rollout_status'
do
expect
(
subject
).
to
include
(
:rollout_status
)
end
end
...
...
@@ -65,7 +66,7 @@ describe EnvironmentEntity do
allow
(
environment
).
to
receive
(
:deployment_service_ready?
).
and_return
(
true
)
end
it
'does not expose rollout_status
_path
'
do
it
'does not expose rollout_status'
do
expect
(
subject
[
:rollout_status_path
]).
to
be_blank
end
end
...
...
spec/serializers/environment_serializer_spec.rb
View file @
51588269
...
...
@@ -54,7 +54,7 @@ describe EnvironmentSerializer do
context
'when representing environments within folders'
do
let
(
:serializer
)
do
described_class
.
new
(
project:
project
).
within_folders
described_class
.
new
(
current_user:
user
,
project:
project
).
within_folders
end
let
(
:resource
)
{
Environment
.
all
}
...
...
@@ -123,7 +123,7 @@ describe EnvironmentSerializer do
let
(
:pagination
)
{
{
page:
1
,
per_page:
2
}
}
let
(
:serializer
)
do
described_class
.
new
(
project:
project
)
described_class
.
new
(
current_user:
user
,
project:
project
)
.
with_pagination
(
request
,
response
)
end
...
...
@@ -169,7 +169,7 @@ describe EnvironmentSerializer do
context
'when grouping environments within folders'
do
let
(
:serializer
)
do
described_class
.
new
(
project:
project
)
described_class
.
new
(
current_user:
user
,
project:
project
)
.
with_pagination
(
request
,
response
)
.
within_folders
end
...
...
spec/serializers/rollout_status_entity_spec.rb
View file @
51588269
...
...
@@ -7,11 +7,29 @@ describe RolloutStatusEntity do
described_class
.
new
(
rollout_status
,
request:
double
)
end
let
(
:rollout_status
)
{
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
(
kube_deployment
)
}
subject
{
entity
.
as_json
}
it
{
is_expected
.
to
have_key
(
:instances
)
}
it
{
is_expected
.
to
have_key
(
:completion
)
}
it
{
is_expected
.
to
have_key
(
:is_completed
)
}
it
{
is_expected
.
to
have_key
(
:valid
)
}
context
'when kube deployment is valid'
do
let
(
:rollout_status
)
{
kube_deployment_rollout_status
}
it
"exposes status"
do
is_expected
.
to
include
(
:status
)
end
it
"exposes deployment data"
do
is_expected
.
to
include
(
:instances
,
:completion
,
:is_completed
)
end
end
context
'when kube deployment is empty'
do
let
(
:rollout_status
)
{
empty_deployment_rollout_status
}
it
"exposes status"
do
is_expected
.
to
include
(
:status
)
end
it
"does not expose deployment data"
do
is_expected
.
not_to
include
(
:instances
,
:completion
,
:is_completed
)
end
end
end
spec/support/kubernetes_helpers.rb
View file @
51588269
...
...
@@ -122,4 +122,12 @@ module KubernetesHelpers
terminal
end
end
def
kube_deployment_rollout_status
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
(
kube_deployment
)
end
def
empty_deployment_rollout_status
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
()
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