From bccb8d20d9f7fa3fca80cc099696798eb421eb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dato=20Sim=C3=B3?= <dato@google.com> Date: Thu, 6 Dec 2012 18:43:25 +0000 Subject: [PATCH] htest/Types.hs: check ordering of some ADTs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some ADT, ordering of constructors is important because a certain meaning is attached to ordinality (e.g., "clusters with lesser AllocPolicy are preferred"). To ensure constructor order is not accidentally changed, this commit introduces assertions that verify the ordering of these types is as expected. Signed-off-by: Dato SimΓ³ <dato@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- htest/Test/Ganeti/Types.hs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/htest/Test/Ganeti/Types.hs b/htest/Test/Ganeti/Types.hs index 0129a525b..971b974ad 100644 --- a/htest/Test/Ganeti/Types.hs +++ b/htest/Test/Ganeti/Types.hs @@ -137,6 +137,14 @@ $(genArbitrary ''OpStatus) prop_AllocPolicy_serialisation :: AllocPolicy -> Property prop_AllocPolicy_serialisation = testSerialisation +-- | Test 'AllocPolicy' ordering is as expected. +case_AllocPolicy_order :: Assertion +case_AllocPolicy_order = + assertEqual "sort order" [ Types.AllocPreferred + , Types.AllocLastResort + , Types.AllocUnallocable + ] [minBound..maxBound] + prop_DiskTemplate_serialisation :: DiskTemplate -> Property prop_DiskTemplate_serialisation = testSerialisation @@ -299,6 +307,18 @@ prop_OpStatus_serialization = testSerialisation prop_JobStatus_serialization :: JobStatus -> Property prop_JobStatus_serialization = testSerialisation +-- | Test 'JobStatus' ordering is as expected. +case_JobStatus_order :: Assertion +case_JobStatus_order = + assertEqual "sort order" [ Types.JOB_STATUS_QUEUED + , Types.JOB_STATUS_WAITING + , Types.JOB_STATUS_CANCELING + , Types.JOB_STATUS_RUNNING + , Types.JOB_STATUS_CANCELED + , Types.JOB_STATUS_SUCCESS + , Types.JOB_STATUS_ERROR + ] [minBound..maxBound] + -- | Tests equivalence with Python, based on Constants.hs code. case_NICMode_pyequiv :: Assertion case_NICMode_pyequiv = do @@ -334,6 +354,7 @@ prop_OpSubmitPriority_serialisation = testSerialisation testSuite "Types" [ 'prop_AllocPolicy_serialisation + , 'case_AllocPolicy_order , 'prop_DiskTemplate_serialisation , 'prop_InstanceStatus_serialisation , 'prop_NonNeg_pass @@ -366,6 +387,7 @@ testSuite "Types" , 'prop_NICMode_serialisation , 'prop_OpStatus_serialization , 'prop_JobStatus_serialization + , 'case_JobStatus_order , 'case_NICMode_pyequiv , 'prop_FinalizedJobStatus_serialisation , 'case_FinalizedJobStatus_pyequiv -- GitLab