@@ -883,3 +883,76 @@ def test_alias_volumes_set(self):
883883 assert v .container_path == '/bar'
884884 assert v .host_path == '/host/bar'
885885 assert v .options == ['z' , 'ro' ]
886+
887+ def test_volumes_with_env_vars_simple (self , monkeypatch ):
888+ '''volume definitions can contain environment variables'''
889+ monkeypatch .setenv ("TEST_VOL_PATH" , "/bar/baz" )
890+ monkeypatch .setenv ("TEST_VOL_PATH2" , "/moo/doo" )
891+ with open ('.scuba.yml' , 'w' ) as f :
892+ f .write (r'''
893+ image: na
894+ volumes:
895+ $TEST_VOL_PATH/foo: ${TEST_VOL_PATH2}/foo
896+ ''' )
897+
898+ config = scuba .config .load_config ('.scuba.yml' )
899+ vols = config .volumes
900+ assert len (vols ) == 1
901+
902+ v = list (vols .values ())[0 ]
903+ assert isinstance (v , scuba .config .ScubaVolume )
904+ assert v .container_path == '/bar/baz/foo'
905+ assert v .host_path == '/moo/doo/foo'
906+ assert v .options == []
907+
908+ def test_volumes_with_env_vars_complex (self , monkeypatch ):
909+ '''complex volume definitions can contain environment variables'''
910+ monkeypatch .setenv ("TEST_HOME" , "/home/testuser" )
911+ monkeypatch .setenv ("TEST_TMP" , "/tmp" )
912+ monkeypatch .setenv ("TEST_MAIL" , "/var/spool/mail/testuser" )
913+
914+ with open ('.scuba.yml' , 'w' ) as f :
915+ f .write (r'''
916+ image: na
917+ volumes:
918+ $TEST_HOME/.config: ${TEST_HOME}/.config
919+ $TEST_TMP/:
920+ hostpath: $TEST_HOME/scuba/myproject/tmp
921+ /var/spool/mail/container:
922+ hostpath: $TEST_MAIL
923+ options: z,ro
924+ ''' )
925+
926+ config = scuba .config .load_config ('.scuba.yml' )
927+ vols = config .volumes
928+ assert len (vols ) == 3
929+
930+ v = vols ['/home/testuser/.config' ]
931+ assert isinstance (v , scuba .config .ScubaVolume )
932+ assert v .container_path == '/home/testuser/.config'
933+ assert v .host_path == '/home/testuser/.config'
934+ assert v .options == []
935+
936+ v = vols ['/tmp/' ]
937+ assert isinstance (v , scuba .config .ScubaVolume )
938+ assert v .container_path == '/tmp/'
939+ assert v .host_path == '/home/testuser/scuba/myproject/tmp'
940+ assert v .options == []
941+
942+ v = vols ['/var/spool/mail/container' ]
943+ assert isinstance (v , scuba .config .ScubaVolume )
944+ assert v .container_path == '/var/spool/mail/container'
945+ assert v .host_path == "/var/spool/mail/testuser"
946+ assert v .options == ['z' , 'ro' ]
947+
948+ def test_volumes_with_invalid_env_vars (self , monkeypatch ):
949+ '''Volume definitions cannot include unset env vars'''
950+ # Ensure that the entry does not exist in the environment
951+ monkeypatch .delenv ("TEST_VAR1" , raising = False )
952+ with open ('.scuba.yml' , 'w' ) as f :
953+ f .write (r'''
954+ image: na
955+ volumes:
956+ $TEST_VAR1/foo: /host/foo
957+ ''' )
958+ self ._invalid_config ('TEST_VAR1' )
0 commit comments