#NEWLINE# @ if_docker_configured #NEWLINE# def test_links( self ) : #NEWLINE# #INDENT# '\n        The links specified in an ``Application`` are passed to the\n        container as environment variables.\n        ' #NEWLINE# expected_variables = frozenset ( { #NEWLINE# #INDENT# 'ALIAS_PORT_80_TCP' : 'tcp://localhost:8080' , #NEWLINE# 'ALIAS_PORT_80_TCP_PROTO' : 'tcp' , #NEWLINE# 'ALIAS_PORT_80_TCP_ADDR' : 'localhost' , #NEWLINE# 'ALIAS_PORT_80_TCP_PORT' : '8080' , #NEWLINE# #UNINDENT# } . items ( ) ) #NEWLINE# volume_service = create_volume_service ( self ) #NEWLINE# docker_dir = FilePath ( __file__ ) . sibling ( 'env-docker' ) #NEWLINE# image = DockerImageBuilder ( test = self , source_dir = docker_dir ) #NEWLINE# d = image . build ( ) #NEWLINE# def image_built( image_name ) : #NEWLINE# #INDENT# application_name = random_name ( self ) #NEWLINE# docker_client = DockerClient ( ) #NEWLINE# self . addCleanup ( docker_client . remove , application_name ) #NEWLINE# deployer = P2PNodeDeployer ( 'localhost' , volume_service , docker_client , make_memory_network ( ) , node_uuid = uuid4 ( ) ) #NEWLINE# link = Link ( alias = 'alias' , local_port = 80 , remote_port = 8080 ) #NEWLINE# dataset = Dataset ( dataset_id = unicode ( uuid4 ( ) ) , metadata = pmap ( { #NEWLINE# #INDENT# 'name' : application_name , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# manifestation = Manifestation ( dataset = dataset , primary = True ) #NEWLINE# desired_state = Deployment ( nodes = frozenset ( [ Node ( uuid = deployer . node_uuid , applications = frozenset ( [ Application ( name = application_name , image = DockerImage . from_string ( image_name ) , links = frozenset ( [ link ] ) , volume = AttachedVolume ( manifestation = manifestation , mountpoint = FilePath ( '/data' ) ) ) ] ) , manifestations = { #NEWLINE# #INDENT# manifestation . dataset_id : manifestation , #NEWLINE# #UNINDENT# } ) ] ) ) #NEWLINE# return change_node_state ( deployer , desired_state ) #NEWLINE# #UNINDENT# d . addCallback ( image_built ) #NEWLINE# d . addCallback ( ( lambda _ : volume_service . enumerate ( ) ) ) #NEWLINE# d . addCallback ( ( lambda volumes : list ( volumes ) [ 0 ] . get_filesystem ( ) . get_path ( ) . child ( b'env' ) ) ) #NEWLINE# def got_result_path( result_path ) : #NEWLINE# #INDENT# d = loop_until ( reactor , result_path . exists ) #NEWLINE# d . addCallback ( ( lambda _ : result_path ) ) #NEWLINE# return d #NEWLINE# #UNINDENT# d . addCallback ( got_result_path ) #NEWLINE# def started( result_path ) : #NEWLINE# #INDENT# contents = result_path . getContent ( ) #NEWLINE# assertContainsAll ( haystack = contents , test_case = self , needles = [ '{}={}\n' . format ( k , v ) for ( k , v ) in expected_variables ] ) #NEWLINE# #UNINDENT# d . addCallback ( started ) #NEWLINE# return d