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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# frozen_string_literal: true
RSpec.describe QA::Support::Loglinking do
describe '.failure_metadata' do
context 'return nil string' do
it 'if correlation_id is empty' do
expect(QA::Support::Loglinking.failure_metadata('')).to eq(nil)
end
it 'if correlation_id is nil' do
expect(QA::Support::Loglinking.failure_metadata(nil)).to eq(nil)
end
end
context 'return error string' do
it 'with sentry URL' do
allow(QA::Support::Loglinking).to receive(:sentry_url).and_return('https://sentry.address/?environment=bar')
allow(QA::Support::Loglinking).to receive(:kibana_url).and_return(nil)
expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp)
Correlation Id: foo123
Sentry Url: https://sentry.address/?environment=bar&query=correlation_id%3A%22foo123%22
ERROR
end
it 'with kibana URL' do
allow(QA::Support::Loglinking).to receive(:sentry_url).and_return(nil)
allow(QA::Support::Loglinking).to receive(:kibana_url).and_return('https://kibana.address/')
expect(QA::Support::Loglinking.failure_metadata('foo123')).to eql(<<~ERROR.chomp)
Correlation Id: foo123
Kibana Url: https://kibana.address/app/discover#/?_a=%28query%3A%28language%3Akuery%2Cquery%3A%27json.correlation_id%20%3A%20foo123%27%29%29&_g=%28time%3A%28from%3Anow-24h%2Cto%3Anow%29%29
ERROR
end
end
end
describe '.sentry_url' do
let(:url_hash) do
{
:staging => 'https://sentry.gitlab.net/gitlab/staginggitlabcom/?environment=gstg',
:staging_ref => 'https://sentry.gitlab.net/gitlab/staging-ref/?environment=all',
:pre => 'https://sentry.gitlab.net/gitlab/pregitlabcom/?environment=all',
:production => 'https://sentry.gitlab.net/gitlab/gitlabcom/?environment=gprd',
:foo => nil,
nil => nil
}
end
it 'returns sentry URL if environment found' do
url_hash.each do |environment, url|
allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(environment)
expect(QA::Support::Loglinking.sentry_url).to eq(url)
end
end
end
describe '.kibana_url' do
let(:url_hash) do
{
:staging => 'https://nonprod-log.gitlab.net/',
:staging_ref => nil,
:production => 'https://log.gprd.gitlab.net/',
:foo => nil,
nil => nil
}
end
it 'returns kibana URL if environment found' do
url_hash.each do |environment, url|
allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(environment)
expect(QA::Support::Loglinking.kibana_url).to eq(url)
end
end
end
describe '.logging_environment' do
let(:staging_address) { 'https://staging.gitlab.com' }
let(:staging_ref_address) { 'https://staging-ref.gitlab.com' }
let(:production_address) { 'https://gitlab.com' }
let(:pre_prod_address) { 'https://pre.gitlab.com' }
let(:logging_env_array) do
[
{
address: staging_address,
expected_env: :staging
},
{
address: staging_ref_address,
expected_env: :staging_ref
},
{
address: production_address,
expected_env: :production
},
{
address: pre_prod_address,
expected_env: :pre
},
{
address: 'https://foo.com',
expected_env: nil
}
]
end
it 'returns logging environment if environment found' do
logging_env_array.each do |logging_env_hash|
allow(QA::Runtime::Scenario).to receive(:attributes).and_return({ gitlab_address: logging_env_hash[:address] })
expect(QA::Support::Loglinking.logging_environment).to eq(logging_env_hash[:expected_env])
end
end
end
describe '.logging_environment?' do
context 'returns boolean' do
it 'returns true if logging_environment is not nil' do
allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(:staging)
expect(QA::Support::Loglinking.logging_environment?).to eq(true)
end
it 'returns false if logging_environment is nil' do
allow(QA::Support::Loglinking).to receive(:logging_environment).and_return(nil)
expect(QA::Support::Loglinking.logging_environment?).to eq(false)
end
end
end
end
|