Revision a8038349 htest/Test/Ganeti/HTools/Types.hs
b/htest/Test/Ganeti/HTools/Types.hs | ||
---|---|---|
1 |
{-# LANGUAGE TemplateHaskell #-} |
|
1 |
{-# LANGUAGE TemplateHaskell, FlexibleInstances, TypeSynonymInstances #-}
|
|
2 | 2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
3 | 3 |
|
4 | 4 |
{-| Unittests for ganeti-htools. |
... | ... | |
32 | 32 |
, Types.DiskTemplate(..) |
33 | 33 |
, Types.FailMode(..) |
34 | 34 |
, Types.EvacMode(..) |
35 |
, Types.OpResult(..) |
|
36 | 35 |
, Types.ISpec(..) |
37 | 36 |
, Types.IPolicy(..) |
38 | 37 |
, nullIPolicy |
... | ... | |
68 | 67 |
instance Arbitrary a => Arbitrary (Types.OpResult a) where |
69 | 68 |
arbitrary = arbitrary >>= \c -> |
70 | 69 |
if c |
71 |
then Types.OpGood <$> arbitrary
|
|
72 |
else Types.OpFail <$> arbitrary
|
|
70 |
then Ok <$> arbitrary
|
|
71 |
else Bad <$> arbitrary
|
|
73 | 72 |
|
74 | 73 |
instance Arbitrary Types.ISpec where |
75 | 74 |
arbitrary = do |
... | ... | |
138 | 137 |
prop_EvacMode_serialisation :: Types.EvacMode -> Property |
139 | 138 |
prop_EvacMode_serialisation = testSerialisation |
140 | 139 |
|
141 |
prop_opToResult :: Types.OpResult Int -> Bool
|
|
140 |
prop_opToResult :: Types.OpResult Int -> Property
|
|
142 | 141 |
prop_opToResult op = |
143 | 142 |
case op of |
144 |
Types.OpFail _ -> isBad r
|
|
145 |
Types.OpGood v -> case r of
|
|
146 |
Bad _ -> False
|
|
147 |
Ok v' -> v == v'
|
|
143 |
Bad _ -> printTestCase ("expected bad but got " ++ show r) $ isBad r
|
|
144 |
Ok v -> case r of
|
|
145 |
Bad msg -> failTest ("expected Ok but got Bad " ++ msg)
|
|
146 |
Ok v' -> v ==? v'
|
|
148 | 147 |
where r = Types.opToResult op |
149 | 148 |
|
150 | 149 |
prop_eitherToResult :: Either String Int -> Bool |
Also available in: Unified diff