From 1045800e908ca7f0c8f94f65dacbd0da03c7d4d7 Mon Sep 17 00:00:00 2001
From: Mikolaj Wawrzyniak <mwawrzyniak@gitlab.com>
Date: Wed, 12 Oct 2022 09:24:53 +0200
Subject: [PATCH] Fix failing aggregate_spec

Spec file assumed that there is at least one aggregated metric
definition present at appointed directory. Due to migration process
there is non, which made spec failed. This commit uses temp directory
to test method implementation until more broad clean up will be delivered
in follow up MR.
---
 .../metrics/aggregates/aggregate_spec.rb      | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb b/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb
index be50685a4f1f..76eec2755dfa 100644
--- a/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb
+++ b/spec/lib/gitlab/usage/metrics/aggregates/aggregate_spec.rb
@@ -235,10 +235,27 @@ def aggregated_metric(name:, time_frame:, source: "redis", events: %w[event1 eve
       end
     end
 
-    it 'allows for YAML aliases in aggregated metrics configs' do
-      expect(YAML).to receive(:safe_load).with(kind_of(String), aliases: true).at_least(:once)
+    context 'legacy aggregated metrics configuration' do
+      let(:temp_dir) { Dir.mktmpdir }
+      let(:temp_file) { Tempfile.new(%w[common .yml], temp_dir) }
+
+      before do
+        stub_const("#{namespace}::AGGREGATED_METRICS_PATH", File.expand_path('*.yml', temp_dir))
+        File.open(temp_file.path, "w+b") do |file|
+          file.write [aggregated_metric(name: "gmau_1", time_frame: '7d')].to_yaml
+        end
+      end
+
+      after do
+        temp_file.unlink
+        FileUtils.remove_entry(temp_dir) if Dir.exist?(temp_dir)
+      end
+
+      it 'allows for YAML aliases in aggregated metrics configs' do
+        expect(YAML).to receive(:safe_load).with(kind_of(String), aliases: true).at_least(:once)
 
-      described_class.new(recorded_at)
+        described_class.new(recorded_at)
+      end
     end
 
     describe '.aggregated_metrics_weekly_data' do
-- 
GitLab