test_generate.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os.path
  16. import re
  17. import shutil
  18. import tempfile
  19. from synapse.config.homeserver import HomeServerConfig
  20. from tests import unittest
  21. class ConfigGenerationTestCase(unittest.TestCase):
  22. def setUp(self):
  23. self.dir = tempfile.mkdtemp()
  24. self.file = os.path.join(self.dir, "homeserver.yaml")
  25. def tearDown(self):
  26. shutil.rmtree(self.dir)
  27. def test_generate_config_generates_files(self):
  28. HomeServerConfig.load_or_generate_config(
  29. "",
  30. [
  31. "--generate-config",
  32. "-c",
  33. self.file,
  34. "--report-stats=yes",
  35. "-H",
  36. "lemurs.win",
  37. ],
  38. )
  39. self.assertSetEqual(
  40. set(
  41. [
  42. "homeserver.yaml",
  43. "lemurs.win.log.config",
  44. "lemurs.win.signing.key",
  45. "lemurs.win.tls.crt",
  46. "lemurs.win.tls.dh",
  47. "lemurs.win.tls.key",
  48. ]
  49. ),
  50. set(os.listdir(self.dir)),
  51. )
  52. self.assert_log_filename_is(
  53. os.path.join(self.dir, "lemurs.win.log.config"),
  54. os.path.join(os.getcwd(), "homeserver.log"),
  55. )
  56. def assert_log_filename_is(self, log_config_file, expected):
  57. with open(log_config_file) as f:
  58. config = f.read()
  59. # find the 'filename' line
  60. matches = re.findall(r"^\s*filename:\s*(.*)$", config, re.M)
  61. self.assertEqual(1, len(matches))
  62. self.assertEqual(matches[0], expected)