Skip to content

Commit

Permalink
Merge branch 'main' of github.com:up9inc/mockintosh into main
Browse files Browse the repository at this point in the history
  • Loading branch information
undera committed Jan 18, 2021
2 parents 26b3ce9 + a78c94a commit a289816
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mockintosh/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
from abc import abstractmethod
from collections import OrderedDict
from os import path
from os import path, environ

import tornado.ioloop
import tornado.web
Expand Down Expand Up @@ -60,6 +60,8 @@ def __init__(self, definition, impl: Impl, debug=False, interceptors=(), address
self.load()

def load(self):
port_override = environ.get('MOCKINTOSH_FORCE_PORT', None)

port_mapping = OrderedDict()
for service in self.definition.data['services']:
port = str(service['port'])
Expand Down Expand Up @@ -89,6 +91,9 @@ def load(self):

for service in services:
if self.services_list:
if port_override is not None:
service['port'] = int(port_override)

if 'name' in service:
if service['name'] not in self.services_list:
continue
Expand Down
13 changes: 13 additions & 0 deletions tests/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ def test_services_list(self):
resp = requests.get(SRV_8001 + '/service2', headers={'Host': SRV_8002_HOST})
assert 404 == resp.status_code

def test_port_override(self):
os.environ['MOCKINTOSH_FORCE_PORT'] = '8002'
config = 'configs/json/hbs/core/multiple_services_on_same_port.json'
self.mock_server_process = run_mock_server(get_config_path(config), 'Mock for Service1')

resp = requests.get(SRV_8002 + '/service1', headers={'Host': SRV_8001_HOST})
assert 200 == resp.status_code
assert resp.headers['Content-Type'] == 'text/html; charset=UTF-8'
assert resp.text == 'service1'

result, _ = tcping('localhost', '8001')
assert not result


class TestInterceptors():

Expand Down

0 comments on commit a289816

Please sign in to comment.