2019-04-09 19:45:58 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2019-06-03 14:42:06 +00:00
|
|
|
describe Clusters::KnativeServicesFinder do
|
2019-04-09 19:45:58 +00:00
|
|
|
include KubernetesHelpers
|
|
|
|
include ReactiveCachingHelpers
|
|
|
|
|
2019-12-21 03:07:37 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
|
2019-08-07 04:40:29 +00:00
|
|
|
let(:service) { environment.deployment_platform }
|
|
|
|
let(:environment) { create(:environment, project: project) }
|
|
|
|
let!(:deployment) { create(:deployment, :success, environment: environment, cluster: cluster) }
|
2019-04-09 19:45:58 +00:00
|
|
|
let(:namespace) do
|
|
|
|
create(:cluster_kubernetes_namespace,
|
|
|
|
cluster: cluster,
|
2019-08-07 04:40:29 +00:00
|
|
|
project: project,
|
|
|
|
environment: environment)
|
2019-04-09 19:45:58 +00:00
|
|
|
end
|
|
|
|
|
2019-08-07 04:40:29 +00:00
|
|
|
let(:finder) { described_class.new(cluster, environment) }
|
|
|
|
|
2019-04-09 19:45:58 +00:00
|
|
|
before do
|
|
|
|
stub_kubeclient_knative_services(namespace: namespace.namespace)
|
|
|
|
stub_kubeclient_service_pods(
|
|
|
|
kube_response(
|
|
|
|
kube_knative_pods_body(
|
|
|
|
project.name, namespace.namespace
|
|
|
|
)
|
|
|
|
),
|
|
|
|
namespace: namespace.namespace
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a cached data' do
|
|
|
|
it 'has an unintialized cache' do
|
|
|
|
is_expected.to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when using synchronous reactive cache' do
|
|
|
|
before do
|
2019-08-07 04:40:29 +00:00
|
|
|
synchronous_reactive_cache(finder)
|
2019-04-09 19:45:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are functions for cluster namespace' do
|
|
|
|
it { is_expected.not_to be_blank }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are no functions for cluster namespace' do
|
|
|
|
before do
|
|
|
|
stub_kubeclient_knative_services(
|
|
|
|
namespace: namespace.namespace,
|
|
|
|
response: kube_response({ "kind" => "ServiceList", "items" => [] })
|
|
|
|
)
|
|
|
|
stub_kubeclient_service_pods(
|
|
|
|
kube_response({ "kind" => "PodList", "items" => [] }),
|
|
|
|
namespace: namespace.namespace
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_blank }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#service_pod_details' do
|
2019-08-07 04:40:29 +00:00
|
|
|
subject { finder.service_pod_details(project.name) }
|
2019-04-09 19:45:58 +00:00
|
|
|
|
|
|
|
it_behaves_like 'a cached data'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#services' do
|
2019-08-07 04:40:29 +00:00
|
|
|
subject { finder.services }
|
2019-04-09 19:45:58 +00:00
|
|
|
|
|
|
|
it_behaves_like 'a cached data'
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#knative_detected' do
|
2019-08-07 04:40:29 +00:00
|
|
|
subject { finder.knative_detected }
|
2019-10-18 11:11:44 +00:00
|
|
|
|
2019-04-09 19:45:58 +00:00
|
|
|
before do
|
2019-08-07 04:40:29 +00:00
|
|
|
synchronous_reactive_cache(finder)
|
2019-04-09 19:45:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when knative is installed' do
|
|
|
|
before do
|
|
|
|
stub_kubeclient_discover(service.api_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
it "discovers knative installation" do
|
|
|
|
expect { subject }
|
2019-08-07 04:40:29 +00:00
|
|
|
.to change { finder.cluster.kubeclient.knative_client.discovered }
|
2019-04-09 19:45:58 +00:00
|
|
|
.from(false)
|
|
|
|
.to(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when knative is not installed' do
|
|
|
|
before do
|
|
|
|
stub_kubeclient_discover_knative_not_found(service.api_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsy }
|
|
|
|
it "does not discover knative installation" do
|
|
|
|
expect { subject }.not_to change { cluster.kubeclient.knative_client.discovered }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|