2019-03-02 22:35:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'Functions', :js do
|
2019-03-02 22:35:43 +05:30
|
|
|
include KubernetesHelpers
|
2019-09-04 21:01:54 +05:30
|
|
|
include ReactiveCachingHelpers
|
2019-03-02 22:35:43 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2019-02-15 15:39:39 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_maintainer(user)
|
|
|
|
gitlab_sign_in(user)
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
shared_examples "it's missing knative installation" do
|
2019-02-15 15:39:39 +05:30
|
|
|
before do
|
2020-03-09 13:42:32 +05:30
|
|
|
functions_finder = Projects::Serverless::FunctionsFinder.new(project)
|
2019-02-15 15:39:39 +05:30
|
|
|
visit project_serverless_functions_path(project)
|
2020-03-09 13:42:32 +05:30
|
|
|
allow(Projects::Serverless::FunctionsFinder)
|
|
|
|
.to receive(:new)
|
|
|
|
.and_return(functions_finder)
|
|
|
|
synchronous_reactive_cache(functions_finder)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'sees an empty state require Knative installation' do
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(page).to have_link('Install Knative')
|
|
|
|
expect(page).to have_selector('.empty-state')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when user does not have a cluster and visits the serverless page' do
|
|
|
|
it_behaves_like "it's missing knative installation"
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context 'when the user does have a cluster and visits the serverless page' do
|
|
|
|
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
it_behaves_like "it's missing knative installation"
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
context 'when the user has a cluster and knative installed and visits the serverless page', :kubeclient do
|
2020-03-09 13:42:32 +05:30
|
|
|
let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
|
2019-03-02 22:35:43 +05:30
|
|
|
let(:service) { cluster.platform_kubernetes }
|
2019-10-12 21:52:04 +05:30
|
|
|
let(:environment) { create(:environment, project: project) }
|
|
|
|
let!(:deployment) { create(:deployment, :success, cluster: cluster, environment: environment) }
|
|
|
|
let(:knative_services_finder) { environment.knative_services_finder }
|
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: cluster.cluster_project.project,
|
|
|
|
environment: environment)
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
before do
|
2019-10-12 21:52:04 +05:30
|
|
|
allow(Clusters::KnativeServicesFinder)
|
|
|
|
.to receive(:new)
|
2019-09-04 21:01:54 +05:30
|
|
|
.and_return(knative_services_finder)
|
|
|
|
synchronous_reactive_cache(knative_services_finder)
|
|
|
|
stub_kubeclient_knative_services(stub_get_services_options)
|
|
|
|
stub_kubeclient_service_pods(nil, namespace: namespace.namespace)
|
2019-02-15 15:39:39 +05:30
|
|
|
visit project_serverless_functions_path(project)
|
|
|
|
end
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
context 'when there are no functions' do
|
|
|
|
let(:stub_get_services_options) do
|
|
|
|
{
|
|
|
|
namespace: namespace.namespace,
|
|
|
|
response: kube_response({ "kind" => "ServiceList", "items" => [] })
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sees an empty listing of serverless functions' do
|
|
|
|
expect(page).to have_selector('.empty-state')
|
|
|
|
expect(page).not_to have_selector('.content-list')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there are functions' do
|
|
|
|
let(:stub_get_services_options) { { namespace: namespace.namespace } }
|
|
|
|
|
|
|
|
it 'does not see an empty listing of serverless functions' do
|
|
|
|
expect(page).not_to have_selector('.empty-state')
|
|
|
|
expect(page).to have_selector('.content-list')
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|