debian-mirror-gitlab/spec/lib/gitlab/prometheus/internal_spec.rb

109 lines
2.7 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Prometheus::Internal do
2021-03-08 18:12:59 +05:30
let(:server_address) { 'localhost:9090' }
2019-12-26 22:10:19 +05:30
let(:prometheus_settings) do
{
2021-03-08 18:12:59 +05:30
enabled: true,
server_address: server_address
2019-12-26 22:10:19 +05:30
}
end
before do
stub_config(prometheus: prometheus_settings)
end
describe '.uri' do
shared_examples 'returns valid uri' do |uri_string|
it do
expect(described_class.uri).to eq(uri_string)
expect { Addressable::URI.parse(described_class.uri) }.not_to raise_error
end
end
it_behaves_like 'returns valid uri', 'http://localhost:9090'
context 'with non default prometheus address' do
2021-03-08 18:12:59 +05:30
let(:server_address) { 'https://localhost:9090' }
2019-12-26 22:10:19 +05:30
it_behaves_like 'returns valid uri', 'https://localhost:9090'
context 'with :9090 symbol' do
2021-03-08 18:12:59 +05:30
let(:server_address) { :':9090' }
2019-12-26 22:10:19 +05:30
it_behaves_like 'returns valid uri', 'http://localhost:9090'
end
context 'with 0.0.0.0:9090' do
2021-03-08 18:12:59 +05:30
let(:server_address) { '0.0.0.0:9090' }
2019-12-26 22:10:19 +05:30
it_behaves_like 'returns valid uri', 'http://localhost:9090'
end
end
2021-03-08 18:12:59 +05:30
context 'when server_address is nil' do
let(:server_address) { nil }
2019-12-26 22:10:19 +05:30
it 'does not fail' do
2020-11-24 15:15:51 +05:30
expect(described_class.uri).to be_nil
2019-12-26 22:10:19 +05:30
end
end
context 'when prometheus listen address is blank in gitlab.yml' do
2021-03-08 18:12:59 +05:30
let(:server_address) { '' }
2019-12-26 22:10:19 +05:30
it 'does not configure prometheus' do
2020-11-24 15:15:51 +05:30
expect(described_class.uri).to be_nil
2019-12-26 22:10:19 +05:30
end
end
end
2020-11-24 15:15:51 +05:30
describe '.prometheus_enabled?' do
2019-12-26 22:10:19 +05:30
it 'returns correct value' do
expect(described_class.prometheus_enabled?).to eq(true)
end
context 'when prometheus setting is disabled in gitlab.yml' do
let(:prometheus_settings) do
{
2021-03-08 18:12:59 +05:30
enabled: false,
server_address: server_address
2019-12-26 22:10:19 +05:30
}
end
it 'returns correct value' do
expect(described_class.prometheus_enabled?).to eq(false)
end
end
context 'when prometheus setting is not present in gitlab.yml' do
before do
2023-07-09 08:55:56 +05:30
allow(Gitlab.config).to receive(:prometheus).and_raise(GitlabSettings::MissingSetting)
2019-12-26 22:10:19 +05:30
end
it 'does not fail' do
expect(described_class.prometheus_enabled?).to eq(false)
end
end
end
2021-03-08 18:12:59 +05:30
describe '.server_address' do
2019-12-26 22:10:19 +05:30
it 'returns correct value' do
2021-03-08 18:12:59 +05:30
expect(described_class.server_address).to eq(server_address)
2019-12-26 22:10:19 +05:30
end
context 'when prometheus setting is not present in gitlab.yml' do
before do
2023-07-09 08:55:56 +05:30
allow(Gitlab.config).to receive(:prometheus).and_raise(GitlabSettings::MissingSetting)
2019-12-26 22:10:19 +05:30
end
it 'does not fail' do
2021-03-08 18:12:59 +05:30
expect(described_class.server_address).to be_nil
2019-12-26 22:10:19 +05:30
end
end
end
end