summaryrefslogtreecommitdiff
path: root/spec/features/projects/environments_pod_logs_spec.rb
blob: 5019e45593c5fe57019a55d422c8708fa590ff52 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Environment > Pod Logs', :js, :kubeclient do
  include KubernetesHelpers

  let(:pod_names) { %w(kube-pod) }
  let(:pod_name) { pod_names.first }
  let(:project) { create(:project, :repository) }
  let(:environment) { create(:environment, project: project) }
  let(:service) { create(:cluster_platform_kubernetes, :configured) }

  before do
    cluster = create(:cluster, :provided_by_gcp, environment_scope: '*', projects: [project])
    create(:deployment, :success, environment: environment)

    stub_kubeclient_pods(environment.deployment_namespace)
    stub_kubeclient_logs(pod_name, environment.deployment_namespace, container: 'container-0')
    stub_kubeclient_deployments(environment.deployment_namespace)
    stub_kubeclient_ingresses(environment.deployment_namespace)
    stub_kubeclient_nodes_and_nodes_metrics(cluster.platform.api_url)

    sign_in(project.owner)
  end

  it "shows environments in dropdown" do
    create(:environment, project: project)

    visit project_logs_path(environment.project, environment_name: environment.name, pod_name: pod_name)

    wait_for_requests

    page.within('.js-environments-dropdown') do
      toggle = find(".dropdown-toggle:not([disabled])")

      expect(toggle).to have_content(environment.name)

      toggle.click

      dropdown_items = find(".dropdown-menu").all(".dropdown-item")
      expect(dropdown_items.first).to have_content(environment.name)
      expect(dropdown_items.size).to eq(2)
    end
  end

  context 'with logs', :use_clean_rails_memory_store_caching do
    it "shows pod logs", :sidekiq_might_not_need_inline do
      visit project_logs_path(environment.project, environment_name: environment.name, pod_name: pod_name)

      wait_for_requests

      page.within('.qa-pods-dropdown') do
        find(".dropdown-toggle:not([disabled])").click

        dropdown_items = find(".dropdown-menu").all(".dropdown-item:not([disabled])")
        expect(dropdown_items.size).to eq(1)

        dropdown_items.each_with_index do |item, i|
          expect(item.text).to eq(pod_names[i])
        end
      end
      expect(page).to have_content("kube-pod | Log 1")
      expect(page).to have_content("kube-pod | Log 2")
      expect(page).to have_content("kube-pod | Log 3")
    end
  end
end