U
    n5{iÿ  ã                   @   sˆ   d Z ddlmZmZ ddlmZmZmZmZ	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZ G d	d
„ d
eƒZG dd„ deƒZdS )z1
Tests for L{twisted.protocols.haproxy._parser}.
é    )ÚTypeÚUnion)ÚTCP4ServerEndpointÚTCP6ServerEndpointÚUNIXServerEndpointÚ_parseÚ_WrapperServerEndpointÚserverFromString)ÚMemoryReactor)ÚSynchronousTestCaseé   )ÚunparseEndpoint)ÚHAProxyWrappingFactoryc                   @   st   e Zd ZdZeddœdd„Zddœdd„Zddœd	d
„Zddœdd„Zddœdd„Z	ddœdd„Z
ddœdd„ZdS )ÚUnparseEndpointTestszg
    Tests to ensure that un-parsing an endpoint string round trips through
    escaping properly.
    N)ÚinputÚreturnc                 C   s   |   tt|ƒŽ |¡ dS )aA  
        Check that the input unparses into the output, raising an assertion
        error if it doesn't.

        @param input: an input in endpoint-string-description format.  (To
            ensure determinism, keyword arguments should be in alphabetical
            order.)
        @type input: native L{str}
        N)ÚassertEqualr   ÚparseEndpoint)Úselfr   © r   úN/tmp/pip-unpacked-wheel-mnhg7r0q/twisted/protocols/haproxy/test/test_parser.pyÚcheck   s    
zUnparseEndpointTests.check©r   c                 C   s   |   d¡ dS )z%
        An individual word.
        ÚwordN©r   ©r   r   r   r   Útest_basicUnparse)   s    z&UnparseEndpointTests.test_basicUnparsec                 C   s   |   d¡ dS )z%
        Multiple arguments.
        zone:twoNr   r   r   r   r   Útest_multipleArguments/   s    z+UnparseEndpointTests.test_multipleArgumentsc                 C   s   |   d¡ dS )z$
        Keyword arguments.
        zaleph=one:bet=twoNr   r   r   r   r   Útest_keywords5   s    z"UnparseEndpointTests.test_keywordsc                 C   s   |   d¡ dS )z
        Escaped ":".
        zhello\:colon\:worldNr   r   r   r   r   Útest_colonInArgument;   s    z)UnparseEndpointTests.test_colonInArgumentc                 C   s   |   d¡ dS )z/
        Escaped ":" in keyword value.
        zhello=\:Nr   r   r   r   r   Útest_colonInKeywordValueA   s    z-UnparseEndpointTests.test_colonInKeywordValuec                 C   s   |   d¡ dS )z.
        Escaped ":" in keyword name.
        z\:=helloNr   r   r   r   r   Útest_colonInKeywordNameG   s    z,UnparseEndpointTests.test_colonInKeywordName)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústrr   r   r   r   r   r    r!   r   r   r   r   r      s   r   c                   @   sb   e Zd ZdZeeee ee ee	 f e
dœdd„Zddœdd„Zddœd	d
„Zddœdd„ZdS )ÚHAProxyServerParserTestsz@
    Tests that the parser generates the correct endpoints.
    )ÚdescriptionÚexpectedClassr   c                 C   sJ   t ƒ }t||ƒ}|  |t¡ t|tƒs*t‚|  |j|¡ |  |jt	¡ |S )a%  
        Test the C{haproxy} enpdoint prefix against one sub-endpoint type.

        @param description: A string endpoint description beginning with
            C{haproxy}.
        @type description: native L{str}

        @param expectedClass: the expected sub-endpoint class given the
            description.
        @type expectedClass: L{type}

        @return: the parsed endpoint
        @rtype: L{IStreamServerEndpoint}

        @raise twisted.trial.unittest.Failtest: if the parsed endpoint doesn't
            match expectations.
        )
r
   r	   ZassertIsInstancer   Ú
isinstanceÚAssertionErrorZ_wrappedEndpointZassertIsZ_wrapperFactoryr   )r   r(   r)   ZreactorZendpointr   r   r   Ú	onePrefixS   s    
z"HAProxyServerParserTests.onePrefixNr   c                 C   s   |   dt¡ dS )zG
        Test if the parser generates a wrapped TCP4 endpoint.
        zhaproxy:tcp:8080N)r,   r   r   r   r   r   Ú	test_tcp4u   s    z"HAProxyServerParserTests.test_tcp4c                 C   s   |   dt¡ dS )zG
        Test if the parser generates a wrapped TCP6 endpoint.
        zhaproxy:tcp6:8080N)r,   r   r   r   r   r   Ú	test_tcp6{   s    z"HAProxyServerParserTests.test_tcp6c                 C   s   |   dt¡ dS )zG
        Test if the parser generates a wrapped UNIX endpoint.
        z haproxy:unix:address=/tmp/socketN)r,   r   r   r   r   r   Ú	test_unix�   s    z"HAProxyServerParserTests.test_unix)r"   r#   r$   r%   r&   r   r   r   r   r   r   r,   r-   r.   r/   r   r   r   r   r'   N   s   þÿø"r'   N)r%   Útypingr   r   Ztwisted.internet.endpointsr   r   r   r   r   r   r	   Ztwisted.internet.testingr
   Ztwisted.trial.unittestr   ZTestCaseÚ_parserr   Ú_wrapperr   r   r'   r   r   r   r   Ú<module>   s    7