From 6ae7228684339001fee0fca3c7814be0903eb095 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Wed, 21 Nov 2012 04:52:06 +0100
Subject: [PATCH] Add unit test for default parameter default values

Fails if the default value of an opcode parameter doesn't verify.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 test/ganeti.opcodes_unittest.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/test/ganeti.opcodes_unittest.py b/test/ganeti.opcodes_unittest.py
index ebfeb0875..a5e36d2ab 100755
--- a/test/ganeti.opcodes_unittest.py
+++ b/test/ganeti.opcodes_unittest.py
@@ -191,8 +191,16 @@ class TestOpcodes(unittest.TestCase):
         self.assertTrue(doc is None or isinstance(doc, basestring))
 
         if callable(aval):
-          self.assertFalse(callable(aval()),
+          default_value = aval()
+          self.assertFalse(callable(default_value),
                            msg="Default value returned by function is callable")
+        else:
+          default_value = aval
+
+        if aval is not ht.NoDefault and test is not ht.NoType:
+          self.assertTrue(test(default_value),
+                          msg=("Default value of '%s.%s' does not verify" %
+                               (cls.OP_ID, attr_name)))
 
       # If any parameter has documentation, all others need to have it as well
       has_doc = [doc is not None for (_, _, _, doc) in cls.OP_PARAMS]
-- 
GitLab