mirror of
https://github.com/certbot/certbot.git
synced 2026-06-03 22:08:07 -04:00
add test
This commit is contained in:
parent
17c40c6547
commit
dafc3dcc4d
2 changed files with 34 additions and 4 deletions
|
|
@ -69,10 +69,7 @@ class NginxConfigurator(common.Installer):
|
|||
|
||||
@classmethod
|
||||
def add_parser_arguments(cls, add):
|
||||
if os.environ.get("CERTBOT_DOCS") == "1":
|
||||
default_server_root = "%s or %s" % (LINUX_SERVER_ROOT, FREEBSD_DARWIN_SERVER_ROOT)
|
||||
else:
|
||||
default_server_root = constants.CLI_DEFAULTS["server_root"]
|
||||
default_server_root = _determine_default_server_root()
|
||||
add("server-root", default=default_server_root,
|
||||
help="Nginx server root directory.")
|
||||
add("ctl", default=constants.CLI_DEFAULTS["ctl"], help="Path to the "
|
||||
|
|
@ -1133,3 +1130,11 @@ def install_ssl_options_conf(options_ssl, options_ssl_digest):
|
|||
"""Copy Certbot's SSL options file into the system's config dir if required."""
|
||||
return common.install_version_controlled_file(options_ssl, options_ssl_digest,
|
||||
constants.MOD_SSL_CONF_SRC, constants.ALL_SSL_OPTIONS_HASHES)
|
||||
|
||||
def _determine_default_server_root():
|
||||
if os.environ.get("CERTBOT_DOCS") == "1":
|
||||
default_server_root = "%s or %s" % (constants.LINUX_SERVER_ROOT,
|
||||
constants.FREEBSD_DARWIN_SERVER_ROOT)
|
||||
else:
|
||||
default_server_root = constants.CLI_DEFAULTS["server_root"]
|
||||
return default_server_root
|
||||
|
|
|
|||
|
|
@ -949,5 +949,30 @@ class InstallSslOptionsConfTest(util.NginxTest):
|
|||
" with the sha256 hash of self.config.mod_ssl_conf when it is updated.")
|
||||
|
||||
|
||||
class DetermineDefaultServerRootTest(certbot_test_util.ConfigTestCase):
|
||||
"""Tests for certbot_nginx.configurator._determine_default_server_root."""
|
||||
|
||||
def _call(self):
|
||||
from certbot_nginx.configurator import _determine_default_server_root
|
||||
return _determine_default_server_root()
|
||||
|
||||
@mock.patch.dict(os.environ, {"CERTBOT_DOCS": "1"})
|
||||
def test_docs_value(self):
|
||||
self._test(expect_both_values=True)
|
||||
|
||||
@mock.patch.dict(os.environ, {})
|
||||
def test_real_values(self):
|
||||
self._test(expect_both_values=False)
|
||||
|
||||
def _test(self, expect_both_values):
|
||||
server_root = self._call()
|
||||
|
||||
if expect_both_values:
|
||||
self.assertIn("/usr/local/etc/nginx", server_root)
|
||||
self.assertIn("/etc/nginx", server_root)
|
||||
else:
|
||||
self.assertTrue("/etc/nginx" in server_root or "/usr/local/etc/nginx" in server_root)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main() # pragma: no cover
|
||||
|
|
|
|||
Loading…
Reference in a new issue