From 10e3c522f751d5963e3f933144a70ce857b306b5 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 6 Feb 2023 16:28:34 +0100 Subject: [PATCH] analytics: stop sending analytics in tests --- Library/Homebrew/test/utils/analytics_spec.rb | 5 ++--- Library/Homebrew/utils/analytics.rb | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index 921142bacd..d6bb7b3c26 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -117,9 +117,8 @@ describe Utils::Analytics do ENV.delete("HOMEBREW_NO_ANALYTICS") ENV["HOMEBREW_ANALYTICS_DEBUG"] = "true" ENV["HOMEBREW_ANALYTICS_ENABLE_INFLUX"] = "true" - expect do - described_class.report_influx(:install, action, true, developer: true, CI: true) - end.to output(/--data-raw install,[a-zA-Z=,]*,action=formula_name\\ --head/).to_stdout + expect(described_class).to receive(:defered_curl).once + described_class.report_influx(:install, action, true, developer: true, CI: true) end end diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index d5897e7a11..eee3afccdd 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -99,8 +99,13 @@ module Utils "--data-raw", "#{category},#{tags} count=1i #{Time.now.to_i}" ] - curl = Utils::Curl.curl_executable url = "https://#{INFLUX_HOST}/api/v2/write?bucket=#{INFLUX_BUCKET}&precision=s" + defered_curl(url, args) + end + + sig { params(url: String, args: T::Array[String]).void } + def defered_curl(url, args) + curl = Utils::Curl.curl_executable if ENV["HOMEBREW_ANALYTICS_DEBUG"] puts "#{curl} #{args.join(" ")} \"#{url}\"" puts Utils.popen_read(curl, *args, url)