Преглед изворни кода

Add tests for included files

Mike Naberezny пре 10 година
родитељ
комит
3a5c8be1f5
1 измењених фајлова са 71 додато и 0 уклоњено
  1. 71 0
      supervisor/tests/test_options.py

+ 71 - 0
supervisor/tests/test_options.py

@@ -868,6 +868,77 @@ class ServerOptionsTests(unittest.TestCase):
         finally:
             shutil.rmtree(dirname)
 
+    def test_read_config_include_reads_extra_files(self):
+        dirname = tempfile.mkdtemp()
+        conf_d = os.path.join(dirname, "conf.d")
+        os.mkdir(conf_d)
+
+        supervisord_conf = os.path.join(dirname, "supervisord.conf")
+        text = lstrip("""\
+        [supervisord]
+
+        [include]
+        files=%s/conf.d/*.conf %s/conf.d/*.ini
+        """ % (dirname, dirname))
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+
+        conf_file = os.path.join(conf_d, "a.conf")
+        f = open(conf_file, 'w')
+        f.write("[inet_http_server]\nport=8000\n")
+        f.close()
+
+        ini_file = os.path.join(conf_d, "a.ini")
+        f = open(ini_file, 'w')
+        f.write("[unix_http_server]\nfile=/tmp/file\n")
+        f.close()
+
+        instance = self._makeOne()
+        try:
+            instance.read_config(supervisord_conf)
+            options = instance.configroot.supervisord
+            self.assertEqual(len(options.server_configs), 2)
+            msg = 'Included extra file "%s" during parsing' % conf_file
+            self.assertTrue(msg in instance.parse_warnings)
+            msg = 'Included extra file "%s" during parsing' % ini_file
+            self.assertTrue(msg in instance.parse_warnings)
+        finally:
+            shutil.rmtree(dirname)
+
+    def test_read_config_include_extra_file_malformed(self):
+        dirname = tempfile.mkdtemp()
+        conf_d = os.path.join(dirname, "conf.d")
+        os.mkdir(conf_d)
+
+        supervisord_conf = os.path.join(dirname, "supervisord.conf")
+        text = lstrip("""\
+        [supervisord]
+
+        [include]
+        files=%s/conf.d/*.conf
+        """ % dirname)
+        f = open(supervisord_conf, 'w')
+        f.write(text)
+        f.close()
+
+        malformed_file = os.path.join(conf_d, "a.conf")
+        f = open(malformed_file, 'w')
+        f.write("[inet_http_server]\njunk\n")
+        f.close()
+
+        instance = self._makeOne()
+        try:
+            instance.read_config(supervisord_conf)
+            self.fail("nothing raised")
+        except ValueError, exc:
+            self.assertTrue('contains parsing errors:' in exc.args[0])
+            self.assertTrue(malformed_file in exc.args[0])
+            msg = 'Included extra file "%s" during parsing' % malformed_file
+            self.assertTrue(msg in instance.parse_warnings)
+        finally:
+            shutil.rmtree(dirname)
+
     def test_readFile_failed(self):
         from supervisor.options import readFile
         try: