Welcome to mirror list, hosted at ThFree Co, Russian Federation.

long_running_spec_reporter_spec.rb « tools « spec « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1bf520c53af16a4e89a1ab3b22d24bf3f3e248fc (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
# frozen_string_literal: true

RSpec.describe QA::Tools::LongRunningSpecReporter do
  include QA::Support::Helpers::StubEnv

  subject(:reporter) { described_class.execute }

  let(:gcs_client) { double("Fog::Storage::GoogleJSON", get_object: report) }
  let(:slack_notifier) { double("Slack::Notifier", post: nil) }

  before do
    stub_env("SLACK_WEBHOOK", "slack_url")
    stub_env("QA_KNAPSACK_REPORT_GCS_CREDENTIALS", "gcs_json")

    allow(Fog::Storage::Google).to receive(:new)
      .with(google_project: "gitlab-qa-resources", google_json_key_string: "gcs_json")
      .and_return(gcs_client)
    allow(Slack::Notifier).to receive(:new)
      .with("slack_url", channel: "#quality-reports", username: "Spec Runtime Report")
      .and_return(slack_notifier)
  end

  context "without specs exceeding runtime" do
    let(:report) do
      {
        body: <<~JSON
          {
            "spec.rb": 5,
            "spec_2.rb": 10
          }
        JSON
      }
    end

    it "returns all good message" do
      expect { reporter }.to output("No long running specs detected, all good!\n").to_stdout
    end
  end

  context "with specs exceeding runtime" do
    let(:report) do
      {
        body: <<~JSON
          {
            "spec.rb": 5.0,
            "spec_2.rb": 320.0
          }
        JSON
      }
    end

    let(:spec) { "spec_2.rb: 5.33 minutes" }

    let(:message) do
      <<~MSG
        Following spec files are exceeding 5 minute runtime threshold!
        Current average spec runtime: 5 seconds.
      MSG
    end

    it "notifies on long running specs" do
      expect { reporter }.to output("#{message}\n#{spec}\n").to_stdout
      expect(slack_notifier).to have_received(:post).with(
        icon_emoji: ":time-out:",
        text: "#{message}\n```#{spec}```"
      )
    end
  end
end