25
25
import shutil
26
26
import pathlib
27
27
import re
28
+ import pytest
28
29
from kas import kas
30
+ from kas .kasusererror import ArgsCombinationError
29
31
30
32
31
33
def test_build_dir_is_placed_inside_work_dir_by_default (monkeykas , tmpdir ):
@@ -51,6 +53,36 @@ def test_build_dir_can_be_specified_by_environment_variable(monkeykas, tmpdir):
51
53
assert os .path .exists (os .path .join (build_dir , 'conf' ))
52
54
53
55
56
+ def test_ssh_agent_setup (monkeykas , tmpdir ):
57
+ conf_dir = str (tmpdir / 'test_ssh_agent_setup' )
58
+ shutil .copytree ('tests/test_environment_variables' , conf_dir )
59
+ monkeykas .chdir (conf_dir )
60
+
61
+ SSH_AUTH_SOCK = '/tmp/ssh-KLTafE/agent.64708'
62
+
63
+ with monkeykas .context () as mp :
64
+ envfile = tmpdir / 'env'
65
+ mp .setenv ('SSH_AUTH_SOCK' , SSH_AUTH_SOCK )
66
+ kas .kas (['shell' , '-c' , f'env > { envfile } ' , 'test.yml' ])
67
+ env = _get_env_from_file (envfile )
68
+ assert env ['SSH_AUTH_SOCK' ] == SSH_AUTH_SOCK
69
+
70
+ with monkeykas .context () as mp :
71
+ mp .setenv ('SSH_AUTH_SOCK' , SSH_AUTH_SOCK )
72
+ mp .setenv ('SSH_PRIVATE_KEY' , 'id_rsa' )
73
+ with pytest .raises (ArgsCombinationError ):
74
+ kas .kas (['checkout' , 'test.yml' ])
75
+
76
+
77
+ def _get_env_from_file (filename ):
78
+ env = {}
79
+ with filename .open () as f :
80
+ for line in f .readlines ():
81
+ key , val = line .split ("=" , 1 )
82
+ env [key ] = val .strip ()
83
+ return env
84
+
85
+
54
86
def _test_env_section_export (monkeykas , tmpdir , bb_env_var , bb_repo ):
55
87
conf_dir = pathlib .Path (str (tmpdir / 'test_env_variables' ))
56
88
env_out = conf_dir / 'env_out'
@@ -79,11 +111,7 @@ def _test_env_section_export(monkeykas, tmpdir, bb_env_var, bb_repo):
79
111
kas .kas (['shell' , '-c' , 'bitbake -e > %s' % bb_env_out , 'test_env.yml' ])
80
112
81
113
# Check kas environment
82
- test_env = {}
83
- with env_out .open () as f :
84
- for line in f .readlines ():
85
- key , val = line .split ("=" , 1 )
86
- test_env [key ] = val .strip ()
114
+ test_env = _get_env_from_file (env_out )
87
115
88
116
# Variables with 'None' assigned should not be added to environment
89
117
try :
0 commit comments