2018-11-16 09:02:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Prometheus::QueryVariables do
|
2018-11-16 09:02:43 -05:00
|
|
|
describe '.call' do
|
2020-09-30 11:09:46 -04:00
|
|
|
let_it_be_with_refind(:environment) { create(:environment) }
|
2021-06-28 23:07:32 -04:00
|
|
|
|
2019-04-27 10:35:32 -04:00
|
|
|
let(:project) { environment.project }
|
2018-11-16 09:02:43 -05:00
|
|
|
let(:slug) { environment.slug }
|
2020-06-04 02:08:42 -04:00
|
|
|
let(:params) { {} }
|
2018-11-16 09:02:43 -05:00
|
|
|
|
2020-09-30 11:09:46 -04:00
|
|
|
subject { described_class.call(environment, **params) }
|
2018-11-16 09:02:43 -05:00
|
|
|
|
|
|
|
it { is_expected.to include(ci_environment_slug: slug) }
|
2020-03-09 05:07:45 -04:00
|
|
|
it { is_expected.to include(ci_project_name: project.name) }
|
|
|
|
it { is_expected.to include(ci_project_namespace: project.namespace.name) }
|
|
|
|
it { is_expected.to include(ci_project_path: project.full_path) }
|
|
|
|
it { is_expected.to include(ci_environment_name: environment.name) }
|
2018-11-16 09:02:43 -05:00
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to include(environment_filter:
|
2019-12-08 22:07:57 -05:00
|
|
|
%Q[container_name!="POD",environment="#{slug}"])
|
2018-11-16 09:02:43 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'without deployment platform' do
|
|
|
|
it { is_expected.to include(kube_namespace: '') }
|
|
|
|
end
|
|
|
|
|
2018-12-20 04:39:09 -05:00
|
|
|
context 'with deployment platform' do
|
2019-04-27 10:35:32 -04:00
|
|
|
context 'with project cluster' do
|
2019-08-07 00:40:29 -04:00
|
|
|
let(:kube_namespace) { environment.deployment_namespace }
|
2018-11-16 09:02:43 -05:00
|
|
|
|
2019-04-27 10:35:32 -04:00
|
|
|
before do
|
|
|
|
create(:cluster, :project, :provided_by_user, projects: [project])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(kube_namespace: kube_namespace) }
|
2018-11-16 09:02:43 -05:00
|
|
|
end
|
|
|
|
|
2019-04-27 10:35:32 -04:00
|
|
|
context 'with group cluster' do
|
|
|
|
let(:cluster) { create(:cluster, :group, :provided_by_user, groups: [group]) }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project2) { create(:project) }
|
|
|
|
let(:kube_namespace) { k8s_ns.namespace }
|
|
|
|
|
2019-08-07 00:40:29 -04:00
|
|
|
let!(:k8s_ns) { create(:cluster_kubernetes_namespace, cluster: cluster, project: project, environment: environment) }
|
|
|
|
let!(:k8s_ns2) { create(:cluster_kubernetes_namespace, cluster: cluster, project: project2, environment: environment) }
|
2019-04-27 10:35:32 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
group.projects << project
|
|
|
|
group.projects << project2
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(kube_namespace: kube_namespace) }
|
|
|
|
end
|
2018-11-16 09:02:43 -05:00
|
|
|
end
|
2020-06-04 02:08:42 -04:00
|
|
|
|
|
|
|
context '__range' do
|
|
|
|
context 'when start_time and end_time are present' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
start_time: Time.rfc3339('2020-05-29T07:23:05.008Z'),
|
|
|
|
end_time: Time.rfc3339('2020-05-29T15:23:05.008Z')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(__range: "#{8.hours.to_i}s") }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start_time and end_time are not present' do
|
|
|
|
it { is_expected.to include(__range: nil) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when end_time is not present' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
start_time: Time.rfc3339('2020-05-29T07:23:05.008Z')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(__range: nil) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when start_time is not present' do
|
|
|
|
let(:params) do
|
|
|
|
{
|
|
|
|
end_time: Time.rfc3339('2020-05-29T07:23:05.008Z')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(__range: nil) }
|
|
|
|
end
|
|
|
|
end
|
2018-11-16 09:02:43 -05:00
|
|
|
end
|
|
|
|
end
|