diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4ee89b91..ed1efbac1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,5 +32,8 @@ jobs: - name: install gems run: bundle install - - name: test + - name: rspec test run: bundle exec rake spec + + - name: mini test + run: bundle exec rake test \ No newline at end of file diff --git a/Rakefile b/Rakefile index b7e9ed549..ee57e3bd5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,15 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" +require "minitest/test_task" RSpec::Core::RakeTask.new(:spec) + +Minitest::TestTask.create(:test) do |t| + t.libs << "test" + t.libs << "lib" + t.warning = false + t.test_globs = ["test/**/*_test.rb"] +end + task :default => :spec diff --git a/ood_core.gemspec b/ood_core.gemspec index 09bc0b477..ed17aa67f 100644 --- a/ood_core.gemspec +++ b/ood_core.gemspec @@ -31,4 +31,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "pry", "~> 0.10" 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 new file mode 100644 index 000000000..e4a6c45d5 --- /dev/null +++ b/test/job/adapters/slurm_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class TestSlurm < Minitest::Test + include TestHelper + + def slurm_instance(config = {}) + OodCore::Job::Factory.build({ adapter: 'slurm' }.merge(config)) + end + + def test_submit_interface + slurm = slurm_instance + + assert(slurm.respond_to?(:submit)) + 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 new file mode 100644 index 000000000..b485f0419 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,49 @@ +require 'ood_core' +require 'mocha/minitest' + +module TestHelper + + # verify the keywords of an objects interface. + # Example: given the interface - def foo(bar: nil) + # veryify_keywords(object, :foo, [:bar]) + # to verify that the method foo takes only one keyword :bar. + def veryify_keywords(object, method, keywords) + parameters = object.method(method.to_sym).parameters + actual_keywords = parameters.select do |key, _value| + key.to_sym == :key + end.map do |_key, value| + value + end.sort + + assert_equal(keywords.sort, actual_keywords) + end + + def verify_args(object, method, num_of_args) + parameters = object.method(method.to_sym).parameters + actual_num_of_args = parameters.select do |key, _value| + key.to_sym == :req || key.to_sym == :opt + end.count + + assert_equal(actual_num_of_args, num_of_args) + end + + 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