summaryrefslogtreecommitdiff
path: root/spec/features/projects/serverless/functions_spec.rb
blob: 9865dbbfb3c3e66cf1539211a5b66aa36f1aad56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

describe 'Functions', :js do
  include KubernetesHelpers
  include ReactiveCachingHelpers

  let(:project) { create(:project) }
  let(:user) { create(:user) }

  before do
    project.add_maintainer(user)
    gitlab_sign_in(user)
  end

  shared_examples "it's missing knative installation" do
    before do
      visit project_serverless_functions_path(project)
    end

    it 'sees an empty state require Knative installation' do
      expect(page).to have_link('Install Knative')
      expect(page).to have_selector('.empty-state')
    end
  end

  context 'when user does not have a cluster and visits the serverless page' do
    it_behaves_like "it's missing knative installation"
  end

  context 'when the user does have a cluster and visits the serverless page' do
    let(:cluster) { create(:cluster, :project, :provided_by_gcp) }

    it_behaves_like "it's missing knative installation"
  end

  context 'when the user has a cluster and knative installed and visits the serverless page' do
    let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
    let(:service) { cluster.platform_kubernetes }
    let(:project) { cluster.project }
    let(:knative_services_finder) { project.clusters.first.knative_services_finder(project) }
    let(:namespace) do
      create(:cluster_kubernetes_namespace,
        cluster: cluster,
        cluster_project: cluster.cluster_project,
        project: cluster.cluster_project.project)
    end

    before do
      allow_any_instance_of(Clusters::Cluster)
        .to receive(:knative_services_finder)
        .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)
      visit project_serverless_functions_path(project)
    end

    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
    end
  end
end