Skip to content

Commit

Permalink
Make TestRunner#unit_exec private to prevent mis-use
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Sep 14, 2024
1 parent 1218a35 commit a7696a0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
46 changes: 24 additions & 22 deletions src/bosh-dev/lib/bosh/dev/test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ def ruby(parallel: false)
end
end

def unit_cmd(log_file = nil)
"".tap do |cmd|
cmd << 'rspec --tty --backtrace -c -f p spec'
cmd << " > #{log_file} 2>&1" if log_file
end
end

def unit_parallel(build_name, log_file = nil)
cmd = "parallel_test --test-options '--no-fail-fast' --type rspec --runtime-log /tmp/bosh_#{build_name}_parallel_runtime_rspec.log spec"
cmd << " > #{log_file} 2>&1" if log_file
cmd
end

def unit_builds
@unit_builds ||= begin
builds = Dir['*'].select do |f|
File.directory?(f) && File.exist?("#{f}/spec")
end.sort
builds -= %w(bat)
end
end

private

def unit_exec(build, log_file: nil, parallel: false)
lines = []
command = parallel ? unit_parallel(build, log_file) : unit_cmd(log_file)
Expand All @@ -54,27 +78,5 @@ def unit_exec(build, log_file: nil, parallel: false)
{:lines => lines, :error => true}
end
end

def unit_cmd(log_file = nil)
"".tap do |cmd|
cmd << 'rspec --tty --backtrace -c -f p spec'
cmd << " > #{log_file} 2>&1" if log_file
end
end

def unit_parallel(build_name, log_file = nil)
cmd = "parallel_test --test-options '--no-fail-fast' --type rspec --runtime-log /tmp/bosh_#{build_name}_parallel_runtime_rspec.log spec"
cmd << " > #{log_file} 2>&1" if log_file
cmd
end

def unit_builds
@unit_builds ||= begin
builds = Dir['*'].select do |f|
File.directory?(f) && File.exist?("#{f}/spec")
end.sort
builds -= %w(bat)
end
end
end
end
4 changes: 2 additions & 2 deletions src/bosh-dev/spec/unit/bosh/dev/test_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ module Bosh::Dev

it 'changes directory to the build and shells out to #unit_cmd' do
expect(Kernel).to receive(:system).with({ 'BOSH_BUILD_NAME' => build }, "cd #{build} && #{runner.unit_cmd}")
runner.unit_exec(build)
runner.send(:unit_exec, build)
end

it 'signals failure if the command fails' do
allow(Kernel).to receive(:system).and_return(false)

retval = runner.unit_exec(build)
retval = runner.send(:unit_exec, build)
expect(retval[:error]).to equal(true)
end
end
Expand Down

0 comments on commit a7696a0

Please sign in to comment.