debian-mirror-gitlab/spec/finders/clusters/knative_services_finder_spec.rb

111 lines
2.9 KiB
Ruby
Raw Normal View History

2019-09-04 21:01:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe Clusters::KnativeServicesFinder do
include KubernetesHelpers
include ReactiveCachingHelpers
2020-03-09 13:42:32 +05:30
let(:project) { create(:project, :repository) }
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
2019-10-12 21:52:04 +05:30
let(:service) { environment.deployment_platform }
let(:environment) { create(:environment, project: project) }
let!(:deployment) { create(:deployment, :success, environment: environment, cluster: cluster) }
2019-09-04 21:01:54 +05:30
let(:namespace) do
create(:cluster_kubernetes_namespace,
cluster: cluster,
2019-10-12 21:52:04 +05:30
project: project,
environment: environment)
2019-09-04 21:01:54 +05:30
end
2019-10-12 21:52:04 +05:30
let(:finder) { described_class.new(cluster, environment) }
2019-09-04 21:01:54 +05:30
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-10-12 21:52:04 +05:30
synchronous_reactive_cache(finder)
2019-09-04 21:01:54 +05:30
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-10-12 21:52:04 +05:30
subject { finder.service_pod_details(project.name) }
2019-09-04 21:01:54 +05:30
it_behaves_like 'a cached data'
end
describe '#services' do
2019-10-12 21:52:04 +05:30
subject { finder.services }
2019-09-04 21:01:54 +05:30
it_behaves_like 'a cached data'
end
describe '#knative_detected' do
2019-10-12 21:52:04 +05:30
subject { finder.knative_detected }
2019-12-21 20:55:43 +05:30
2019-09-04 21:01:54 +05:30
before do
2019-10-12 21:52:04 +05:30
synchronous_reactive_cache(finder)
2019-09-04 21:01:54 +05:30
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-10-12 21:52:04 +05:30
.to change { finder.cluster.kubeclient.knative_client.discovered }
2019-09-04 21:01:54 +05:30
.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