test_generate.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(["homeserver.yaml", "lemurs.win.log.config", "lemurs.win.signing.key"]),
  41. set(os.listdir(self.dir)),
  42. )
  43. self.assert_log_filename_is(
  44. os.path.join(self.dir, "lemurs.win.log.config"),
  45. os.path.join(os.getcwd(), "homeserver.log"),
  46. )
  47. def assert_log_filename_is(self, log_config_file, expected):
  48. with open(log_config_file) as f:
  49. config = f.read()
  50. # find the 'filename' line
  51. matches = re.findall(r"^\s*filename:\s*(.*)$", config, re.M)
  52. self.assertEqual(1, len(matches))
  53. self.assertEqual(matches[0], expected)