Skip to content

Commit

Permalink
init and add some tests for the systemd launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Feb 6, 2025
1 parent a742eff commit 35fc331
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/job/adapters/systemd_launcher_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'test_helper'
require 'ood_core/job/adapters/systemd'
require 'ood_core/job/adapters/systemd/launcher'

class SystemdLauncherTest < Minitest::Test
include TestHelper

def launcher_instance(config = {})
default = { ssh_hosts: ['foo'], submit_host: 'localhost' }
OodCore::Job::Adapters::LinuxSystemd::Launcher.new(**default.merge(config))
end

def setup
Etc.stubs(:getlogin).returns('testuser')
end

def test_instantiation
launcher = launcher_instance

refute_nil(launcher)
end

def test_ssh_cmd_default
launcher = launcher_instance
expected = [ 'ssh', '-t', '-p', '22', '-o',
'Batchmode=yes', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null',
'testuser@localhost', '/bin/bash'
]

assert_equal(expected, launcher.send(:ssh_cmd, 'localhost', ['/bin/bash']))
end

def test_ssh_cmd_with_host_checking
launcher = launcher_instance({ strict_host_checking: true })
expected = [ 'ssh', '-t', '-p', '22', '-o',
'Batchmode=yes', 'testuser@localhost', '/bin/bash'
]

assert_equal(expected, launcher.send(:ssh_cmd, 'localhost', ['/bin/bash']))
end

def test_ssh_cmd_with_keyfile
launcher = launcher_instance({ ssh_keyfile: "~/.ssh/my_key" })
expected = [ 'ssh', '-t', '-p', '22', '-o',
'Batchmode=yes', '-o', 'StrictHostKeyChecking=no', '-o', 'UserKnownHostsFile=/dev/null',
'-i', '~/.ssh/my_key', 'testuser@localhost', '/bin/bash'
]

assert_equal(expected, launcher.send(:ssh_cmd, 'localhost', ['/bin/bash']))
end
end

0 comments on commit 35fc331

Please sign in to comment.