# HG changeset patch
# User Gabriel Mazetto <gabriel@gitlab.com>
# Date 1623708166 -7200
#      Tue Jun 15 00:02:46 2021 +0200
# Node ID 224ffc46af509d7a8fd67319b6a859a28e15cd1b
# Parent  aa0f09214720162a8ee71852e5add9c5ab668e33
Rewrite test expectations to use new `expect_logged_:something`

diff --git a/spec/chef/package/libraries/omnibus_helper_spec.rb b/spec/chef/package/libraries/omnibus_helper_spec.rb
--- a/spec/chef/package/libraries/omnibus_helper_spec.rb
+++ b/spec/chef/package/libraries/omnibus_helper_spec.rb
@@ -151,8 +151,9 @@
     it 'detects deprecated OS correctly' do
       allow_any_instance_of(Ohai::System).to receive(:data).and_return({ "platform" => "raspbian", "platform_version" => "8.0" })
 
-      expect(LoggingHelper).to receive(:deprecation).with(/Your OS, raspbian-8.0, will be deprecated soon/)
       OmnibusHelper.is_deprecated_os?
+
+      expect_logged_deprecation(/Your OS, raspbian-8.0, will be deprecated soon/)
     end
 
     it 'does not detects valid OS as deprecated' do
@@ -178,10 +179,9 @@
       end
 
       it 'detects deprecated config correctly' do
-        expect(LoggingHelper).to receive(:deprecation)
-                                   .with(/Specifying Praefect storage nodes as an array is deprecated/)
+        subject.is_deprecated_praefect_config?
 
-        subject.is_deprecated_praefect_config?
+        expect_logged_deprecation(/Specifying Praefect storage nodes as an array is deprecated/)
       end
     end
 
@@ -260,9 +260,10 @@
 
         it 'attempts to remove the file' do
           expect(FileUtils).to receive(:rm_f).with('/etc/gitlab/initial_root_password')
-          expect(LoggingHelper).to receive(:note).with('Found old initial root password file at /etc/gitlab/initial_root_password and deleted it.')
 
           described_class.cleanup_root_password_file
+
+          expect_logged_note('Found old initial root password file at /etc/gitlab/initial_root_password and deleted it.')
         end
       end
 
@@ -273,9 +274,10 @@
 
         it 'does not attempt to remove the file' do
           expect(FileUtils).not_to receive(:rm_f).with('/etc/gitlab/initial_root_password')
-          expect(LoggingHelper).not_to receive(:note).with('Found old initial root password file at /etc/gitlab/initial_root_password and deleted it.')
 
           described_class.cleanup_root_password_file
+
+          expect_logged_note('Found old initial root password file at /etc/gitlab/initial_root_password and deleted it.')
         end
       end
     end
@@ -320,9 +322,9 @@
             NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
           EOS
 
-          expect(LoggingHelper).to receive(:note).with(msg)
+          described_class.new(converge_config.node).print_root_account_details
 
-          described_class.new(converge_config.node).print_root_account_details
+          expect_logged_note(msg)
         end
       end
 
@@ -346,9 +348,9 @@
             NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
           EOS
 
-          expect(LoggingHelper).to receive(:note).with(msg)
+          described_class.new(converge_config.node).print_root_account_details
 
-          described_class.new(converge_config.node).print_root_account_details
+          expect_logged_note(msg)
         end
       end
 
@@ -366,11 +368,11 @@
 
           it 'writes initial root password to /etc/gitlab/initial_root_password' do
             subject = described_class.new(converge_config.node)
-
             expect(subject).to receive(:write_root_password)
-            expect(LoggingHelper).to receive(:note).with(%r{Password stored to /etc/gitlab/initial_root_password})
 
             subject.print_root_account_details
+
+            expect_logged_note(%r{Password stored to /etc/gitlab/initial_root_password})
           end
         end
 
@@ -386,9 +388,10 @@
               subject = described_class.new(chef_run.node)
 
               expect(subject).to receive(:write_root_password)
-              expect(LoggingHelper).to receive(:note).with(%r{Password stored to /etc/gitlab/initial_root_password})
 
               subject.print_root_account_details
+
+              expect_logged_note(%r{Password stored to /etc/gitlab/initial_root_password})
             end
           end
 
@@ -451,9 +454,9 @@
         allow(ENV).to receive(:[]).and_call_original
         allow(ENV).to receive(:[]).with('LC_ALL').and_return('en_SG ISO-8859-1')
 
-        expect(LoggingHelper).to receive(:warning).with("Environment variable LC_ALL specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
+        described_class.check_locale
 
-        described_class.check_locale
+        expect_logged_warning("Environment variable LC_ALL specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
       end
     end
 
@@ -466,9 +469,9 @@
       it 'raises warning when LC_CTYPE is non-UTF-8' do
         allow(ENV).to receive(:[]).with('LC_CTYPE').and_return('en_SG ISO-8859-1')
 
-        expect(LoggingHelper).to receive(:warning).with("Environment variable LC_CTYPE specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
+        described_class.check_locale
 
-        described_class.check_locale
+        expect_logged_warning("Environment variable LC_CTYPE specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
       end
     end
 
@@ -482,9 +485,9 @@
       it 'raises warning when LC_COLLATE is non-UTF-8' do
         allow(ENV).to receive(:[]).with('LC_COLLATE').and_return('en_SG ISO-8859-1')
 
-        expect(LoggingHelper).to receive(:warning).with("Environment variable LC_COLLATE specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
+        described_class.check_locale
 
-        described_class.check_locale
+        expect_logged_warning("Environment variable LC_COLLATE specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
       end
     end
 
@@ -503,9 +506,9 @@
         it 'raises warning when LANG is non-UTF-8' do
           allow(ENV).to receive(:[]).with('LANG').and_return('en_SG ISO-8859-1')
 
-          expect(LoggingHelper).to receive(:warning).with("Environment variable LANG specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
+          described_class.check_locale
 
-          described_class.check_locale
+          expect_logged_warning("Environment variable LANG specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
         end
       end
 
@@ -518,9 +521,9 @@
         it 'raises warning when LANG is non-UTF-8' do
           allow(ENV).to receive(:[]).with('LANG').and_return('en_SG ISO-8859-1')
 
-          expect(LoggingHelper).to receive(:warning).with("Environment variable LANG specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
+          described_class.check_locale
 
-          described_class.check_locale
+          expect_logged_warning("Environment variable LANG specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
         end
       end
 
@@ -531,9 +534,9 @@
         end
 
         it 'does not raise a warning even if LANG is not UTF-8' do
-          expect(LoggingHelper).not_to receive(:warning).with("Environment variable LANG specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
+          described_class.check_locale
 
-          described_class.check_locale
+          expect_logged_warning("Environment variable LANG specifies a non-UTF-8 locale. GitLab requires UTF-8 encoding to function properly. Please check your locale settings.")
         end
       end
     end
diff --git a/spec/chef/recipes/database_migrations_spec.rb b/spec/chef/recipes/database_migrations_spec.rb
--- a/spec/chef/recipes/database_migrations_spec.rb
+++ b/spec/chef/recipes/database_migrations_spec.rb
@@ -41,9 +41,10 @@
 
         expect(migration_block).to notify('ruby_block[check remote PG version]').to(:run)
         expect(chef_run.ruby_block('check remote PG version').should_skip?(:run)).to be_falsey
-        expect(LoggingHelper).to receive(:warning).with(/Support for PostgreSQL 11 has been removed/)
 
         chef_run.ruby_block('check remote PG version').block.call
+
+        expect_logged_warning(/Support for PostgreSQL 11 has been removed/)
       end
     end
 
diff --git a/spec/chef/recipes/letsencrypt_spec.rb b/spec/chef/recipes/letsencrypt_spec.rb
--- a/spec/chef/recipes/letsencrypt_spec.rb
+++ b/spec/chef/recipes/letsencrypt_spec.rb
@@ -156,8 +156,9 @@
         end
 
         it 'warns that we do not setup automatic renewal' do
-          expect(LoggingHelper).to receive(:warning).with(/does not setup/)
           chef_run.ruby_block('display_le_message').block.call
+
+          expect_logged_warning(/does not setup/)
         end
       end
     end
diff --git a/spec/libraries/deprecations_spec.rb b/spec/libraries/deprecations_spec.rb
--- a/spec/libraries/deprecations_spec.rb
+++ b/spec/libraries/deprecations_spec.rb
@@ -207,16 +207,16 @@
       config = { 'monitoring' => { 'test' => 'test-value' } }
       config['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(config['monitoring'], "config['prometheus']", "config['monitoring']")
 
-      expect(LoggingHelper).to receive(:deprecation).with(/Accessing config\['prometheus'\] is deprecated/)
       expect(config['prometheus']['test']).to eq('test-value')
+      expect_logged_deprecation(/Accessing config\['prometheus'\] is deprecated/)
     end
 
     it 'Logs deprecations for passed variables and proxies to new Proc if provided' do
       config = { 'monitoring' => { 'test' => 'test-value' } }
       config['prometheus'] = Gitlab::Deprecations::NodeAttribute.new(proc { config['monitoring'] }, "config['prometheus']", "config['monitoring']")
 
-      expect(LoggingHelper).to receive(:deprecation).with(/Accessing config\['prometheus'\] is deprecated/)
       expect(config['prometheus']['test']).to eq('test-value')
+      expect_logged_deprecation(/Accessing config\['prometheus'\] is deprecated/)
     end
   end
 end