BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
3aafcc16
Unverified
Commit
3aafcc16
authored
Oct 26, 2017
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add KubernetesService#default_namespace tests
parent
6798bab1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
14 deletions
+24
-14
kubernetes_service.rb
app/models/project_services/kubernetes_service.rb
+2
-9
kubernetes_service_spec.rb
spec/models/project_services/kubernetes_service_spec.rb
+22
-5
No files found.
app/models/project_services/kubernetes_service.rb
View file @
3aafcc16
...
...
@@ -155,15 +155,8 @@ class KubernetesService < DeploymentService
def
default_namespace
return
unless
project
# 1. lowercase
# 2. replace non kubernetes characters with dash
# 3. trim dash from the beginning and end
slugified
=
"
#{
project
.
path
}
-
#{
project
.
id
}
"
slugified
.
downcase!
slugified
.
gsub!
(
/[^a-z0-9]/
,
'-'
)
slugified
.
gsub!
(
/^-+|-+$/
,
''
)
slugified
slug
=
"
#{
project
.
path
}
-
#{
project
.
id
}
"
.
downcase
slug
.
gsub
(
/[^-a-z0-9]/
,
'-'
).
gsub
(
/^-+/
,
''
)
end
def
build_kubeclient!
(
api_path:
'api'
,
api_version:
'v1'
)
...
...
spec/models/project_services/kubernetes_service_spec.rb
View file @
3aafcc16
...
...
@@ -99,8 +99,25 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
describe
'#actual_namespace'
do
subject
{
service
.
actual_namespace
}
it
"returns the default namespace"
do
is_expected
.
to
eq
(
service
.
send
(
:default_namespace
))
shared_examples
'a correctly formatted namespace'
do
it
'returns a valid Kubernetes namespace name'
do
expect
(
subject
).
to
match
(
Gitlab
::
Regex
.
kubernetes_namespace_regex
)
expect
(
subject
).
to
eq
(
expected_namespace
)
end
end
it_behaves_like
'a correctly formatted namespace'
do
let
(
:expected_namespace
)
{
service
.
send
(
:default_namespace
)
}
end
context
'when the project path contains forbidden characters'
do
before
do
project
.
path
=
'-a_Strange.Path--forSure'
end
it_behaves_like
'a correctly formatted namespace'
do
let
(
:expected_namespace
)
{
"a-strange-path--forsure-
#{
project
.
id
}
"
}
end
end
context
'when namespace is specified'
do
...
...
@@ -108,8 +125,8 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
service
.
namespace
=
'my-namespace'
end
it
"returns the user-namespace"
do
is_expected
.
to
eq
(
'my-namespace'
)
it
_behaves_like
'a correctly formatted namespace'
do
let
(
:expected_namespace
)
{
'my-namespace'
}
end
end
...
...
@@ -118,7 +135,7 @@ describe KubernetesService, :use_clean_rails_memory_store_caching do
service
.
project
=
nil
end
it
"does not return namespace"
do
it
'does not return namespace'
do
is_expected
.
to
be_nil
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