diff options
Diffstat (limited to 'spec/lib/generators')
-rw-r--r-- | spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb | 11 |
2 files changed, 16 insertions, 7 deletions
diff --git a/spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb b/spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb index e497551bc3f..4cba9732c22 100644 --- a/spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb +++ b/spec/lib/generators/gitlab/usage_metric_definition/redis_hll_generator_spec.rb @@ -28,8 +28,14 @@ RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator, :silence_stdout weekly_metric_definition_path = Dir.glob(File.join(temp_dir, 'metrics/counts_7d/*i_test_event_weekly.yml')).first monthly_metric_definition_path = Dir.glob(File.join(temp_dir, 'metrics/counts_28d/*i_test_event_monthly.yml')).first - expect(YAML.safe_load(File.read(weekly_metric_definition_path))).to include("key_path" => "redis_hll_counters.test_category.i_test_event_weekly") - expect(YAML.safe_load(File.read(monthly_metric_definition_path))).to include("key_path" => "redis_hll_counters.test_category.i_test_event_monthly") + weekly_metric_definition = YAML.safe_load(File.read(weekly_metric_definition_path)) + monthly_metric_definition = YAML.safe_load(File.read(monthly_metric_definition_path)) + + expect(weekly_metric_definition).to include("key_path" => "redis_hll_counters.test_category.i_test_event_weekly") + expect(monthly_metric_definition).to include("key_path" => "redis_hll_counters.test_category.i_test_event_monthly") + + expect(weekly_metric_definition["instrumentation_class"]).to eq('RedisHLLMetric') + expect(monthly_metric_definition["instrumentation_class"]).to eq('RedisHLLMetric') end context 'with ee option' do @@ -49,9 +55,11 @@ RSpec.describe Gitlab::UsageMetricDefinition::RedisHllGenerator, :silence_stdout expect(weekly_metric_definition).to include("key_path" => "redis_hll_counters.test_category.i_test_event_weekly") expect(weekly_metric_definition["distribution"]).to include('ee') + expect(weekly_metric_definition["instrumentation_class"]).to eq('RedisHLLMetric') expect(monthly_metric_definition).to include("key_path" => "redis_hll_counters.test_category.i_test_event_monthly") expect(monthly_metric_definition["distribution"]).to include('ee') + expect(monthly_metric_definition["instrumentation_class"]).to eq('RedisHLLMetric') end end end diff --git a/spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb b/spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb index b67425ae012..6a30bcd0e2c 100644 --- a/spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb +++ b/spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator, :silence_stdout do let(:key_path) { 'counts_weekly.test_metric' } let(:dir) { '7d' } + let(:class_name) { 'Count' } let(:temp_dir) { Dir.mktmpdir } before do @@ -33,7 +34,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator, :silence_stdout do let(:metric_definition_path) { Dir.glob(File.join(temp_dir, 'metrics/counts_7d/*_test_metric.yml')).first } it 'creates a metric definition file using the template' do - described_class.new([key_path], { 'dir' => dir }).invoke_all + described_class.new([key_path], { 'dir' => dir, 'class_name' => class_name }).invoke_all expect(YAML.safe_load(File.read(metric_definition_path))).to eq(sample_metric) end end @@ -48,14 +49,14 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator, :silence_stdout do end it 'creates a metric definition file using the template' do - described_class.new([key_path], { 'dir' => dir, 'ee': true }).invoke_all + described_class.new([key_path], { 'dir' => dir, 'class_name' => class_name, 'ee': true }).invoke_all expect(YAML.safe_load(File.read(metric_definition_path))).to eq(sample_metric) end end end describe 'Validation' do - let(:options) { [key_path, '--dir', dir] } + let(:options) { [key_path, '--dir', dir, '--class_name', class_name] } subject { described_class.start(options) } @@ -93,7 +94,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator, :silence_stdout do describe 'Name suggestions' do it 'adds name key to metric definition' do expect(::Gitlab::Usage::Metrics::NamesSuggestions::Generator).to receive(:generate).and_return('some name') - described_class.new([key_path], { 'dir' => dir }).invoke_all + described_class.new([key_path], { 'dir' => dir, 'class_name' => class_name }).invoke_all metric_definition_path = Dir.glob(File.join(temp_dir, 'metrics/counts_7d/*_test_metric.yml')).first expect(YAML.safe_load(File.read(metric_definition_path))).to include("name" => "some name") @@ -104,7 +105,7 @@ RSpec.describe Gitlab::UsageMetricDefinitionGenerator, :silence_stdout do let(:key_paths) { ['counts_weekly.test_metric', 'counts_weekly.test1_metric'] } it 'creates multiple files' do - described_class.new(key_paths, { 'dir' => dir }).invoke_all + described_class.new(key_paths, { 'dir' => dir, 'class_name' => class_name }).invoke_all files = Dir.glob(File.join(temp_dir, 'metrics/counts_7d/*_metric.yml')) expect(files.count).to eq(2) |