Commit 7022db83 authored by Iustin Pop's avatar Iustin Pop
Browse files

Replace manual arbitrary instances with genArbitrary



There are a few more that could be replaces, once we start using
appropriate (new)types.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarRené Nussbaumer <rn@google.com>
parent 8492daa3
......@@ -41,15 +41,11 @@ import qualified Ganeti.Confd.Utils as Confd.Utils
import qualified Ganeti.Constants as C
import qualified Ganeti.Hash as Hash
instance Arbitrary Confd.ConfdRequestType where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Confd.ConfdRequestType)
instance Arbitrary Confd.ConfdReqField where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Confd.ConfdReqField)
instance Arbitrary Confd.ConfdReqQ where
arbitrary = Confd.ConfdReqQ <$> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary
$(genArbitrary ''Confd.ConfdReqQ)
instance Arbitrary Confd.ConfdQuery where
arbitrary = oneof [ pure Confd.EmptyQuery
......@@ -57,9 +53,7 @@ instance Arbitrary Confd.ConfdQuery where
, Confd.DictQuery <$> arbitrary
]
instance Arbitrary Confd.ConfdRequest where
arbitrary = Confd.ConfdRequest <$> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary
$(genArbitrary ''Confd.ConfdRequest)
-- | Test that signing messages and checking signatures is correct. It
-- also tests, indirectly the serialisation of messages so we don't
......
......@@ -56,17 +56,13 @@ allDiskTemplates = [minBound..maxBound]
-- * Arbitrary instance
instance Arbitrary Types.AllocPolicy where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Types.AllocPolicy)
instance Arbitrary Types.DiskTemplate where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Types.DiskTemplate)
instance Arbitrary Types.FailMode where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Types.FailMode)
instance Arbitrary Types.EvacMode where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Types.EvacMode)
instance Arbitrary a => Arbitrary (Types.OpResult a) where
arbitrary = arbitrary >>= \c ->
......
......@@ -37,11 +37,9 @@ import qualified Ganeti.Jobs as Jobs
-- * Arbitrary instances
instance Arbitrary Jobs.OpStatus where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Jobs.OpStatus)
instance Arbitrary Jobs.JobStatus where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Jobs.JobStatus)
-- * Test cases
......
......@@ -48,11 +48,9 @@ import qualified Ganeti.Luxi as Luxi
-- * Luxi tests
instance Arbitrary Luxi.TagObject where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Luxi.TagObject)
instance Arbitrary Luxi.LuxiReq where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Luxi.LuxiReq)
instance Arbitrary Luxi.LuxiOp where
arbitrary = do
......
......@@ -45,11 +45,9 @@ import Ganeti.JSON
-- * Arbitrary instances
instance Arbitrary Hypervisor where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Hypervisor)
instance Arbitrary PartialNDParams where
arbitrary = PartialNDParams <$> arbitrary <*> arbitrary
$(genArbitrary ''PartialNDParams)
instance Arbitrary Node where
arbitrary = Node <$> getFQDN <*> getFQDN <*> getFQDN
......@@ -58,14 +56,11 @@ instance Arbitrary Node where
<*> arbitrary <*> arbitrary <*> getFQDN <*> arbitrary
<*> (Set.fromList <$> genTags)
instance Arbitrary FileDriver where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''FileDriver)
instance Arbitrary BlockDriver where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''BlockDriver)
instance Arbitrary DiskMode where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''DiskMode)
instance Arbitrary DiskLogicalId where
arbitrary = oneof [ LIDPlain <$> arbitrary <*> arbitrary
......@@ -83,26 +78,19 @@ instance Arbitrary Disk where
arbitrary = Disk <$> arbitrary <*> (pure []) <*> arbitrary
<*> arbitrary <*> arbitrary
instance Arbitrary PartialBeParams where
-- FIXME: we should generate proper values, >=0, etc., but this is
-- hard for partial ones, where all must be wrapped in a 'Maybe'
arbitrary = PartialBeParams <$> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary
-- FIXME: we should generate proper values, >=0, etc., but this is
-- hard for partial ones, where all must be wrapped in a 'Maybe'
$(genArbitrary ''PartialBeParams)
instance Arbitrary DiskTemplate where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''DiskTemplate)
instance Arbitrary AdminState where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''AdminState)
instance Arbitrary NICMode where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''NICMode)
instance Arbitrary PartialNicParams where
arbitrary = PartialNicParams <$> arbitrary <*> arbitrary
$(genArbitrary ''PartialNicParams)
instance Arbitrary PartialNic where
arbitrary = PartialNic <$> arbitrary <*> arbitrary <*> arbitrary
$(genArbitrary ''PartialNic)
instance Arbitrary Instance where
arbitrary =
......
......@@ -46,8 +46,7 @@ import qualified Ganeti.OpCodes as OpCodes
-- * Arbitrary instances
instance Arbitrary OpCodes.ReplaceDisksMode where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''OpCodes.ReplaceDisksMode)
instance Arbitrary OpCodes.DiskIndex where
arbitrary = choose (0, C.maxDisks - 1) >>= OpCodes.mkDiskIndex
......
......@@ -72,8 +72,7 @@ genFilter' n = do
n'' = max n' 2 -- but we don't want empty or 1-element lists,
-- so use this for and/or filter list length
instance Arbitrary Qlang.ItemType where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Qlang.ItemType)
instance Arbitrary Qlang.FilterRegex where
arbitrary = getName >>= Qlang.mkRegex -- a name should be a good regex
......@@ -81,8 +80,7 @@ instance Arbitrary Qlang.FilterRegex where
-- | Tests that serialisation/deserialisation of filters is
-- idempotent.
prop_Serialisation :: Property
prop_Serialisation =
forAll genFilter testSerialisation
prop_Serialisation = forAll genFilter testSerialisation
prop_FilterRegex_instances :: Qlang.FilterRegex -> Property
prop_FilterRegex_instances rex =
......
......@@ -38,8 +38,7 @@ import qualified Ganeti.Ssconf as Ssconf
-- * Ssconf tests
instance Arbitrary Ssconf.SSKey where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Ssconf.SSKey)
prop_filename :: Ssconf.SSKey -> Property
prop_filename key =
......
......@@ -28,10 +28,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Test.Ganeti.TestHTools where
import Test.QuickCheck
import qualified Data.Map as Map
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import qualified Ganeti.Constants as C
......@@ -120,5 +119,4 @@ setInstanceSmallerThanNode node inst =
-- * Arbitrary instances
instance Arbitrary Types.InstanceStatus where
arbitrary = elements [minBound..maxBound]
$(genArbitrary ''Types.InstanceStatus)
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