Revision 5ef78537 Ganeti/HTools/QC.hs
b/Ganeti/HTools/QC.hs | ||
---|---|---|
281 | 281 |
cont = foldl (\c x -> Container.add x x c) Container.empty cdata |
282 | 282 |
fn x1 x2 = Container.addTwo x1 x1 x2 x2 |
283 | 283 |
|
284 |
prop_Container_nameOf node = |
|
285 |
let nl = makeSmallCluster node 1 |
|
286 |
fnode = head (Container.elems nl) |
|
287 |
in Container.nameOf nl (Node.idx fnode) == Node.name fnode |
|
288 |
|
|
289 |
-- We test that in a cluster, given a random node, we can find it by |
|
290 |
-- its name and alias, as long as all names and aliases are unique, |
|
291 |
-- and that we fail to find a non-existing name |
|
292 |
prop_Container_findByName node othername = |
|
293 |
forAll (choose (1, 20)) $ \ cnt -> |
|
294 |
forAll (choose (0, cnt - 1)) $ \ fidx -> |
|
295 |
forAll (vector cnt) $ \ names -> |
|
296 |
(length . nub) (map fst names ++ map snd names) == |
|
297 |
length names * 2 && |
|
298 |
not (othername `elem` (map fst names ++ map snd names)) ==> |
|
299 |
let nl = makeSmallCluster node cnt |
|
300 |
nodes = Container.elems nl |
|
301 |
nodes' = map (\((name, alias), nn) -> (Node.idx nn, |
|
302 |
nn { Node.name = name, |
|
303 |
Node.alias = alias })) |
|
304 |
$ zip names nodes |
|
305 |
nl' = Container.fromAssocList nodes' |
|
306 |
target = snd (nodes' !! fidx) |
|
307 |
in Container.findByName nl' (Node.name target) == Just target && |
|
308 |
Container.findByName nl' (Node.alias target) == Just target && |
|
309 |
Container.findByName nl' othername == Nothing |
|
310 |
|
|
284 | 311 |
testContainer = |
285 |
[ run prop_Container_addTwo ] |
|
312 |
[ run prop_Container_addTwo |
|
313 |
, run prop_Container_nameOf |
|
314 |
, run prop_Container_findByName |
|
315 |
] |
|
286 | 316 |
|
287 | 317 |
-- Simple instance tests, we only have setter/getters |
288 | 318 |
|
Also available in: Unified diff