From 736ba1606e33c90e1507fe02ff4bf60fb92bcfc6 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 29 Nov 2012 18:23:28 +0100 Subject: [PATCH] Add generator for list of arbitrary nodes This generates a minimum of one node, because legal clusters never have zero nodes. Signed-off-by: Guido Trotter <ultrotter@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- htest/Test/Ganeti/HTools/Node.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/htest/Test/Ganeti/HTools/Node.hs b/htest/Test/Ganeti/HTools/Node.hs index 13934532e..2e1acf516 100644 --- a/htest/Test/Ganeti/HTools/Node.hs +++ b/htest/Test/Ganeti/HTools/Node.hs @@ -32,6 +32,7 @@ module Test.Ganeti.HTools.Node , setInstanceSmallerThanNode , genNode , genOnlineNode + , genNodeList ) where import Test.QuickCheck @@ -46,6 +47,7 @@ import Test.Ganeti.TestHTools import Test.Ganeti.HTools.Instance (genInstanceSmallerThanNode) import Ganeti.BasicTypes +import qualified Ganeti.HTools.Loader as Loader import qualified Ganeti.HTools.Container as Container import qualified Ganeti.HTools.Instance as Instance import qualified Ganeti.HTools.Node as Node @@ -97,6 +99,14 @@ genOnlineNode = instance Arbitrary Node.Node where arbitrary = genNode Nothing Nothing +-- | Node list generator. +-- Given a node generator, create a random length node list. Note that "real" +-- clusters always have at least one node, so we don't generate empty node +-- lists here. +genNodeList :: Gen Node.Node -> Gen Node.List +genNodeList ngen = fmap (snd . Loader.assignIndices) names_nodes + where names_nodes = (fmap . map) (\n -> (Node.name n, n)) $ listOf1 ngen + -- * Test cases prop_setAlias :: Node.Node -> String -> Bool -- GitLab