Skip to content

Commit

Permalink
move native tests earlier in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed Nov 14, 2024
1 parent a7a43ca commit 7dd5f51
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 89 deletions.
10 changes: 9 additions & 1 deletion nuget/script/ci-test
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,13 @@

set -e

pushd ./helpers/lib/NuGetUpdater
dotnet restore
dotnet format --no-restore --exclude ../NuGet.Client --verify-no-changes -v diag
dotnet build --configuration Release
dotnet test --configuration Release --no-restore --no-build --logger "console;verbosity=normal" --blame-hang-timeout 5m ./NuGetUpdater.Cli.Test/NuGetUpdater.Cli.Test.csproj
dotnet test --configuration Release --no-restore --no-build --logger "console;verbosity=normal" --blame-hang-timeout 5m ./NuGetUpdater.Core.Test/NuGetUpdater.Core.Test.csproj
popd

bundle install
bundle exec turbo_tests --verbose
bundle exec rspec spec
7 changes: 7 additions & 0 deletions nuget/spec/dependabot/nuget/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def intercept_native_tools(discovery_content_hash:)
file = Tempfile.new
File.write(file.path, job.to_json)
ENV["DEPENDABOT_JOB_PATH"] = file.path
puts "BRETTFO: wrote temp job file to [#{file.path}]"
puts "BRETTFO: job file is not present" unless File.exist?(file.path)

intercept_native_tools(
discovery_content_hash: {
Expand Down Expand Up @@ -236,11 +238,14 @@ def intercept_native_tools(discovery_content_hash:)
after do
job_path = ENV.fetch("DEPENDABOT_JOB_PATH")
FileUtils.rm_f(job_path)
puts "BRETTFO: deleted temp job file at [#{job_path}]"
end

context "with a dirs.proj" do
it "does not repeatedly update the same project" do
run_update_test do |updater|
puts "BRETTFO: running the test with file from [#{ENV.fetch("DEPENDABOT_JOB_PATH")}]"
puts "BRETTFO: expected file to exist but it doesn't" unless File.exist?(ENV.fetch("DEPENDABOT_JOB_PATH"))
expect(updater.updated_dependency_files.map(&:name)).to contain_exactly("Proj1/Proj1/Proj1.csproj")

expect(updater.send(:testonly_update_tooling_calls)).to eq(
Expand All @@ -267,6 +272,8 @@ def intercept_native_tools(discovery_content_hash:)
it "raises the expected error" do
run_update_test do |updater|
expect do
puts "BRETTFO: running the test with file from [#{ENV.fetch("DEPENDABOT_JOB_PATH")}]"
puts "BRETTFO: expected file to exist but it doesn't" unless File.exist?(ENV.fetch("DEPENDABOT_JOB_PATH"))
updater.updated_dependency_files
end.to raise_error(Dependabot::UpdateNotPossible)
end
Expand Down
88 changes: 0 additions & 88 deletions nuget/spec/dependabot/nuget/native_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,94 +138,6 @@
end
end

describe "#native_csharp_tests" do
subject(:dotnet_test) do
Dependabot::SharedHelpers.run_shell_command(command, allow_unsafe_shell_command: true, cwd: cwd)
end

let(:command) do
[
"dotnet",
"test",
"--configuration",
"Release",
"--tl:off",
"--logger",
"\"console;verbosity=normal\"",
project_path
].join(" ")
end

let(:cwd) do
File.join(dependabot_home, "nuget", "helpers", "lib", "NuGetUpdater")
end

context "when the output is from `dotnet test NuGetUpdater.Core.Test` output" do
let(:project_path) do
File.join(dependabot_home, "nuget", "helpers", "lib", "NuGetUpdater",
"NuGetUpdater.Core.Test", "NuGetUpdater.Core.Test.csproj")
end

it "contains the expected output" do
# In CI when the terminal logger is disabled by default in .NET 9 there is no
# output from the test runner: https://github.com/dotnet/msbuild/issues/10682.
# Instead we have to rely on the cmd invocation failing with a non-zero exit code
# if any tests fail. Locally when the terminal logger is enabled we can check
# there is an absence of any evidence of test failures in the output.
# expect(dotnet_test).to include("Passed!")
expect(dotnet_test).not_to include("Build failed")
end
end

context "when the output is from `dotnet test NuGetUpdater.Cli.Test`" do
let(:project_path) do
File.join(dependabot_home, "nuget", "helpers", "lib", "NuGetUpdater",
"NuGetUpdater.Cli.Test", "NuGetUpdater.Cli.Test.csproj")
end

it "contains the expected output" do
# In CI when the terminal logger is disabled by default in .NET 9 there is no
# output from the test runner: https://github.com/dotnet/msbuild/issues/10682.
# Instead we have to rely on the cmd invocation failing with a non-zero exit code
# if any tests fail. Locally when the terminal logger is enabled we can check
# there is an absence of any evidence of test failures in the output.
# expect(dotnet_test).to include("Passed!")
expect(dotnet_test).not_to include("Build failed")
end
end
end

describe "#native_csharp_format" do
subject(:dotnet_test) do
Dependabot::SharedHelpers.run_shell_command(command)
end

let(:command) do
[
"dotnet",
"format",
lib_path,
"--exclude",
except_path,
"--verify-no-changes",
"-v",
"diag"
].join(" ")
end

context "when output is from `dotnet format NuGetUpdater` output" do
let(:lib_path) do
File.absolute_path(File.join("helpers", "lib", "NuGetUpdater"))
end

let(:except_path) { "helpers/lib/NuGet.Client" }

it "contains the expected output" do
expect(dotnet_test).to include("Format complete")
end
end
end

describe "#ensure_no_errors" do
subject(:error_message) do
described_class.ensure_no_errors(JSON.parse(json))
Expand Down
8 changes: 8 additions & 0 deletions nuget/spec/dependabot/nuget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
require "dependabot/nuget"
require_common_spec "shared_examples_for_autoloading"

time_limit_seconds = 5 * 60 # 5 minutes

RSpec.configure do |config|
config.around(:each) do |example|
Timeout::timeout(time_limit_seconds) { example.run }
end
end

RSpec.describe Dependabot::Nuget do
it_behaves_like "it registers the required classes", "nuget"
end

0 comments on commit 7dd5f51

Please sign in to comment.