On Tue, Jul 09, 2013 at 06:07:08PM +0200, Klaus Aehlig wrote:
> genNodeList is used in testing to generate list of nodes
> that could come up in cluster configurations. Since names
> are used to assign indices to nodes, they have to be unique;
> this is also the case in all real clusters.
> 
> Signed-off-by: Klaus Aehlig <aeh...@google.com>
> ---
>  test/hs/Test/Ganeti/HTools/Node.hs | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/test/hs/Test/Ganeti/HTools/Node.hs 
> b/test/hs/Test/Ganeti/HTools/Node.hs
> index 4b36db4..fd28962 100644
> --- a/test/hs/Test/Ganeti/HTools/Node.hs
> +++ b/test/hs/Test/Ganeti/HTools/Node.hs
> @@ -112,7 +112,9 @@ instance Arbitrary Node.Node where
>  -- 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
> +    where names_nodes = (fmap . map) (\n -> (Node.name n, n)) nodes
> +          nodes = listOf1 ngen `suchThat`
> +                  ((\ns -> ns == nub ns) . map Node.name)

LGTM, but note that for some 'ngen' values, this might become quite
expensive.  You might want to rework this to generate a list of unique
names and overwrite the auto-generated node names with this. See for
a somewhat-related example prop_findByName in HTools/Container.hs (I
think there's a better example somewhere around genUniquesList…).

regards,
iustin

Reply via email to