Revision 20bc5360 htest/Test/Ganeti/HTools/Types.hs
b/htest/Test/Ganeti/HTools/Types.hs | ||
---|---|---|
127 | 127 |
|
128 | 128 |
-- * Test cases |
129 | 129 |
|
130 |
prop_Types_AllocPolicy_serialisation :: Types.AllocPolicy -> Property
|
|
131 |
prop_Types_AllocPolicy_serialisation apol =
|
|
130 |
prop_AllocPolicy_serialisation :: Types.AllocPolicy -> Property |
|
131 |
prop_AllocPolicy_serialisation apol = |
|
132 | 132 |
case J.readJSON (J.showJSON apol) of |
133 | 133 |
J.Ok p -> p ==? apol |
134 | 134 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
135 | 135 |
|
136 |
prop_Types_DiskTemplate_serialisation :: Types.DiskTemplate -> Property
|
|
137 |
prop_Types_DiskTemplate_serialisation dt =
|
|
136 |
prop_DiskTemplate_serialisation :: Types.DiskTemplate -> Property |
|
137 |
prop_DiskTemplate_serialisation dt = |
|
138 | 138 |
case J.readJSON (J.showJSON dt) of |
139 | 139 |
J.Ok p -> p ==? dt |
140 | 140 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
141 | 141 |
|
142 |
prop_Types_ISpec_serialisation :: Types.ISpec -> Property
|
|
143 |
prop_Types_ISpec_serialisation ispec =
|
|
142 |
prop_ISpec_serialisation :: Types.ISpec -> Property |
|
143 |
prop_ISpec_serialisation ispec = |
|
144 | 144 |
case J.readJSON (J.showJSON ispec) of |
145 | 145 |
J.Ok p -> p ==? ispec |
146 | 146 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
147 | 147 |
|
148 |
prop_Types_IPolicy_serialisation :: Types.IPolicy -> Property
|
|
149 |
prop_Types_IPolicy_serialisation ipol =
|
|
148 |
prop_IPolicy_serialisation :: Types.IPolicy -> Property |
|
149 |
prop_IPolicy_serialisation ipol = |
|
150 | 150 |
case J.readJSON (J.showJSON ipol) of |
151 | 151 |
J.Ok p -> p ==? ipol |
152 | 152 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
153 | 153 |
|
154 |
prop_Types_EvacMode_serialisation :: Types.EvacMode -> Property
|
|
155 |
prop_Types_EvacMode_serialisation em =
|
|
154 |
prop_EvacMode_serialisation :: Types.EvacMode -> Property |
|
155 |
prop_EvacMode_serialisation em = |
|
156 | 156 |
case J.readJSON (J.showJSON em) of |
157 | 157 |
J.Ok p -> p ==? em |
158 | 158 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
159 | 159 |
|
160 |
prop_Types_opToResult :: Types.OpResult Int -> Bool
|
|
161 |
prop_Types_opToResult op =
|
|
160 |
prop_opToResult :: Types.OpResult Int -> Bool |
|
161 |
prop_opToResult op = |
|
162 | 162 |
case op of |
163 | 163 |
Types.OpFail _ -> Types.isBad r |
164 | 164 |
Types.OpGood v -> case r of |
... | ... | |
166 | 166 |
Types.Ok v' -> v == v' |
167 | 167 |
where r = Types.opToResult op |
168 | 168 |
|
169 |
prop_Types_eitherToResult :: Either String Int -> Bool
|
|
170 |
prop_Types_eitherToResult ei =
|
|
169 |
prop_eitherToResult :: Either String Int -> Bool |
|
170 |
prop_eitherToResult ei = |
|
171 | 171 |
case ei of |
172 | 172 |
Left _ -> Types.isBad r |
173 | 173 |
Right v -> case r of |
... | ... | |
176 | 176 |
where r = Types.eitherToResult ei |
177 | 177 |
|
178 | 178 |
testSuite "Types" |
179 |
[ 'prop_Types_AllocPolicy_serialisation
|
|
180 |
, 'prop_Types_DiskTemplate_serialisation
|
|
181 |
, 'prop_Types_ISpec_serialisation
|
|
182 |
, 'prop_Types_IPolicy_serialisation
|
|
183 |
, 'prop_Types_EvacMode_serialisation
|
|
184 |
, 'prop_Types_opToResult
|
|
185 |
, 'prop_Types_eitherToResult
|
|
179 |
[ 'prop_AllocPolicy_serialisation |
|
180 |
, 'prop_DiskTemplate_serialisation |
|
181 |
, 'prop_ISpec_serialisation |
|
182 |
, 'prop_IPolicy_serialisation |
|
183 |
, 'prop_EvacMode_serialisation |
|
184 |
, 'prop_opToResult |
|
185 |
, 'prop_eitherToResult |
|
186 | 186 |
] |
Also available in: Unified diff