determine-test-runners: test failure modes (again)

This commit is contained in:
Carlo Cabrera 2023-04-04 02:28:56 +08:00
parent e191dbfb9e
commit 3d03d243a4
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 19 additions and 2 deletions

View File

@ -197,6 +197,9 @@ module Homebrew
dependents: args.dependents?,
)
github_run_id = ENV.fetch("GITHUB_RUN_ID") { raise "GITHUB_RUN_ID is not defined" }
github_run_attempt = ENV.fetch("GITHUB_RUN_ATTEMPT") { raise "GITHUB_RUN_ATTEMPT is not defined" }
MacOSVersions::SYMBOLS.each_value do |version|
macos_version = MacOS::Version.new(version)
next if macos_version.outdated_release? || macos_version.prerelease?
@ -211,7 +214,7 @@ module Homebrew
next # No formulae to test on this macOS version.
end
ephemeral_suffix = "-#{ENV.fetch("GITHUB_RUN_ID")}-#{ENV.fetch("GITHUB_RUN_ATTEMPT")}"
ephemeral_suffix = "-#{github_run_id}-#{github_run_attempt}"
runners << { runner: "#{macos_version}#{ephemeral_suffix}", cleanup: false } if add_intel_runners
next unless add_m1_runners

View File

@ -24,7 +24,7 @@ describe "brew determine-test-runners" do
"HOMEBREW_LINUX_CLEANUP" => "false",
"GITHUB_RUN_ID" => ephemeral_suffix.split("-").second,
"GITHUB_RUN_ATTEMPT" => ephemeral_suffix.split("-").third,
}
}.freeze
end
it_behaves_like "parseable arguments"
@ -35,6 +35,20 @@ describe "brew determine-test-runners" do
.and be_a_failure
end
it "fails when the necessary environment variables are missing", :integration_test, :needs_linux do
setup_test_formula "testball"
runner_env.each_key do |k|
runner_env_dup = runner_env.dup
runner_env_dup[k] = nil
expect { brew "determine-test-runners", "testball", runner_env_dup }
.to not_to_output.to_stdout
.and output("Error: #{k} is not defined\n").to_stderr
.and be_a_failure
end
end
it "assigns all runners for formulae without any requirements", :integration_test, :needs_linux do
setup_test_formula "testball"