diff options
Diffstat (limited to 'spec/lib/gitlab/metrics/dashboard/url_spec.rb')
-rw-r--r-- | spec/lib/gitlab/metrics/dashboard/url_spec.rb | 103 |
1 files changed, 88 insertions, 15 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/url_spec.rb b/spec/lib/gitlab/metrics/dashboard/url_spec.rb index 205e1000376..830d43169a9 100644 --- a/spec/lib/gitlab/metrics/dashboard/url_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/url_spec.rb @@ -6,11 +6,12 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do include Gitlab::Routing.url_helpers describe '#metrics_regex' do + let(:environment_id) { 1 } let(:url_params) do [ 'foo', 'bar', - 1, + environment_id, { start: '2019-08-02T05:43:09.000Z', dashboard: 'config/prometheus/common_metrics.yml', @@ -33,12 +34,42 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do subject { described_class.metrics_regex } - context 'for metrics route' do + context 'for /-/environments/:environment_id/metrics route' do let(:url) { metrics_namespace_project_environment_url(*url_params) } it_behaves_like 'regex which matches url when expected' end + context 'for /-/metrics?environment=:environment_id route' do + let(:url) { namespace_project_metrics_dashboard_url(*url_params) } + let(:url_params) do + [ + 'namespace1', + 'project1', + { + environment: environment_id, + start: '2019-08-02T05:43:09.000Z', + dashboard: 'config/prometheus/common_metrics.yml', + group: 'awesome group', + anchor: 'title' + } + ] + end + + let(:expected_params) do + { + 'url' => url, + 'namespace' => 'namespace1', + 'project' => 'project1', + 'environment' => "#{environment_id}", + 'query' => "?dashboard=config%2Fprometheus%2Fcommon_metrics.yml&environment=#{environment_id}&group=awesome+group&start=2019-08-02T05%3A43%3A09.000Z", + 'anchor' => '#title' + } + end + + it_behaves_like 'regex which matches url when expected' + end + context 'for metrics_dashboard route' do let(:url) { metrics_dashboard_namespace_project_environment_url(*url_params) } @@ -47,16 +78,19 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do end describe '#clusters_regex' do - let(:url) do - Gitlab::Routing.url_helpers.namespace_project_cluster_url( + let(:url) { Gitlab::Routing.url_helpers.namespace_project_cluster_url(*url_params) } + let(:url_params) do + [ 'foo', 'bar', '1', - group: 'Cluster Health', - title: 'Memory Usage', - y_label: 'Memory 20(GiB)', - anchor: 'title' - ) + { + group: 'Cluster Health', + title: 'Memory Usage', + y_label: 'Memory 20(GiB)', + anchor: 'title' + } + ] end let(:expected_params) do @@ -73,6 +107,27 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do subject { described_class.clusters_regex } it_behaves_like 'regex which matches url when expected' + + context 'for metrics_dashboard route' do + let(:url) do + metrics_dashboard_namespace_project_cluster_url( + *url_params, cluster_type: :project, embedded: true, format: :json + ) + end + + let(:expected_params) do + { + 'url' => url, + 'namespace' => 'foo', + 'project' => 'bar', + 'cluster_id' => '1', + 'query' => '?cluster_type=project&embedded=true', + 'anchor' => nil + } + end + + it_behaves_like 'regex which matches url when expected' + end end describe '#grafana_regex' do @@ -103,15 +158,18 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do end describe '#alert_regex' do - let(:url) do - Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_prometheus_alert_url( + let(:url) { Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_prometheus_alert_url(*url_params) } + let(:url_params) do + [ 'foo', 'bar', '1', - start: '2020-02-10T12:59:49.938Z', - end: '2020-02-10T20:59:49.938Z', - anchor: "anchor" - ) + { + start: '2020-02-10T12:59:49.938Z', + end: '2020-02-10T20:59:49.938Z', + anchor: "anchor" + } + ] end let(:expected_params) do @@ -128,6 +186,21 @@ RSpec.describe Gitlab::Metrics::Dashboard::Url do subject { described_class.alert_regex } it_behaves_like 'regex which matches url when expected' + + it_behaves_like 'regex which matches url when expected' do + let(:url) { Gitlab::Routing.url_helpers.metrics_dashboard_namespace_project_prometheus_alert_url(*url_params, format: :json) } + + let(:expected_params) do + { + 'url' => url, + 'namespace' => 'foo', + 'project' => 'bar', + 'alert' => '1', + 'query' => nil, + 'anchor' => nil + } + end + end end describe '#build_dashboard_url' do |