test_generate.py 2.0 KB

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