fix dumper test cov

This commit is contained in:
Alexander Prinzhorn 2021-07-13 12:51:24 +02:00
parent eef6522a5e
commit 793f5c5681
2 changed files with 32 additions and 6 deletions

View File

@ -30,7 +30,7 @@ def ttcpflow(client_conn=True, server_conn=True, messages=True, err=None):
return f
def twebsocketflow(messages=True, err=None) -> http.HTTPFlow:
def twebsocketflow(messages=True, err=None, close_code=None, close_reason='') -> http.HTTPFlow:
flow = http.HTTPFlow(tclient_conn(), tserver_conn())
flow.request = http.Request(
"example.com",
@ -74,12 +74,18 @@ def twebsocketflow(messages=True, err=None) -> http.HTTPFlow:
websocket.WebSocketMessage(Opcode.TEXT, True, b"hello text", 946681204),
websocket.WebSocketMessage(Opcode.TEXT, False, b"it's me", 946681205),
]
if err is True:
# ABNORMAL_CLOSURE
flow.websocket.close_code = 1006
flow.websocket.close_reason = close_reason
if close_code is not None:
flow.websocket.close_code = close_code
else:
# NORMAL_CLOSURE
flow.websocket.close_code = 1000
if err is True:
# ABNORMAL_CLOSURE
flow.websocket.close_code = 1006
else:
# NORMAL_CLOSURE
flow.websocket.close_code = 1000
flow.reply = controller.DummyReply()
return flow

View File

@ -232,10 +232,30 @@ def test_websocket():
d.websocket_end(f)
assert "WebSocket connection closed by" in sio.getvalue()
sio_err.truncate(0)
f = tflow.twebsocketflow(err=True)
d.websocket_end(f)
assert "Error in WebSocket" in sio_err.getvalue()
assert "(reason:" not in sio_err.getvalue()
sio_err.truncate(0)
f = tflow.twebsocketflow(err=True, close_reason='Some lame excuse')
d.websocket_end(f)
assert "Error in WebSocket" in sio_err.getvalue()
assert "(reason: Some lame excuse)" in sio_err.getvalue()
sio_err.truncate(0)
f = tflow.twebsocketflow(close_code=4000)
d.websocket_end(f)
assert "UNKNOWN_ERROR=4000" in sio_err.getvalue()
assert "(reason:" not in sio_err.getvalue()
sio_err.truncate(0)
f = tflow.twebsocketflow(close_code=4000, close_reason='I swear I had a reason')
d.websocket_end(f)
assert "UNKNOWN_ERROR=4000" in sio_err.getvalue()
assert "(reason: I swear I had a reason)" in sio_err.getvalue()
def test_http2():