From eae69eeeeabc7763e1a3fd5fcca63ae168b1a29b Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 20 Feb 2012 13:30:04 +0100
Subject: [PATCH] Add two more unittests for Node add/remove
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

These just test that add/remove are idempotent. This is not perfect,
as we use unsorted lists for some values (instead of sets), so when
using non-empty nodes this would break (but for empty nodes, a
1-element list is sorted, so it's fine).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 htools/Ganeti/HTools/QC.hs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
index 7b3d25369..ed61cbf43 100644
--- a/htools/Ganeti/HTools/QC.hs
+++ b/htools/Ganeti/HTools/QC.hs
@@ -1077,6 +1077,23 @@ prop_Node_computeGroups nodes =
      length (nub onlyuuid) == length onlyuuid &&
      (null nodes || not (null ng))
 
+-- Check idempotence of add/remove operations
+prop_Node_addPri_idempotent =
+  forAll genOnlineNode $ \node ->
+  forAll (genInstanceSmallerThanNode node) $ \inst ->
+  case Node.addPri node inst of
+    Types.OpGood node' -> Node.removePri node' inst ==? node
+    _ -> failTest "Can't add instance"
+
+prop_Node_addSec_idempotent =
+  forAll genOnlineNode $ \node ->
+  forAll (genInstanceSmallerThanNode node) $ \inst ->
+  let pdx = Node.idx node + 1
+      inst' = Instance.setPri inst pdx
+  in case Node.addSec node inst' pdx of
+       Types.OpGood node' -> Node.removeSec node' inst' ==? node
+       _ -> failTest "Can't add instance"
+
 testSuite "Node"
             [ 'prop_Node_setAlias
             , 'prop_Node_setOffline
@@ -1093,6 +1110,8 @@ testSuite "Node"
             , 'prop_Node_tagMaps_reject
             , 'prop_Node_showField
             , 'prop_Node_computeGroups
+            , 'prop_Node_addPri_idempotent
+            , 'prop_Node_addSec_idempotent
             ]
 
 -- ** Cluster tests
-- 
GitLab