@@ -391,9 +391,17 @@ def test_ssh_identity_file_configuration():
391391 )
392392
393393 # Test that the instance was created correctly
394- assert instance .ssh_identity == TEST_SSH_KEY
394+ # ssh_identity should be None until first use (lazy loading)
395+ assert instance .ssh_identity is None
395396 assert instance .ssh_identity_file == temp_file_path
396397
398+ # Test that get_ssh_identity() reads the file on first use
399+ identity = instance .get_ssh_identity ()
400+ assert identity == TEST_SSH_KEY
401+
402+ # Test that ssh_identity is now cached
403+ assert instance .ssh_identity == TEST_SSH_KEY
404+
397405 # Test that the client class is correct
398406 assert instance .client () == "jumpstarter_driver_ssh.client.SSHWrapperClient"
399407 finally :
@@ -413,13 +421,17 @@ def test_ssh_identity_validation_error():
413421
414422
415423def test_ssh_identity_file_read_error ():
416- """Test SSH wrapper raises error when ssh_identity_file cannot be read"""
424+ """Test SSH wrapper raises error when ssh_identity_file cannot be read on first use"""
425+ # Instance creation should succeed (lazy loading)
426+ instance = SSHWrapper (
427+ children = {"tcp" : TcpNetwork (host = "127.0.0.1" , port = 22 )},
428+ default_username = "testuser" ,
429+ ssh_identity_file = "/nonexistent/path/to/key"
430+ )
431+
432+ # Error should be raised when get_ssh_identity() is called
417433 with pytest .raises (ConfigurationError , match = "Failed to read ssh_identity_file" ):
418- SSHWrapper (
419- children = {"tcp" : TcpNetwork (host = "127.0.0.1" , port = 22 )},
420- default_username = "testuser" ,
421- ssh_identity_file = "/nonexistent/path/to/key"
422- )
434+ instance .get_ssh_identity ()
423435
424436
425437def test_ssh_command_with_identity_string ():
0 commit comments