Add a small 'passTest' helper
[ganeti-local] / htest / Test / Ganeti / HTools / Types.hs
index 5eeaae2..aebcc4c 100644 (file)
@@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 -}
 
 module Test.Ganeti.HTools.Types
-  ( testTypes
+  ( testHTools_Types
   , Types.AllocPolicy(..)
   , Types.DiskTemplate(..)
   , Types.FailMode(..)
@@ -41,7 +41,6 @@ module Test.Ganeti.HTools.Types
 import Test.QuickCheck
 
 import Control.Applicative
-import qualified Text.JSON as J
 
 import Test.Ganeti.TestHelper
 import Test.Ganeti.TestCommon
@@ -57,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 ->
@@ -128,34 +123,19 @@ instance Arbitrary Types.IPolicy where
 -- * Test cases
 
 prop_AllocPolicy_serialisation :: Types.AllocPolicy -> Property
-prop_AllocPolicy_serialisation apol =
-  case J.readJSON (J.showJSON apol) of
-    J.Ok p -> p ==? apol
-    J.Error s -> failTest $ "Failed to deserialise: " ++ s
+prop_AllocPolicy_serialisation = testSerialisation
 
 prop_DiskTemplate_serialisation :: Types.DiskTemplate -> Property
-prop_DiskTemplate_serialisation dt =
-  case J.readJSON (J.showJSON dt) of
-    J.Ok p -> p ==? dt
-    J.Error s -> failTest $ "Failed to deserialise: " ++ s
+prop_DiskTemplate_serialisation = testSerialisation
 
 prop_ISpec_serialisation :: Types.ISpec -> Property
-prop_ISpec_serialisation ispec =
-  case J.readJSON (J.showJSON ispec) of
-    J.Ok p -> p ==? ispec
-    J.Error s -> failTest $ "Failed to deserialise: " ++ s
+prop_ISpec_serialisation = testSerialisation
 
 prop_IPolicy_serialisation :: Types.IPolicy -> Property
-prop_IPolicy_serialisation ipol =
-  case J.readJSON (J.showJSON ipol) of
-    J.Ok p -> p ==? ipol
-    J.Error s -> failTest $ "Failed to deserialise: " ++ s
+prop_IPolicy_serialisation = testSerialisation
 
 prop_EvacMode_serialisation :: Types.EvacMode -> Property
-prop_EvacMode_serialisation em =
-  case J.readJSON (J.showJSON em) of
-    J.Ok p -> p ==? em
-    J.Error s -> failTest $ "Failed to deserialise: " ++ s
+prop_EvacMode_serialisation = testSerialisation
 
 prop_opToResult :: Types.OpResult Int -> Bool
 prop_opToResult op =
@@ -175,7 +155,7 @@ prop_eitherToResult ei =
                  Types.Ok v' -> v == v'
     where r = Types.eitherToResult ei
 
-testSuite "Types"
+testSuite "HTools/Types"
             [ 'prop_AllocPolicy_serialisation
             , 'prop_DiskTemplate_serialisation
             , 'prop_ISpec_serialisation