diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-11 15:09:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-11 15:09:26 +0300 |
commit | c9687bdf58e9d4a9c3942f587bd4841f42e3b5de (patch) | |
tree | a60a2e20f152483be6a92bacdf10564bbc96c664 /spec/lib/gitlab/metrics | |
parent | 3f3e4bcc50a3280d03299c2c263eafd9c8e3bd7b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/metrics')
-rw-r--r-- | spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb | 82 |
1 files changed, 17 insertions, 65 deletions
diff --git a/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb b/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb index 5c2ec6dae6b..e41004bb57e 100644 --- a/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/stages/grafana_formatter_spec.rb @@ -11,8 +11,9 @@ describe Gitlab::Metrics::Dashboard::Stages::GrafanaFormatter do describe '#transform!' do let(:grafana_dashboard) { JSON.parse(fixture_file('grafana/simplified_dashboard_response.json'), symbolize_names: true) } let(:datasource) { JSON.parse(fixture_file('grafana/datasource_response.json'), symbolize_names: true) } + let(:expected_dashboard) { JSON.parse(fixture_file('grafana/expected_grafana_embed.json'), symbolize_names: true) } - let(:dashboard) { described_class.new(project, {}, params).transform! } + subject(:dashboard) { described_class.new(project, {}, params).transform! } let(:params) do { @@ -23,83 +24,34 @@ describe Gitlab::Metrics::Dashboard::Stages::GrafanaFormatter do end context 'when the query and resources are configured correctly' do - let(:expected_dashboard) { JSON.parse(fixture_file('grafana/expected_grafana_embed.json'), symbolize_names: true) } - - it 'generates a gitlab-yml formatted dashboard' do - expect(dashboard).to eq(expected_dashboard) - end + it { is_expected.to eq expected_dashboard } end - context 'when the inputs are invalid' do - shared_examples_for 'processing error' do - it 'raises a processing error' do - expect { dashboard } - .to raise_error(Gitlab::Metrics::Dashboard::Stages::InputFormatValidator::DashboardProcessingError) - end - end - - context 'when the datasource is not proxyable' do - before do - params[:datasource][:access] = 'not-proxy' - end - - it_behaves_like 'processing error' + context 'when a panelId is not included in the grafana_url' do + before do + params[:grafana_url].gsub('&panelId=8', '') end - context 'when query param "panelId" is not specified' do - before do - params[:grafana_url].gsub!('panelId=8', '') - end - - it_behaves_like 'processing error' - end - - context 'when query param "from" is not specified' do - before do - params[:grafana_url].gsub!('from=1570397739557', '') - end - - it_behaves_like 'processing error' - end + it { is_expected.to eq expected_dashboard } - context 'when query param "to" is not specified' do + context 'when there is also no valid panel in the dashboard' do before do - params[:grafana_url].gsub!('to=1570484139557', '') + params[:grafana_dashboard][:dashboard][:panels] = [] end - it_behaves_like 'processing error' - end - - context 'when the panel is not a graph' do - before do - params[:grafana_dashboard][:dashboard][:panels][0][:type] = 'singlestat' + it 'raises a processing error' do + expect { dashboard }.to raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError) end - - it_behaves_like 'processing error' end + end - context 'when the panel is not a line graph' do - before do - params[:grafana_dashboard][:dashboard][:panels][0][:lines] = false - end - - it_behaves_like 'processing error' - end - - context 'when the query dashboard includes undefined variables' do - before do - params[:grafana_url].gsub!('&var-instance=localhost:9121', '') - end - - it_behaves_like 'processing error' + context 'when an input is invalid' do + before do + params[:datasource][:access] = 'not-proxy' end - context 'when the expression contains unsupported global variables' do - before do - params[:grafana_dashboard][:dashboard][:panels][0][:targets][0][:expr] = 'sum(important_metric[$__interval_ms])' - end - - it_behaves_like 'processing error' + it 'raises a processing error' do + expect { dashboard }.to raise_error(::Gitlab::Metrics::Dashboard::Errors::DashboardProcessingError) end end end |