Revision 3c002a13

b/htools/Ganeti/HTools/QC.hs
34 34
    , testJobs
35 35
    , testCluster
36 36
    , testLoader
37
    , testTypes
37 38
    ) where
38 39

  
39 40
import Test.QuickCheck
......
265 266
      v <- choose (0, 1)
266 267
      return $ SmallRatio v
267 268

  
269
instance Arbitrary Types.AllocPolicy where
270
  arbitrary = elements [minBound..maxBound]
271

  
272
instance Arbitrary Types.DiskTemplate where
273
  arbitrary = elements [minBound..maxBound]
274

  
268 275
-- * Actual tests
269 276

  
270 277
-- ** Utils tests
......
956 963
  , run prop_Loader_assignIndices
957 964
  , run prop_Loader_mergeData
958 965
  ]
966

  
967
-- ** Types tests
968

  
969
prop_AllocPolicy_serialisation apol =
970
    case Types.apolFromString (Types.apolToString apol) of
971
      Types.Ok p -> printTestCase ("invalid deserialisation " ++ show p) $
972
                    p == apol
973
      Types.Bad s -> printTestCase ("failed to deserialise: " ++ s) False
974

  
975
prop_DiskTemplate_serialisation dt =
976
    case Types.dtFromString (Types.dtToString dt) of
977
      Types.Ok p -> printTestCase ("invalid deserialisation " ++ show p) $
978
                    p == dt
979
      Types.Bad s -> printTestCase ("failed to deserialise: " ++ s) False
980

  
981
testTypes =
982
    [ run prop_AllocPolicy_serialisation
983
    , run prop_DiskTemplate_serialisation
984
    ]
b/htools/Ganeti/HTools/Types.hs
104 104
                       -- last-resort, after the preferred groups
105 105
    | AllocUnallocable -- ^ This group must not be used for new
106 106
                       -- allocations
107
      deriving (Show, Read, Eq, Ord)
107
      deriving (Show, Read, Eq, Ord, Enum, Bounded)
108 108

  
109 109
-- | Convert a string to an alloc policy.
110 110
apolFromString :: (Monad m) => String -> m AllocPolicy
......
185 185
                  | DTPlain
186 186
                  | DTBlock
187 187
                  | DTDrbd8
188
                    deriving (Show, Read, Eq)
188
                    deriving (Show, Read, Eq, Enum, Bounded)
189 189

  
190 190
-- | Converts a DiskTemplate to String
191 191
dtToString :: DiskTemplate -> String
b/htools/test.hs
110 110
  , ("OpCodes", fast, testOpCodes)
111 111
  , ("Jobs", fast, testJobs)
112 112
  , ("Loader", fast, testLoader)
113
  , ("Types", fast, testTypes)
113 114
  , ("Cluster", slow, testCluster)
114 115
  ]
115 116

  

Also available in: Unified diff