From 2be09b64fe8ff66e88ccabf169c6de44df00b593 Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Mon, 15 Jul 2024 11:46:36 -0400 Subject: [PATCH] refactor another test case --- ood_core.gemspec | 1 + test/job/adapters/slurm_test.rb | 7 +++++++ test/test_helper.rb | 23 ++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ood_core.gemspec b/ood_core.gemspec index 549beb2f..ed17aa67 100644 --- a/ood_core.gemspec +++ b/ood_core.gemspec @@ -32,4 +32,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "timecop", "~> 0.8" spec.add_development_dependency "climate_control", "~> 1.2.0" spec.add_development_dependency "minitest", "~> 5" + spec.add_development_dependency "mocha", "~> 2.4" end diff --git a/test/job/adapters/slurm_test.rb b/test/job/adapters/slurm_test.rb index 1acb99d3..e4a6c45d 100644 --- a/test/job/adapters/slurm_test.rb +++ b/test/job/adapters/slurm_test.rb @@ -14,4 +14,11 @@ def test_submit_interface veryify_keywords(slurm, :submit, [:after, :afterok, :afternotok, :afterany]) verify_args(slurm, :submit, 1) end + + def test_submitting_with_hold + slurm = slurm_instance + stub_submit + OodCore::Job::Adapters::Slurm::Batch.any_instance.expects(:submit_string).with(script_content, args: ["-H", "--export", "NONE"], env: {}) + slurm.submit(build_script(submit_as_hold: true)) + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3123068c..b485f041 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,5 @@ require 'ood_core' +require 'mocha/minitest' module TestHelper @@ -25,4 +26,24 @@ def verify_args(object, method, num_of_args) assert_equal(actual_num_of_args, num_of_args) end -end \ No newline at end of file + + def build_script(opts = {}) + OodCore::Job::Script.new( + **{ + content: script_content + }.merge(opts) + ) + end + + def script_content + "my job script" + end + + def stub_submit(jobid = '123') + Open3.stubs(:capture3).returns([jobid, '', exit_success]) + end + + def exit_success + OpenStruct.new(:success? => true, :exitstatus => 0) + end +end