Revision 2d87bd0a htools/Ganeti/HTools/QC.hs
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
32 | 32 |
-} |
33 | 33 |
|
34 | 34 |
module Ganeti.HTools.QC |
35 |
( testJobs |
|
36 |
, testJSON |
|
37 |
) where |
|
35 |
() where |
|
38 | 36 |
|
39 | 37 |
import qualified Test.HUnit as HUnit |
40 | 38 |
import Test.QuickCheck |
... | ... | |
100 | 98 |
|
101 | 99 |
import Test.Ganeti.TestHelper (testSuite) |
102 | 100 |
import Test.Ganeti.TestCommon |
103 |
|
|
104 |
-- * Helper functions |
|
105 |
|
|
106 |
|
|
107 |
instance Arbitrary Jobs.OpStatus where |
|
108 |
arbitrary = elements [minBound..maxBound] |
|
109 |
|
|
110 |
instance Arbitrary Jobs.JobStatus where |
|
111 |
arbitrary = elements [minBound..maxBound] |
|
112 |
|
|
113 |
-- * Actual tests |
|
114 |
|
|
115 |
|
|
116 |
-- ** Jobs tests |
|
117 |
|
|
118 |
-- | Check that (queued) job\/opcode status serialization is idempotent. |
|
119 |
prop_Jobs_OpStatus_serialization :: Jobs.OpStatus -> Property |
|
120 |
prop_Jobs_OpStatus_serialization os = |
|
121 |
case J.readJSON (J.showJSON os) of |
|
122 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
|
123 |
J.Ok os' -> os ==? os' |
|
124 |
|
|
125 |
prop_Jobs_JobStatus_serialization :: Jobs.JobStatus -> Property |
|
126 |
prop_Jobs_JobStatus_serialization js = |
|
127 |
case J.readJSON (J.showJSON js) of |
|
128 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
|
129 |
J.Ok js' -> js ==? js' |
|
130 |
|
|
131 |
testSuite "Jobs" |
|
132 |
[ 'prop_Jobs_OpStatus_serialization |
|
133 |
, 'prop_Jobs_JobStatus_serialization |
|
134 |
] |
|
135 |
|
|
136 |
-- * JSON tests |
|
137 |
|
|
138 |
prop_JSON_toArray :: [Int] -> Property |
|
139 |
prop_JSON_toArray intarr = |
|
140 |
let arr = map J.showJSON intarr in |
|
141 |
case JSON.toArray (J.JSArray arr) of |
|
142 |
Types.Ok arr' -> arr ==? arr' |
|
143 |
Types.Bad err -> failTest $ "Failed to parse array: " ++ err |
|
144 |
|
|
145 |
prop_JSON_toArrayFail :: Int -> String -> Bool -> Property |
|
146 |
prop_JSON_toArrayFail i s b = |
|
147 |
-- poor man's instance Arbitrary JSValue |
|
148 |
forAll (elements [J.showJSON i, J.showJSON s, J.showJSON b]) $ \item -> |
|
149 |
case JSON.toArray item of |
|
150 |
Types.Bad _ -> property True |
|
151 |
Types.Ok result -> failTest $ "Unexpected parse, got " ++ show result |
|
152 |
|
|
153 |
testSuite "JSON" |
|
154 |
[ 'prop_JSON_toArray |
|
155 |
, 'prop_JSON_toArrayFail |
|
156 |
] |
Also available in: Unified diff