# Path: shpkpr/marathon_lb/resolver.py
# def resolve(marathon_lb_url):
# def _get_alias_records(hostname):
# def _reassemble_urls(url, hosts):
# def _reassemble_url(url, host):


import mock
from shpkpr.marathon_lb import resolver
# third-party imports

# local imports


def _mock_gethostbyname_ex(aliaslist=None, ipaddrlist=None):
    """Returns a mocked socket.gethostbyname_ex function for testing use
    """
    if aliaslist is None:
        aliaslist = []
    if ipaddrlist is None:
        ipaddrlist = ['127.0.0.1']
    return lambda hostname: (hostname, aliaslist, ipaddrlist)


@mock.patch('socket.gethostbyname_ex')
def test_resolve(gethostbyname_ex):
    ipaddrlist = ['127.0.0.1', '127.0.0.2']
    gethostbyname_ex.side_effect = _mock_gethostbyname_ex(ipaddrlist=ipaddrlist)


# Path: shpkpr/marathon_lb/resolver.py
# def resolve(marathon_lb_url):
# def _get_alias_records(hostname):
# def _reassemble_urls(url, hosts):
# def _reassemble_url(url, host):


# Path: tests/marathon_lb/test_resolver.py
import mock
from shpkpr.marathon_lb import resolver

# third-party imports

# local imports


def _mock_gethostbyname_ex(aliaslist=None, ipaddrlist=None):
    """Returns a mocked socket.gethostbyname_ex function for testing use
    """
    if aliaslist is None:
        aliaslist = []
    if ipaddrlist is None:
        ipaddrlist = ['127.0.0.1']
    return lambda hostname: (hostname, aliaslist, ipaddrlist)


@mock.patch('socket.gethostbyname_ex')
def test_resolve(gethostbyname_ex):
    ipaddrlist = ['127.0.0.1', '127.0.0.2']
    gethostbyname_ex.side_effect = _mock_gethostbyname_ex(ipaddrlist=ipaddrlist)


    actual_urls = resolver.resolve('http://foobar.com:1234')