From 7022db834d7dff3ae2159f0db2e6a353a76e2ee5 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Fri, 31 Aug 2012 12:42:04 +0200
Subject: [PATCH] Replace manual arbitrary instances with genArbitrary
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
There are a few more that could be replaces, once we start using
appropriate (new)types.
Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
htest/Test/Ganeti/Confd/Utils.hs | 14 +++--------
htest/Test/Ganeti/HTools/Types.hs | 12 +++------
htest/Test/Ganeti/Jobs.hs | 6 ++---
htest/Test/Ganeti/Luxi.hs | 6 ++---
htest/Test/Ganeti/Objects.hs | 38 ++++++++++-------------------
htest/Test/Ganeti/OpCodes.hs | 3 +--
htest/Test/Ganeti/Query/Language.hs | 6 ++---
htest/Test/Ganeti/Ssconf.hs | 3 +--
htest/Test/Ganeti/TestHTools.hs | 6 ++---
9 files changed, 31 insertions(+), 63 deletions(-)
diff --git a/htest/Test/Ganeti/Confd/Utils.hs b/htest/Test/Ganeti/Confd/Utils.hs
index 1629f7560..fea3dd9df 100644
--- a/htest/Test/Ganeti/Confd/Utils.hs
+++ b/htest/Test/Ganeti/Confd/Utils.hs
@@ -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
diff --git a/htest/Test/Ganeti/HTools/Types.hs b/htest/Test/Ganeti/HTools/Types.hs
index 34759c50b..aebcc4ceb 100644
--- a/htest/Test/Ganeti/HTools/Types.hs
+++ b/htest/Test/Ganeti/HTools/Types.hs
@@ -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 ->
diff --git a/htest/Test/Ganeti/Jobs.hs b/htest/Test/Ganeti/Jobs.hs
index b9504f718..b6d954678 100644
--- a/htest/Test/Ganeti/Jobs.hs
+++ b/htest/Test/Ganeti/Jobs.hs
@@ -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
diff --git a/htest/Test/Ganeti/Luxi.hs b/htest/Test/Ganeti/Luxi.hs
index e36889fe7..dea4d5f10 100644
--- a/htest/Test/Ganeti/Luxi.hs
+++ b/htest/Test/Ganeti/Luxi.hs
@@ -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
diff --git a/htest/Test/Ganeti/Objects.hs b/htest/Test/Ganeti/Objects.hs
index 0883e30a4..4d94fdb4f 100644
--- a/htest/Test/Ganeti/Objects.hs
+++ b/htest/Test/Ganeti/Objects.hs
@@ -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 =
diff --git a/htest/Test/Ganeti/OpCodes.hs b/htest/Test/Ganeti/OpCodes.hs
index 39396cb86..93abaf183 100644
--- a/htest/Test/Ganeti/OpCodes.hs
+++ b/htest/Test/Ganeti/OpCodes.hs
@@ -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
diff --git a/htest/Test/Ganeti/Query/Language.hs b/htest/Test/Ganeti/Query/Language.hs
index 15ff94ebb..c38fe5ee0 100644
--- a/htest/Test/Ganeti/Query/Language.hs
+++ b/htest/Test/Ganeti/Query/Language.hs
@@ -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 =
diff --git a/htest/Test/Ganeti/Ssconf.hs b/htest/Test/Ganeti/Ssconf.hs
index 0b8695026..98f66080a 100644
--- a/htest/Test/Ganeti/Ssconf.hs
+++ b/htest/Test/Ganeti/Ssconf.hs
@@ -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 =
diff --git a/htest/Test/Ganeti/TestHTools.hs b/htest/Test/Ganeti/TestHTools.hs
index 07f1cae7e..8dbaceac0 100644
--- a/htest/Test/Ganeti/TestHTools.hs
+++ b/htest/Test/Ganeti/TestHTools.hs
@@ -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)
--
GitLab