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
end
end
context 'on Knative 0.5' do
context 'on Knative 0.5.0' 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)
prepare_knative_stubs('0.5.0', namespace: namespace.namespace, name: cluster.project.name)
end
include_examples 'GET #show with valid data'
end
context 'on Knative 0.6' do
context 'on Knative 0.6.0' 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)
prepare_knative_stubs('0.6.0', namespace: namespace.namespace, name: cluster.project.name)
end
include_examples 'GET #show with valid data'
end
context 'on Knative 0.7' do
context 'on Knative 0.7.0' do
before do
prepare_knative_stubs('0.7.0', namespace: namespace.namespace, name: cluster.project.name)
end
......@@ -197,39 +181,23 @@ describe Projects::Serverless::FunctionsController do
end
end
context 'on Knative 0.5' do
context 'on Knative 0.5.0' 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)
prepare_knative_stubs('0.5.0', namespace: namespace.namespace, name: cluster.project.name)
end
include_examples 'GET #index with data'
end
context 'on Knative 0.6' do
context 'on Knative 0.6.0' 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)
prepare_knative_stubs('0.6.0', namespace: namespace.namespace, name: cluster.project.name)
end
include_examples 'GET #index with data'
end
context 'on Knative 0.7' do
context 'on Knative 0.7.0' do
before do
prepare_knative_stubs('0.7.0', namespace: namespace.namespace, name: cluster.project.name)
end
......@@ -243,6 +211,10 @@ describe Projects::Serverless::FunctionsController do
case version
when '0.7.0'
knative_07_service(options)
when '0.6.0'
knative_06_service(options)
when '0.5.0'
knative_05_service(options)
end
stub_kubeclient_service_pods
......
......@@ -322,7 +322,7 @@ module KubernetesHelpers
def kube_knative_services_body(legacy_knative: false, **options)
{
"kind" => "List",
"items" => [legacy_knative ? knative_05_service(options) : kube_service(options)]
"items" => [legacy_knative ? knative_05_service(options) : knative_06_service(options)]
}
end
......@@ -398,7 +398,8 @@ module KubernetesHelpers
}
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" => {
"creationTimestamp" => "2018-11-21T06:16:33Z",
......@@ -474,6 +475,7 @@ module KubernetesHelpers
"podcount" => 0 }
end
# noinspection RubyStringKeysInHashInspection
def knative_05_service(name: "kubetest", namespace: "default", domain: "example.com")
{
"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