Revision 4a826364 htest/Test/Ganeti/OpCodes.hs
b/htest/Test/Ganeti/OpCodes.hs | ||
---|---|---|
337 | 337 |
genNameNE |
338 | 338 |
_ -> fail $ "Undefined arbitrary for opcode " ++ op_id |
339 | 339 |
|
340 |
instance Arbitrary OpCodes.CommonOpParams where |
|
341 |
arbitrary = OpCodes.CommonOpParams <$> arbitrary <*> arbitrary <*> |
|
342 |
arbitrary <*> resize 5 arbitrary <*> genMaybe genName |
|
343 |
|
|
340 | 344 |
-- * Helper functions |
341 | 345 |
|
342 | 346 |
-- | Empty JSObject. |
... | ... | |
403 | 407 |
octets <- vectorOf 3 $ choose (0::Int, 255) |
404 | 408 |
mkNonEmpty . intercalate ":" $ map (printf "%02x") octets |
405 | 409 |
|
410 |
-- | Arbitrary instance for MetaOpCode, defined here due to TH ordering. |
|
411 |
$(genArbitrary ''OpCodes.MetaOpCode) |
|
412 |
|
|
406 | 413 |
-- * Test cases |
407 | 414 |
|
408 | 415 |
-- | Check that opcode serialization is idempotent. |
... | ... | |
441 | 448 |
case_py_compat_types = do |
442 | 449 |
let num_opcodes = length OpCodes.allOpIDs * 100 |
443 | 450 |
sample_opcodes <- sample' (vectorOf num_opcodes |
444 |
(arbitrary::Gen OpCodes.OpCode)) |
|
451 |
(arbitrary::Gen OpCodes.MetaOpCode))
|
|
445 | 452 |
let opcodes = head sample_opcodes |
446 | 453 |
serialized = J.encode opcodes |
447 | 454 |
-- check for non-ASCII fields, usually due to 'arbitrary :: String' |
... | ... | |
460 | 467 |
\encoded = [op.__getstate__() for op in decoded]\n\ |
461 | 468 |
\print serializer.Dump(encoded)" serialized |
462 | 469 |
>>= checkPythonResult |
463 |
let deserialised = J.decode py_stdout::J.Result [OpCodes.OpCode] |
|
470 |
let deserialised = J.decode py_stdout::J.Result [OpCodes.MetaOpCode]
|
|
464 | 471 |
decoded <- case deserialised of |
465 | 472 |
J.Ok ops -> return ops |
466 | 473 |
J.Error msg -> |
... | ... | |
506 | 513 |
py_flds hs_flds |
507 | 514 |
) $ zip py_fields hs_fields |
508 | 515 |
|
516 |
-- | Checks that setOpComment works correctly. |
|
517 |
prop_setOpComment :: OpCodes.MetaOpCode -> String -> Property |
|
518 |
prop_setOpComment op comment = |
|
519 |
let (OpCodes.MetaOpCode common _) = OpCodes.setOpComment comment op |
|
520 |
in OpCodes.opComment common ==? Just comment |
|
521 |
|
|
509 | 522 |
testSuite "OpCodes" |
510 | 523 |
[ 'prop_serialization |
511 | 524 |
, 'case_AllDefined |
512 | 525 |
, 'case_py_compat_types |
513 | 526 |
, 'case_py_compat_fields |
527 |
, 'prop_setOpComment |
|
514 | 528 |
] |
Also available in: Unified diff