Commit 688f35e6 authored by Michele Tartara's avatar Michele Tartara
Browse files

Add function for generating arbitrary UUID



Add a function for generating arbitrary UUIDs to be used for QuickCheck tests.
Signed-off-by: default avatarMichele Tartara <mtartara@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent bdf51a05
......@@ -42,6 +42,7 @@ module Test.Ganeti.TestCommon
, DNSChar(..)
, genName
, genFQDN
, genUUID
, genMaybe
, genTags
, genFields
......@@ -193,6 +194,24 @@ genFQDN = do
names <- vectorOf ncomps genName
return $ intercalate "." names
-- | Generates a UUID-like string.
--
-- Only to be used for QuickCheck testing. For obtaining actual UUIDs use
-- the newUUID function in Ganeti.Utils
genUUID :: Gen String
genUUID = do
c1 <- vector 6
c2 <- vector 4
c3 <- vector 4
c4 <- vector 4
c5 <- vector 4
c6 <- vector 4
c7 <- vector 6
return $ map dnsGetChar c1 ++ "-" ++ map dnsGetChar c2 ++ "-" ++
map dnsGetChar c3 ++ "-" ++ map dnsGetChar c4 ++ "-" ++
map dnsGetChar c5 ++ "-" ++ map dnsGetChar c6 ++ "-" ++
map dnsGetChar c7
-- | Combinator that generates a 'Maybe' using a sub-combinator.
genMaybe :: Gen a -> Gen (Maybe a)
genMaybe subgen = frequency [ (1, pure Nothing), (3, Just <$> subgen) ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment