Revision 7af7da68 test/hs/Test/Ganeti/Objects.hs
b/test/hs/Test/Ganeti/Objects.hs | ||
---|---|---|
492 | 492 |
HUnit.assertEqual "" "1.3.0.0" $ nextIp4Address "1.2.255.255" |
493 | 493 |
HUnit.assertEqual "" "1.2.255.63" $ nextIp4Address "1.2.255.62" |
494 | 494 |
|
495 |
-- | Tests the compatibility between Haskell-serialized instances and their |
|
496 |
-- python-decoded and encoded version. |
|
497 |
-- Note: this can be enhanced with logical validations on the decoded objects |
|
498 |
casePyCompatInstances :: HUnit.Assertion |
|
499 |
casePyCompatInstances = do |
|
500 |
let num_inst = 500::Int |
|
501 |
instances <- genSample (vectorOf num_inst genInst) |
|
502 |
let serialized = J.encode instances |
|
503 |
-- check for non-ASCII fields, usually due to 'arbitrary :: String' |
|
504 |
mapM_ (\inst -> when (any (not . isAscii) (J.encode inst)) . |
|
505 |
HUnit.assertFailure $ |
|
506 |
"Instance has non-ASCII fields: " ++ show inst |
|
507 |
) instances |
|
508 |
py_stdout <- |
|
509 |
runPython "from ganeti import objects\n\ |
|
510 |
\from ganeti import serializer\n\ |
|
511 |
\import sys\n\ |
|
512 |
\inst_data = serializer.Load(sys.stdin.read())\n\ |
|
513 |
\decoded = [objects.Instance.FromDict(i) for i in inst_data]\n\ |
|
514 |
\encoded = [i.ToDict() for i in decoded]\n\ |
|
515 |
\print serializer.Dump(encoded)" serialized |
|
516 |
>>= checkPythonResult |
|
517 |
let deserialised = J.decode py_stdout::J.Result [Instance] |
|
518 |
decoded <- case deserialised of |
|
519 |
J.Ok ops -> return ops |
|
520 |
J.Error msg -> |
|
521 |
HUnit.assertFailure ("Unable to decode instance: " ++ msg) |
|
522 |
-- this already raised an expection, but we need it |
|
523 |
-- for proper types |
|
524 |
>> fail "Unable to decode instances" |
|
525 |
HUnit.assertEqual "Mismatch in number of returned instances" |
|
526 |
(length decoded) (length instances) |
|
527 |
mapM_ (uncurry (HUnit.assertEqual "Different result after encoding/decoding") |
|
528 |
) $ zip decoded instances |
|
529 |
|
|
495 | 530 |
testSuite "Objects" |
496 | 531 |
[ 'prop_fillDict |
497 | 532 |
, 'prop_Disk_serialisation |
... | ... | |
501 | 536 |
, 'prop_Config_serialisation |
502 | 537 |
, 'casePyCompatNetworks |
503 | 538 |
, 'casePyCompatNodegroups |
539 |
, 'casePyCompatInstances |
|
504 | 540 |
, 'prop_nextIp4Address |
505 | 541 |
, 'caseNextIp4Address |
506 | 542 |
] |
Also available in: Unified diff