SetEtcHostsEntry: maintain existing ordering
[ganeti-local] / test / docs_unittest.py
index 87aa26d..6959616 100755 (executable)
@@ -95,9 +95,15 @@ class TestDocs(unittest.TestCase):
     group_name = re.escape("[group_name]")
     job_id = re.escape("[job_id]")
     disk_index = re.escape("[disk_index]")
+    query_res = re.escape("[resource]")
 
     resources = connector.GetHandlers(node_name, instance_name, group_name,
-                                      job_id, disk_index)
+                                      job_id, disk_index, query_res)
+
+    handler_dups = utils.FindDuplicates(resources.values())
+    self.assertFalse(handler_dups,
+                     msg=("Resource handlers used more than once: %r" %
+                          handler_dups))
 
     uri_check_fixup = {
       re.compile(node_name): "node1examplecom",
@@ -105,6 +111,7 @@ class TestDocs(unittest.TestCase):
       re.compile(group_name): "group4440",
       re.compile(job_id): "9409",
       re.compile(disk_index): "123",
+      re.compile(query_res): "lock",
       }
 
     assert compat.all(VALID_URI_RE.match(value)
@@ -123,6 +130,7 @@ class TestDocs(unittest.TestCase):
     prefix_exception = frozenset(["/", "/version", "/2"])
 
     undocumented = []
+    used_uris = []
 
     for key, handler in resources.iteritems():
       # Regex objects
@@ -137,6 +145,7 @@ class TestDocs(unittest.TestCase):
             uri = title[2:-2]
             if key.match(uri):
               self._CheckRapiResource(uri, uri_check_fixup, handler)
+              used_uris.append(uri)
               found = True
               break
 
@@ -150,6 +159,7 @@ class TestDocs(unittest.TestCase):
 
         if ("``%s``" % key) in titles:
           self._CheckRapiResource(key, {}, handler)
+          used_uris.append(key)
         else:
           undocumented.append(key)
 
@@ -157,6 +167,11 @@ class TestDocs(unittest.TestCase):
                 msg=("Missing RAPI resource documentation for %s" %
                      utils.CommaJoin(undocumented)))
 
+    uri_dups = utils.FindDuplicates(used_uris)
+    self.failIf(uri_dups,
+                msg=("URIs matched by more than one resource: %s" %
+                     utils.CommaJoin(uri_dups)))
+
 
 class TestManpages(unittest.TestCase):
   """Manpage tests"""