From 08b80b93068c8428b68fb71297702c3b7c8d8a36 Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Sun, 15 Oct 2017 16:50:04 +0900 Subject: [PATCH] Improve coverage of Env tests --- tests/server/test_env.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/server/test_env.py b/tests/server/test_env.py index 1bc8683..323eed3 100644 --- a/tests/server/test_env.py +++ b/tests/server/test_env.py @@ -136,6 +136,7 @@ def test_SSL_PORT(): with pytest.raises(Env.Error): Env() os.environ['SSL_CERTFILE'] = 'certfile' + Env() os.environ.pop('SSL_PORT') assert_integer('SSL_PORT', 'ssl_port', None) @@ -160,6 +161,13 @@ def test_MAX_SEND(): def test_MAX_SUBS(): assert_integer('MAX_SUBS', 'max_subs', 250000) +def test_MAX_SESSIONS(): + too_big = 1000000 + os.environ['MAX_SESSIONS'] = str(too_big) + e = Env() + assert e.max_sessions < too_big + # Cannot test default as it may be lowered by the open file limit cap + def test_MAX_SESSION_SUBS(): assert_integer('MAX_SESSION_SUBS', 'max_session_subs', 50000) @@ -263,15 +271,22 @@ def test_clearnet_identity(): os.environ['SSL_KEYFILE'] = 'keyfile' Env() os.environ['IRC'] = 'OK' - with pytest.raises(Env.Error): + with pytest.raises(Env.Error) as err: Env() + assert 'not a valid REPORT_HOST' in str(err) os.environ.pop('IRC', None) os.environ['PEER_ANNOUNCE'] = 'OK' - with pytest.raises(Env.Error): + with pytest.raises(Env.Error) as err: Env() + os.environ.pop('PEER_ANNOUNCE', None) + assert 'not a valid REPORT_HOST' in str(err) + + os.environ['REPORT_HOST'] = '1.2.3.4' os.environ['REPORT_SSL_PORT'] = os.environ['REPORT_TCP_PORT'] - with pytest.raises(Env.Error): + with pytest.raises(Env.Error) as err: Env() + assert 'both resolve' in str(err) + os.environ['REPORT_SSL_PORT'] = '457' os.environ['REPORT_HOST'] = 'foo.com' e = Env()