1
+ require 'test_helper'
2
+ require 'ood_core/job/adapters/systemd'
3
+ require 'ood_core/job/adapters/systemd/launcher'
4
+
5
+ class SystemdLauncherTest < Minitest ::Test
6
+ include TestHelper
7
+
8
+ def launcher_instance ( config = { } )
9
+ default = { ssh_hosts : [ 'foo' ] , submit_host : 'localhost' }
10
+ OodCore ::Job ::Adapters ::LinuxSystemd ::Launcher . new ( **default . merge ( config ) )
11
+ end
12
+
13
+ def setup
14
+ Etc . stubs ( :getlogin ) . returns ( 'testuser' )
15
+ end
16
+
17
+ def test_instantiation
18
+ launcher = launcher_instance
19
+
20
+ refute_nil ( launcher )
21
+ end
22
+
23
+ def test_ssh_cmd_default
24
+ launcher = launcher_instance
25
+ expected = [ 'ssh' , '-t' , '-p' , '22' , '-o' ,
26
+ 'Batchmode=yes' , '-o' , 'StrictHostKeyChecking=no' , '-o' , 'UserKnownHostsFile=/dev/null' ,
27
+ 'testuser@localhost' , '/bin/bash'
28
+ ]
29
+
30
+ assert_equal ( expected , launcher . send ( :ssh_cmd , 'localhost' , [ '/bin/bash' ] ) )
31
+ end
32
+
33
+ def test_ssh_cmd_with_host_checking
34
+ launcher = launcher_instance ( { strict_host_checking : true } )
35
+ expected = [ 'ssh' , '-t' , '-p' , '22' , '-o' ,
36
+ 'Batchmode=yes' , 'testuser@localhost' , '/bin/bash'
37
+ ]
38
+
39
+ assert_equal ( expected , launcher . send ( :ssh_cmd , 'localhost' , [ '/bin/bash' ] ) )
40
+ end
41
+
42
+ def test_ssh_cmd_with_keyfile
43
+ launcher = launcher_instance ( { ssh_keyfile : "~/.ssh/my_key" } )
44
+ expected = [ 'ssh' , '-t' , '-p' , '22' , '-o' ,
45
+ 'Batchmode=yes' , '-o' , 'StrictHostKeyChecking=no' , '-o' , 'UserKnownHostsFile=/dev/null' ,
46
+ '-i' , '~/.ssh/my_key' , 'testuser@localhost' , '/bin/bash'
47
+ ]
48
+
49
+ assert_equal ( expected , launcher . send ( :ssh_cmd , 'localhost' , [ '/bin/bash' ] ) )
50
+ end
51
+ end
0 commit comments