summaryrefslogtreecommitdiff
path: root/spec/factories/alert_management/alerts.rb
blob: 01f40a7a465dc0bed59b6196ab6002ab688f5cca (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
# frozen_string_literal: true
require 'ffaker'

FactoryBot.define do
  factory :alert_management_alert, class: 'AlertManagement::Alert' do
    triggered
    project
    title { FFaker::Lorem.sentence }
    started_at { Time.current }

    trait :with_issue do
      issue
    end

    trait :with_fingerprint do
      fingerprint { SecureRandom.hex }
    end

    trait :with_service do
      service { FFaker::Product.product_name }
    end

    trait :with_monitoring_tool do
      monitoring_tool { FFaker::AWS.product_description }
    end

    trait :with_description do
      description { FFaker::Lorem.sentence }
    end

    trait :with_host do
      hosts { [FFaker::Internet.ip_v4_address] }
    end

    trait :with_ended_at do
      ended_at { Time.current }
    end

    trait :without_ended_at do
      ended_at { nil }
    end

    trait :triggered do
      status { AlertManagement::Alert::STATUSES[:triggered] }
      without_ended_at
    end

    trait :acknowledged do
      status { AlertManagement::Alert::STATUSES[:acknowledged] }
      without_ended_at
    end

    trait :resolved do
      status { AlertManagement::Alert::STATUSES[:resolved] }
      with_ended_at
    end

    trait :ignored do
      status { AlertManagement::Alert::STATUSES[:ignored] }
      without_ended_at
    end

    trait :low_severity do
      severity { 'low' }
    end

    trait :prometheus do
      monitoring_tool { Gitlab::AlertManagement::AlertParams::MONITORING_TOOLS[:prometheus] }
    end

    trait :all_fields do
      with_issue
      with_fingerprint
      with_service
      with_monitoring_tool
      with_host
      with_description
      low_severity
    end
  end
end