htest/Types.hs: check ordering of some ADTs
authorDato Simó <dato@google.com>
Thu, 6 Dec 2012 18:43:25 +0000 (18:43 +0000)
committerDato Simó <dato@google.com>
Fri, 7 Dec 2012 15:43:35 +0000 (15:43 +0000)
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

index 0129a52..971b974 100644 (file)
@@ -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