-}
module Test.Ganeti.HTools.Types
- ( testTypes
+ ( testHTools_Types
, Types.AllocPolicy(..)
, Types.DiskTemplate(..)
, Types.FailMode(..)
import Test.QuickCheck
import Control.Applicative
-import qualified Text.JSON as J
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
-- * 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 ->
-- * 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 =
Types.Ok v' -> v == v'
where r = Types.eitherToResult ei
-testSuite "Types"
+testSuite "HTools/Types"
[ 'prop_AllocPolicy_serialisation
, 'prop_DiskTemplate_serialisation
, 'prop_ISpec_serialisation