Commit 51fa67e8 authored by Alishan Ladhani's avatar Alishan Ladhani

DRY up the creation of knative stubs

parent dc24b4ab
...@@ -121,39 +121,23 @@ describe Projects::Serverless::FunctionsController do ...@@ -121,39 +121,23 @@ describe Projects::Serverless::FunctionsController do
end end
end end
context 'on Knative 0.5' do context 'on Knative 0.5.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs('0.5.0', namespace: namespace.namespace, name: cluster.project.name)
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 end
include_examples 'GET #show with valid data' include_examples 'GET #show with valid data'
end end
context 'on Knative 0.6' do context 'on Knative 0.6.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs('0.6.0', namespace: namespace.namespace, name: cluster.project.name)
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 end
include_examples 'GET #show with valid data' include_examples 'GET #show with valid data'
end end
context 'on Knative 0.7' do context 'on Knative 0.7.0' do
before do before do
prepare_knative_stubs('0.7.0', namespace: namespace.namespace, name: cluster.project.name) prepare_knative_stubs('0.7.0', namespace: namespace.namespace, name: cluster.project.name)
end end
...@@ -197,39 +181,23 @@ describe Projects::Serverless::FunctionsController do ...@@ -197,39 +181,23 @@ describe Projects::Serverless::FunctionsController do
end end
end end
context 'on Knative 0.5' do context 'on Knative 0.5.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs('0.5.0', namespace: namespace.namespace, name: cluster.project.name)
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 end
include_examples 'GET #index with data' include_examples 'GET #index with data'
end end
context 'on Knative 0.6' do context 'on Knative 0.6.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs('0.6.0', namespace: namespace.namespace, name: cluster.project.name)
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 end
include_examples 'GET #index with data' include_examples 'GET #index with data'
end end
context 'on Knative 0.7' do context 'on Knative 0.7.0' do
before do before do
prepare_knative_stubs('0.7.0', namespace: namespace.namespace, name: cluster.project.name) prepare_knative_stubs('0.7.0', namespace: namespace.namespace, name: cluster.project.name)
end end
...@@ -243,6 +211,10 @@ describe Projects::Serverless::FunctionsController do ...@@ -243,6 +211,10 @@ describe Projects::Serverless::FunctionsController do
case version case version
when '0.7.0' when '0.7.0'
knative_07_service(options) knative_07_service(options)
when '0.6.0'
knative_06_service(options)
when '0.5.0'
knative_05_service(options)
end end
stub_kubeclient_service_pods stub_kubeclient_service_pods
......
...@@ -322,7 +322,7 @@ module KubernetesHelpers ...@@ -322,7 +322,7 @@ module KubernetesHelpers
def kube_knative_services_body(legacy_knative: false, **options) def kube_knative_services_body(legacy_knative: false, **options)
{ {
"kind" => "List", "kind" => "List",
"items" => [legacy_knative ? knative_05_service(options) : kube_service(options)] "items" => [legacy_knative ? knative_05_service(options) : knative_06_service(options)]
} }
end end
...@@ -398,7 +398,8 @@ module KubernetesHelpers ...@@ -398,7 +398,8 @@ module KubernetesHelpers
} }
end end
def kube_service(name: "kubetest", namespace: "default", domain: "example.com") # noinspection RubyStringKeysInHashInspection
def knative_06_service(name: "kubetest", namespace: "default", domain: "example.com")
{ {
"metadata" => { "metadata" => {
"creationTimestamp" => "2018-11-21T06:16:33Z", "creationTimestamp" => "2018-11-21T06:16:33Z",
...@@ -474,6 +475,7 @@ module KubernetesHelpers ...@@ -474,6 +475,7 @@ module KubernetesHelpers
"podcount" => 0 } "podcount" => 0 }
end end
# noinspection RubyStringKeysInHashInspection
def knative_05_service(name: "kubetest", namespace: "default", domain: "example.com") def knative_05_service(name: "kubetest", namespace: "default", domain: "example.com")
{ {
"metadata" => { "metadata" => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment