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
45f2d0af
Commit
45f2d0af
authored
Nov 22, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test suit for platform::kubernetes
parent
a8e2094c
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
219 additions
and
82 deletions
+219
-82
app/models/project.rb
app/models/project.rb
+7
-7
spec/controllers/projects/branches_controller_spec.rb
spec/controllers/projects/branches_controller_spec.rb
+18
-0
spec/features/auto_deploy_spec.rb
spec/features/auto_deploy_spec.rb
+83
-30
spec/features/projects/environments/environment_spec.rb
spec/features/projects/environments/environment_spec.rb
+32
-19
spec/features/projects/environments/environments_spec.rb
spec/features/projects/environments/environments_spec.rb
+23
-10
spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb
spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb
+17
-4
spec/models/project_spec.rb
spec/models/project_spec.rb
+18
-5
spec/support/prometheus/additional_metrics_shared_examples.rb
.../support/prometheus/additional_metrics_shared_examples.rb
+21
-7
No files found.
app/models/project.rb
View file @
45f2d0af
...
@@ -914,13 +914,6 @@ class Project < ActiveRecord::Base
...
@@ -914,13 +914,6 @@ class Project < ActiveRecord::Base
deployment_platform
deployment_platform
end
end
# TODO: This will be extended for multiple enviroment clusters
# TODO: Add super nice tests to check this interchangeability
def
deployment_platform
@deployment_platform
||=
clusters
.
where
(
enabled:
true
).
first
&
.
platform_kubernetes
@deployment_platform
||=
deployment_services
.
reorder
(
nil
).
find_by
(
active:
true
)
end
def
monitoring_services
def
monitoring_services
services
.
where
(
category: :monitoring
)
services
.
where
(
category: :monitoring
)
end
end
...
@@ -1858,4 +1851,11 @@ class Project < ActiveRecord::Base
...
@@ -1858,4 +1851,11 @@ class Project < ActiveRecord::Base
raise
ex
raise
ex
end
end
# TODO: This will be extended for multiple enviroment clusters
# TODO: Add super nice tests to check this interchangeability
def
deployment_platform
@deployment_platform
||=
clusters
.
where
(
enabled:
true
).
first
&
.
platform_kubernetes
@deployment_platform
||=
deployment_services
.
reorder
(
nil
).
find_by
(
active:
true
)
end
end
end
spec/controllers/projects/branches_controller_spec.rb
View file @
45f2d0af
...
@@ -130,6 +130,24 @@ describe Projects::BranchesController do
...
@@ -130,6 +130,24 @@ describe Projects::BranchesController do
expect
(
response
.
location
).
to
include
(
project_new_blob_path
(
project
,
branch
))
expect
(
response
.
location
).
to
include
(
project_new_blob_path
(
project
,
branch
))
expect
(
response
).
to
have_gitlab_http_status
(
302
)
expect
(
response
).
to
have_gitlab_http_status
(
302
)
end
end
it
'redirects to autodeploy setup page'
do
result
=
{
status: :success
,
branch:
double
(
name:
branch
)
}
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
expect_any_instance_of
(
CreateBranchService
).
to
receive
(
:execute
).
and_return
(
result
)
expect
(
SystemNoteService
).
to
receive
(
:new_issue_branch
).
and_return
(
true
)
post
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
branch_name:
branch
,
issue_iid:
issue
.
iid
expect
(
response
.
location
).
to
include
(
project_new_blob_path
(
project
,
branch
))
expect
(
response
).
to
have_gitlab_http_status
(
302
)
end
end
end
context
'without issue feature access'
do
context
'without issue feature access'
do
...
...
spec/features/auto_deploy_spec.rb
View file @
45f2d0af
...
@@ -4,6 +4,7 @@ describe 'Auto deploy' do
...
@@ -4,6 +4,7 @@ describe 'Auto deploy' do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
context
'when user configured kubernetes from Integration > Kubernetes'
do
before
do
before
do
create
:kubernetes_service
,
project:
project
create
:kubernetes_service
,
project:
project
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
...
@@ -52,4 +53,56 @@ describe 'Auto deploy' do
...
@@ -52,4 +53,56 @@ describe 'Auto deploy' do
expect
(
page
).
to
have_content
(
'New Merge Request From auto-deploy into master'
)
expect
(
page
).
to
have_content
(
'New Merge Request From auto-deploy into master'
)
end
end
end
end
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
before
do
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
project
.
team
<<
[
user
,
:master
]
sign_in
user
end
context
'when no deployment service is active'
do
before
do
project
.
kubernetes_service
.
update!
(
active:
false
)
end
it
'does not show a button to set up auto deploy'
do
visit
project_path
(
project
)
expect
(
page
).
to
have_no_content
(
'Set up auto deploy'
)
end
end
context
'when a deployment service is active'
do
before
do
project
.
kubernetes_service
.
update!
(
active:
true
)
visit
project_path
(
project
)
end
it
'shows a button to set up auto deploy'
do
expect
(
page
).
to
have_link
(
'Set up auto deploy'
)
end
it
'includes OpenShift as an available template'
,
:js
do
click_link
'Set up auto deploy'
click_button
'Apply a GitLab CI Yaml template'
within
'.gitlab-ci-yml-selector'
do
expect
(
page
).
to
have_content
(
'OpenShift'
)
end
end
it
'creates a merge request using "auto-deploy" branch'
,
:js
do
click_link
'Set up auto deploy'
click_button
'Apply a GitLab CI Yaml template'
within
'.gitlab-ci-yml-selector'
do
click_on
'OpenShift'
end
wait_for_requests
click_button
'Commit changes'
expect
(
page
).
to
have_content
(
'New Merge Request From auto-deploy into master'
)
end
end
end
end
end
spec/features/projects/environments/environment_spec.rb
View file @
45f2d0af
...
@@ -101,8 +101,7 @@ feature 'Environment' do
...
@@ -101,8 +101,7 @@ feature 'Environment' do
end
end
context
'with terminal'
do
context
'with terminal'
do
let
(
:project
)
{
create
(
:kubernetes_project
,
:test_repo
)
}
shared_examples
'correct behavior with terminal'
do
context
'for project master'
do
context
'for project master'
do
let
(
:role
)
{
:master
}
let
(
:role
)
{
:master
}
...
@@ -133,6 +132,20 @@ feature 'Environment' do
...
@@ -133,6 +132,20 @@ feature 'Environment' do
end
end
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:kubernetes_project
,
:test_repo
)
}
it_behaves_like
'correct behavior with terminal'
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
it_behaves_like
'correct behavior with terminal'
end
end
context
'when environment is available'
do
context
'when environment is available'
do
context
'with stop action'
do
context
'with stop action'
do
given
(
:action
)
do
given
(
:action
)
do
...
...
spec/features/projects/environments/environments_spec.rb
View file @
45f2d0af
...
@@ -208,8 +208,7 @@ feature 'Environments page', :js do
...
@@ -208,8 +208,7 @@ feature 'Environments page', :js do
end
end
context
'when kubernetes terminal is available'
do
context
'when kubernetes terminal is available'
do
let
(
:project
)
{
create
(
:kubernetes_project
,
:test_repo
)
}
shared_examples
'correct behavior with terminal'
do
context
'for project master'
do
context
'for project master'
do
let
(
:role
)
{
:master
}
let
(
:role
)
{
:master
}
...
@@ -226,6 +225,20 @@ feature 'Environments page', :js do
...
@@ -226,6 +225,20 @@ feature 'Environments page', :js do
end
end
end
end
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:kubernetes_project
,
:test_repo
)
}
it_behaves_like
'correct behavior with terminal'
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
it_behaves_like
'correct behavior with terminal'
end
end
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/build/policy/kubernetes_spec.rb
View file @
45f2d0af
...
@@ -4,14 +4,27 @@ describe Gitlab::Ci::Build::Policy::Kubernetes do
...
@@ -4,14 +4,27 @@ describe Gitlab::Ci::Build::Policy::Kubernetes do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
context
'when kubernetes service is active'
do
context
'when kubernetes service is active'
do
set
(
:project
)
{
create
(
:kubernetes_project
)
}
shared_examples
'correct behavior for satisfied_by?'
do
it
'is satisfied by a kubernetes pipeline'
do
it
'is satisfied by a kubernetes pipeline'
do
expect
(
described_class
.
new
(
'active'
))
expect
(
described_class
.
new
(
'active'
))
.
to
be_satisfied_by
(
pipeline
)
.
to
be_satisfied_by
(
pipeline
)
end
end
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
it_behaves_like
'correct behavior for satisfied_by?'
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
it_behaves_like
'correct behavior for satisfied_by?'
end
end
context
'when kubernetes service is inactive'
do
context
'when kubernetes service is inactive'
do
set
(
:project
)
{
create
(
:project
)
}
set
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/project_spec.rb
View file @
45f2d0af
...
@@ -2002,14 +2002,27 @@ describe Project do
...
@@ -2002,14 +2002,27 @@ describe Project do
end
end
context
'when project has a deployment service'
do
context
'when project has a deployment service'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
shared_examples
'correct behavior with variables'
do
it
'returns variables from this service'
do
it
'returns variables from this service'
do
expect
(
project
.
deployment_variables
).
to
include
(
expect
(
project
.
deployment_variables
).
to
include
(
{
key:
'KUBE_TOKEN'
,
value:
project
.
kubernetes_service
.
token
,
public:
false
}
{
key:
'KUBE_TOKEN'
,
value:
project
.
kubernetes_service
.
token
,
public:
false
}
)
)
end
end
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
it_behaves_like
'correct behavior with variables'
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
it_behaves_like
'correct behavior with variables'
end
end
end
end
describe
'#secret_variables_for'
do
describe
'#secret_variables_for'
do
...
...
spec/support/prometheus/additional_metrics_shared_examples.rb
View file @
45f2d0af
...
@@ -41,7 +41,7 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -41,7 +41,7 @@ RSpec.shared_examples 'additional metrics query' do
end
end
describe
'project has Kubernetes service'
do
describe
'project has Kubernetes service'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
shared_examples
'correct behavior with metrics'
do
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
,
project:
project
)
}
let
(
:environment
)
{
create
(
:environment
,
slug:
'environment-slug'
,
project:
project
)
}
let
(
:kube_namespace
)
{
project
.
kubernetes_service
.
actual_namespace
}
let
(
:kube_namespace
)
{
project
.
kubernetes_service
.
actual_namespace
}
...
@@ -54,6 +54,20 @@ RSpec.shared_examples 'additional metrics query' do
...
@@ -54,6 +54,20 @@ RSpec.shared_examples 'additional metrics query' do
end
end
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:kubernetes_project
)
}
it_behaves_like
'correct behavior with metrics'
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
let
(
:project
)
{
cluster
.
project
}
it_behaves_like
'correct behavior with metrics'
end
end
describe
'project without Kubernetes service'
do
describe
'project without Kubernetes service'
do
it_behaves_like
'query context containing environment slug and filter'
it_behaves_like
'query context containing environment slug and filter'
...
...
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