From bdb7dbbbc4f0924efbbbe05619d58e4547785012 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Fri, 30 Nov 2012 09:17:19 +0100 Subject: [PATCH] Add generator for list of arbitrary instances 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 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/htest/Test/Ganeti/HTools/Instance.hs b/htest/Test/Ganeti/HTools/Instance.hs index 59ef515fc..2b046720b 100644 --- a/htest/Test/Ganeti/HTools/Instance.hs +++ b/htest/Test/Ganeti/HTools/Instance.hs @@ -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 -- GitLab