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
625cea68
Commit
625cea68
authored
Oct 17, 2019
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for serializing URL when using Knative 0.5
parent
c6494154
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
113 additions
and
46 deletions
+113
-46
spec/controllers/projects/serverless/functions_controller_spec.rb
...trollers/projects/serverless/functions_controller_spec.rb
+90
-44
spec/support/helpers/kubernetes_helpers.rb
spec/support/helpers/kubernetes_helpers.rb
+23
-2
No files found.
spec/controllers/projects/serverless/functions_controller_spec.rb
View file @
625cea68
...
...
@@ -107,26 +107,50 @@ describe Projects::Serverless::FunctionsController do
end
end
context
'valid data'
,
:use_clean_rails_memory_store_caching
do
before
do
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
{
services:
kube_knative_services_body
(
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)[
"items"
],
pods:
kube_knative_pods_body
(
cluster
.
project
.
name
,
namespace
.
namespace
)[
"items"
]
},
*
knative_services_finder
.
cache_args
)
context
'with valid data'
,
:use_clean_rails_memory_store_caching
do
shared_examples
'GET #show with valid data'
do
it
'has a valid function name'
do
get
:show
,
params:
params
({
format: :json
,
environment_id:
"*"
,
id:
cluster
.
project
.
name
})
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
include
(
"name"
=>
project
.
name
,
"url"
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
,
"podcount"
=>
1
)
end
end
it
'has a valid function name'
do
get
:show
,
params:
params
({
format: :json
,
environment_id:
"*"
,
id:
cluster
.
project
.
name
})
expect
(
response
).
to
have_gitlab_http_status
(
200
)
context
'on Knative 0.5'
do
before
do
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
{
services:
kube_knative_services_body
(
legacy_knative:
true
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)[
"items"
],
pods:
kube_knative_pods_body
(
cluster
.
project
.
name
,
namespace
.
namespace
)[
"items"
]
},
*
knative_services_finder
.
cache_args
)
end
expect
(
json_response
).
to
include
(
"name"
=>
project
.
name
,
"url"
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
,
"podcount"
=>
1
)
include_examples
'GET #show with valid data'
end
context
'on Knative 0.6 or 0.7'
do
before
do
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
{
services:
kube_knative_services_body
(
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)[
"items"
],
pods:
kube_knative_pods_body
(
cluster
.
project
.
name
,
namespace
.
namespace
)[
"items"
]
},
*
knative_services_finder
.
cache_args
)
end
include_examples
'GET #show with valid data'
end
end
end
...
...
@@ -141,38 +165,60 @@ describe Projects::Serverless::FunctionsController do
end
describe
'GET #index with data'
,
:use_clean_rails_memory_store_caching
do
before
do
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
{
services:
kube_knative_services_body
(
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)[
"items"
],
pods:
kube_knative_pods_body
(
cluster
.
project
.
name
,
namespace
.
namespace
)[
"items"
]
},
*
knative_services_finder
.
cache_args
)
shared_examples
'GET #index with data'
do
it
'has data'
do
get
:index
,
params:
params
({
format: :json
})
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
match
({
"knative_installed"
=>
"checking"
,
"functions"
=>
[
a_hash_including
(
"name"
=>
project
.
name
,
"url"
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
)
]
})
end
it
'has data in html'
do
get
:index
,
params:
params
expect
(
response
).
to
have_gitlab_http_status
(
200
)
end
end
it
'has data
'
do
get
:index
,
params:
params
({
format: :json
})
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
match
(
{
"knative_installed"
=>
"checking"
,
"functions"
=>
[
a_hash_including
(
"name"
=>
project
.
name
,
"url"
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
)
]
}
)
context
'on Knative 0.5
'
do
before
do
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
{
services:
kube_knative_services_body
(
legacy_knative:
true
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)[
"items"
],
pods:
kube_knative_pods_body
(
cluster
.
project
.
name
,
namespace
.
namespace
)[
"items"
]
},
*
knative_services_finder
.
cache_args
)
end
include_examples
'GET #index with data'
end
it
'has data in html'
do
get
:index
,
params:
params
context
'on Knative 0.6 or 0.7'
do
before
do
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
{
services:
kube_knative_services_body
(
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)[
"items"
],
pods:
kube_knative_pods_body
(
cluster
.
project
.
name
,
namespace
.
namespace
)[
"items"
]
},
*
knative_services_finder
.
cache_args
)
end
expect
(
response
).
to
have_gitlab_http_status
(
200
)
include_examples
'GET #index with data'
end
end
end
spec/support/helpers/kubernetes_helpers.rb
View file @
625cea68
...
...
@@ -319,10 +319,10 @@ module KubernetesHelpers
}
end
def
kube_knative_services_body
(
**
options
)
def
kube_knative_services_body
(
legacy_knative:
false
,
**
options
)
{
"kind"
=>
"List"
,
"items"
=>
[
kube_service
(
options
)]
"items"
=>
[
legacy_knative
?
knative_05_service
(
options
)
:
kube_service
(
options
)]
}
end
...
...
@@ -421,6 +421,27 @@ module KubernetesHelpers
}
end
def
knative_05_service
(
name:
"kubetest"
,
namespace:
"default"
,
domain:
"example.com"
)
{
"metadata"
=>
{
"creationTimestamp"
=>
"2018-11-21T06:16:33Z"
,
"name"
=>
name
,
"namespace"
=>
namespace
,
"selfLink"
=>
"/apis/serving.knative.dev/v1alpha1/namespaces/
#{
namespace
}
/services/
#{
name
}
"
},
"spec"
=>
{
"generation"
=>
2
},
"status"
=>
{
"domain"
=>
"
#{
name
}
.
#{
namespace
}
.
#{
domain
}
"
,
"domainInternal"
=>
"
#{
name
}
.
#{
namespace
}
.svc.cluster.local"
,
"latestCreatedRevisionName"
=>
"
#{
name
}
-00002"
,
"latestReadyRevisionName"
=>
"
#{
name
}
-00002"
,
"observedGeneration"
=>
2
}
}
end
def
kube_service_full
(
name:
"kubetest"
,
namespace:
"kube-ns"
,
domain:
"example.com"
)
{
"metadata"
=>
{
...
...
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