1
0

test_generate.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. "--generate-config",
  30. "-c", self.file,
  31. "--report-stats=yes",
  32. "-H", "lemurs.win"
  33. ])
  34. self.assertSetEqual(
  35. set([
  36. "homeserver.yaml",
  37. "lemurs.win.log.config",
  38. "lemurs.win.signing.key",
  39. "lemurs.win.tls.crt",
  40. "lemurs.win.tls.dh",
  41. "lemurs.win.tls.key",
  42. ]),
  43. set(os.listdir(self.dir))
  44. )
  45. self.assert_log_filename_is(
  46. os.path.join(self.dir, "lemurs.win.log.config"),
  47. os.path.join(os.getcwd(), "homeserver.log"),
  48. )
  49. def assert_log_filename_is(self, log_config_file, expected):
  50. with open(log_config_file) as f:
  51. config = f.read()
  52. # find the 'filename' line
  53. matches = re.findall("^\s*filename:\s*(.*)$", config, re.M)
  54. self.assertEqual(1, len(matches))
  55. self.assertEqual(matches[0], expected)