Add generator for list of arbitrary instances
authorGuido Trotter <ultrotter@google.com>
Fri, 30 Nov 2012 08:17:19 +0000 (09:17 +0100)
committerGuido Trotter <ultrotter@google.com>
Mon, 3 Dec 2012 09:18:57 +0000 (10:18 +0100)
This takes an instance generator and produces a possibly empty list of
instances.

Signed-off-by: Guido Trotter <ultrotter@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

htest/Test/Ganeti/HTools/Instance.hs

index 59ef515..2b04672 100644 (file)
@@ -31,6 +31,7 @@ module Test.Ganeti.HTools.Instance
   , genInstanceSmallerThanNode
   , genInstanceMaybeBiggerThanNode
   , genInstanceSmallerThan
+  , genInstanceList
   , Instance.Instance(..)
   ) where
 
@@ -43,6 +44,7 @@ import Test.Ganeti.HTools.Types ()
 import Ganeti.BasicTypes
 import qualified Ganeti.HTools.Instance as Instance
 import qualified Ganeti.HTools.Node as Node
+import qualified Ganeti.HTools.Loader as Loader
 import qualified Ganeti.HTools.Types as Types
 
 -- * Arbitrary instances
@@ -74,6 +76,12 @@ genInstanceMaybeBiggerThanNode node =
                          (Node.availDisk node + Types.unitDsk * 3)
                          (Node.availCpu  node + Types.unitCpu * 4)
 
+-- | Generates an instance list given an instance generator.
+genInstanceList :: Gen Instance.Instance -> Gen Instance.List
+genInstanceList igen = fmap (snd . Loader.assignIndices) names_instances
+    where names_instances =
+            (fmap . map) (\n -> (Instance.name n, n)) $ listOf igen
+
 -- let's generate a random instance
 instance Arbitrary Instance.Instance where
   arbitrary = genInstanceSmallerThan maxMem maxDsk maxCpu