diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 00:08:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-17 00:08:00 +0300 |
commit | 69d6d3ca2013e97cfd2d89449669ea7bf475f4e9 (patch) | |
tree | 2cc4227ebfc52b7603691f06b0b8e09e030e8428 /spec/tasks/gitlab | |
parent | 01fdcf49b1553c22ae116fe96cedd7b91d02225c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/tasks/gitlab')
-rw-r--r-- | spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb b/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb new file mode 100644 index 00000000000..72e61f5c524 --- /dev/null +++ b/spec/tasks/gitlab/generate_sample_prometheus_data_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'rake_helper' + +describe 'gitlab:generate_sample_prometheus_data rake task' do + let(:cluster) { create(:cluster, :provided_by_user, :project) } + let(:environment) { create(:environment, project: cluster.project) } + let(:sample_query_file) { File.join(Rails.root, Metrics::SampleMetricsService::DIRECTORY, 'test_query_result.yml') } + let!(:metric) { create(:prometheus_metric, project: cluster.project, identifier: 'test_query_result') } + + around do |example| + example.run + ensure + FileUtils.rm(sample_query_file) + end + + it 'creates the file correctly' do + Rake.application.rake_require 'tasks/gitlab/generate_sample_prometheus_data' + allow(Environment).to receive(:find).and_return(environment) + allow(environment).to receive_message_chain(:prometheus_adapter, :prometheus_client, :query_range) { sample_query_result } + run_rake_task('gitlab:generate_sample_prometheus_data', [environment.id]) + + expect(File.exist?(sample_query_file)).to be true + + query_file_content = YAML.load_file(sample_query_file) + + expect(query_file_content).to eq(sample_query_result) + end +end + +def sample_query_result + file = File.join(Rails.root, 'spec/fixtures/gitlab/sample_metrics', 'sample_metric_query_result.yml') + YAML.load_file(File.expand_path(file, __dir__)) +end |