root / test / hs / Test / Ganeti / Types.hs @ efa6dd08
History | View | Annotate | Download (14.8 kB)
1 | 5e9deac0 | Iustin Pop | {-# LANGUAGE TemplateHaskell #-} |
---|---|---|---|
2 | 5e9deac0 | Iustin Pop | {-# OPTIONS_GHC -fno-warn-orphans #-} |
3 | 5e9deac0 | Iustin Pop | |
4 | 5e9deac0 | Iustin Pop | {-| Unittests for 'Ganeti.Types'. |
5 | 5e9deac0 | Iustin Pop | |
6 | 5e9deac0 | Iustin Pop | -} |
7 | 5e9deac0 | Iustin Pop | |
8 | 5e9deac0 | Iustin Pop | {- |
9 | 5e9deac0 | Iustin Pop | |
10 | 37fe56e0 | Iustin Pop | Copyright (C) 2012, 2013 Google Inc. |
11 | 5e9deac0 | Iustin Pop | |
12 | 5e9deac0 | Iustin Pop | This program is free software; you can redistribute it and/or modify |
13 | 5e9deac0 | Iustin Pop | it under the terms of the GNU General Public License as published by |
14 | 5e9deac0 | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
15 | 5e9deac0 | Iustin Pop | (at your option) any later version. |
16 | 5e9deac0 | Iustin Pop | |
17 | 5e9deac0 | Iustin Pop | This program is distributed in the hope that it will be useful, but |
18 | 5e9deac0 | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | 5e9deac0 | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | 5e9deac0 | Iustin Pop | General Public License for more details. |
21 | 5e9deac0 | Iustin Pop | |
22 | 5e9deac0 | Iustin Pop | You should have received a copy of the GNU General Public License |
23 | 5e9deac0 | Iustin Pop | along with this program; if not, write to the Free Software |
24 | 5e9deac0 | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25 | 5e9deac0 | Iustin Pop | 02110-1301, USA. |
26 | 5e9deac0 | Iustin Pop | |
27 | 5e9deac0 | Iustin Pop | -} |
28 | 5e9deac0 | Iustin Pop | |
29 | 5e9deac0 | Iustin Pop | module Test.Ganeti.Types |
30 | 5e9deac0 | Iustin Pop | ( testTypes |
31 | 5e9deac0 | Iustin Pop | , AllocPolicy(..) |
32 | 5e9deac0 | Iustin Pop | , DiskTemplate(..) |
33 | 3cbd5808 | Iustin Pop | , allDiskTemplates |
34 | 5e9deac0 | Iustin Pop | , InstanceStatus(..) |
35 | edb5a1c8 | Iustin Pop | , NonEmpty(..) |
36 | 22381768 | Iustin Pop | , Hypervisor(..) |
37 | c48711d5 | Iustin Pop | , JobId(..) |
38 | 5e9deac0 | Iustin Pop | ) where |
39 | 5e9deac0 | Iustin Pop | |
40 | 3cbd5808 | Iustin Pop | import Data.List (delete, sort) |
41 | edb5a1c8 | Iustin Pop | import Test.QuickCheck as QuickCheck hiding (Result) |
42 | edb5a1c8 | Iustin Pop | import Test.HUnit |
43 | c48711d5 | Iustin Pop | import qualified Text.JSON as J |
44 | 5e9deac0 | Iustin Pop | |
45 | 5e9deac0 | Iustin Pop | import Test.Ganeti.TestHelper |
46 | 5e9deac0 | Iustin Pop | import Test.Ganeti.TestCommon |
47 | 5e9deac0 | Iustin Pop | |
48 | edb5a1c8 | Iustin Pop | import Ganeti.BasicTypes |
49 | d696bbef | Iustin Pop | import qualified Ganeti.Constants as C |
50 | edb5a1c8 | Iustin Pop | import Ganeti.Types as Types |
51 | 90634d95 | Iustin Pop | import Ganeti.JSON |
52 | 5e9deac0 | Iustin Pop | |
53 | 39573352 | Iustin Pop | {-# ANN module "HLint: ignore Use camelCase" #-} |
54 | 39573352 | Iustin Pop | |
55 | 5e9deac0 | Iustin Pop | -- * Arbitrary instance |
56 | 5e9deac0 | Iustin Pop | |
57 | edb5a1c8 | Iustin Pop | instance (Arbitrary a, Ord a, Num a, Show a) => |
58 | edb5a1c8 | Iustin Pop | Arbitrary (Types.Positive a) where |
59 | edb5a1c8 | Iustin Pop | arbitrary = do |
60 | edb5a1c8 | Iustin Pop | (QuickCheck.Positive i) <- arbitrary |
61 | edb5a1c8 | Iustin Pop | Types.mkPositive i |
62 | edb5a1c8 | Iustin Pop | |
63 | 6d558717 | Iustin Pop | instance (Arbitrary a, Ord a, Num a, Show a) => |
64 | 6d558717 | Iustin Pop | Arbitrary (Types.NonNegative a) where |
65 | 6d558717 | Iustin Pop | arbitrary = do |
66 | 6d558717 | Iustin Pop | (QuickCheck.NonNegative i) <- arbitrary |
67 | 6d558717 | Iustin Pop | Types.mkNonNegative i |
68 | 6d558717 | Iustin Pop | |
69 | c67b908a | Iustin Pop | instance (Arbitrary a, Ord a, Num a, Show a) => |
70 | c67b908a | Iustin Pop | Arbitrary (Types.Negative a) where |
71 | c67b908a | Iustin Pop | arbitrary = do |
72 | c67b908a | Iustin Pop | (QuickCheck.Positive i) <- arbitrary |
73 | c67b908a | Iustin Pop | Types.mkNegative $ negate i |
74 | c67b908a | Iustin Pop | |
75 | c65621d7 | Iustin Pop | instance (Arbitrary a) => Arbitrary (Types.NonEmpty a) where |
76 | c65621d7 | Iustin Pop | arbitrary = do |
77 | c65621d7 | Iustin Pop | QuickCheck.NonEmpty lst <- arbitrary |
78 | c65621d7 | Iustin Pop | Types.mkNonEmpty lst |
79 | c65621d7 | Iustin Pop | |
80 | 5e9deac0 | Iustin Pop | $(genArbitrary ''AllocPolicy) |
81 | 5e9deac0 | Iustin Pop | |
82 | 3cbd5808 | Iustin Pop | -- | Valid disk templates (depending on configure options). |
83 | 3cbd5808 | Iustin Pop | allDiskTemplates :: [DiskTemplate] |
84 | 3cbd5808 | Iustin Pop | allDiskTemplates = |
85 | 3cbd5808 | Iustin Pop | let all_vals = [minBound..maxBound]::[DiskTemplate] |
86 | 3cbd5808 | Iustin Pop | sel1 = if C.enableFileStorage |
87 | 3cbd5808 | Iustin Pop | then all_vals |
88 | 3cbd5808 | Iustin Pop | else delete DTFile all_vals |
89 | 3cbd5808 | Iustin Pop | sel2 = if C.enableSharedFileStorage |
90 | 3cbd5808 | Iustin Pop | then sel1 |
91 | 3cbd5808 | Iustin Pop | else delete DTSharedFile sel1 |
92 | 3cbd5808 | Iustin Pop | in sel2 |
93 | 3cbd5808 | Iustin Pop | |
94 | 3cbd5808 | Iustin Pop | -- | Custom 'Arbitrary' instance for 'DiskTemplate', which needs to |
95 | 3cbd5808 | Iustin Pop | -- handle the case of file storage being disabled at configure time. |
96 | 3cbd5808 | Iustin Pop | instance Arbitrary DiskTemplate where |
97 | 3cbd5808 | Iustin Pop | arbitrary = elements allDiskTemplates |
98 | 5e9deac0 | Iustin Pop | |
99 | 5e9deac0 | Iustin Pop | $(genArbitrary ''InstanceStatus) |
100 | 5e9deac0 | Iustin Pop | |
101 | d696bbef | Iustin Pop | $(genArbitrary ''MigrationMode) |
102 | d696bbef | Iustin Pop | |
103 | d696bbef | Iustin Pop | $(genArbitrary ''VerifyOptionalChecks) |
104 | d696bbef | Iustin Pop | |
105 | d696bbef | Iustin Pop | $(genArbitrary ''DdmSimple) |
106 | d696bbef | Iustin Pop | |
107 | c2d3219b | Iustin Pop | $(genArbitrary ''DdmFull) |
108 | c2d3219b | Iustin Pop | |
109 | d696bbef | Iustin Pop | $(genArbitrary ''CVErrorCode) |
110 | d696bbef | Iustin Pop | |
111 | 22381768 | Iustin Pop | $(genArbitrary ''Hypervisor) |
112 | 22381768 | Iustin Pop | |
113 | 6a28e02c | Iustin Pop | $(genArbitrary ''OobCommand) |
114 | 6a28e02c | Iustin Pop | |
115 | 3cbd5808 | Iustin Pop | -- | Valid storage types. |
116 | 3cbd5808 | Iustin Pop | allStorageTypes :: [StorageType] |
117 | 3cbd5808 | Iustin Pop | allStorageTypes = |
118 | 3cbd5808 | Iustin Pop | let all_vals = [minBound..maxBound]::[StorageType] |
119 | 3cbd5808 | Iustin Pop | in if C.enableFileStorage |
120 | 3cbd5808 | Iustin Pop | then all_vals |
121 | 3cbd5808 | Iustin Pop | else delete StorageFile all_vals |
122 | 3cbd5808 | Iustin Pop | |
123 | 3cbd5808 | Iustin Pop | -- | Custom 'Arbitrary' instance for 'StorageType', which needs to |
124 | 3cbd5808 | Iustin Pop | -- handle the case of file storage being disabled at configure time. |
125 | 3cbd5808 | Iustin Pop | instance Arbitrary StorageType where |
126 | 3cbd5808 | Iustin Pop | arbitrary = elements allStorageTypes |
127 | 48755fac | Iustin Pop | |
128 | 6a28e02c | Iustin Pop | $(genArbitrary ''NodeEvacMode) |
129 | 6a28e02c | Iustin Pop | |
130 | c65621d7 | Iustin Pop | $(genArbitrary ''FileDriver) |
131 | edb5a1c8 | Iustin Pop | |
132 | 6d558717 | Iustin Pop | $(genArbitrary ''InstCreateMode) |
133 | 6d558717 | Iustin Pop | |
134 | c2d3219b | Iustin Pop | $(genArbitrary ''RebootType) |
135 | c2d3219b | Iustin Pop | |
136 | 398e9066 | Iustin Pop | $(genArbitrary ''ExportMode) |
137 | 398e9066 | Iustin Pop | |
138 | a3f02317 | Iustin Pop | $(genArbitrary ''IAllocatorTestDir) |
139 | a3f02317 | Iustin Pop | |
140 | a3f02317 | Iustin Pop | $(genArbitrary ''IAllocatorMode) |
141 | a3f02317 | Iustin Pop | |
142 | 497beee2 | Iustin Pop | $(genArbitrary ''NICMode) |
143 | 497beee2 | Iustin Pop | |
144 | 3bdbe4b3 | Dato Simó | $(genArbitrary ''JobStatus) |
145 | 3bdbe4b3 | Dato Simó | |
146 | 6903fea0 | Iustin Pop | $(genArbitrary ''FinalizedJobStatus) |
147 | 6903fea0 | Iustin Pop | |
148 | b46ba79c | Iustin Pop | instance Arbitrary JobId where |
149 | c48711d5 | Iustin Pop | arbitrary = do |
150 | c48711d5 | Iustin Pop | (Positive i) <- arbitrary |
151 | b46ba79c | Iustin Pop | makeJobId i |
152 | b46ba79c | Iustin Pop | |
153 | b46ba79c | Iustin Pop | $(genArbitrary ''JobIdDep) |
154 | b46ba79c | Iustin Pop | |
155 | b46ba79c | Iustin Pop | $(genArbitrary ''JobDependency) |
156 | b46ba79c | Iustin Pop | |
157 | b46ba79c | Iustin Pop | $(genArbitrary ''OpSubmitPriority) |
158 | c48711d5 | Iustin Pop | |
159 | 3bdbe4b3 | Dato Simó | $(genArbitrary ''OpStatus) |
160 | 3bdbe4b3 | Dato Simó | |
161 | 5cd95d46 | Iustin Pop | $(genArbitrary ''ELogType) |
162 | 5cd95d46 | Iustin Pop | |
163 | d696bbef | Iustin Pop | -- * Properties |
164 | d696bbef | Iustin Pop | |
165 | 5e9deac0 | Iustin Pop | prop_AllocPolicy_serialisation :: AllocPolicy -> Property |
166 | 5e9deac0 | Iustin Pop | prop_AllocPolicy_serialisation = testSerialisation |
167 | 5e9deac0 | Iustin Pop | |
168 | bccb8d20 | Dato Simó | -- | Test 'AllocPolicy' ordering is as expected. |
169 | bccb8d20 | Dato Simó | case_AllocPolicy_order :: Assertion |
170 | bccb8d20 | Dato Simó | case_AllocPolicy_order = |
171 | bccb8d20 | Dato Simó | assertEqual "sort order" [ Types.AllocPreferred |
172 | bccb8d20 | Dato Simó | , Types.AllocLastResort |
173 | bccb8d20 | Dato Simó | , Types.AllocUnallocable |
174 | bccb8d20 | Dato Simó | ] [minBound..maxBound] |
175 | bccb8d20 | Dato Simó | |
176 | 5e9deac0 | Iustin Pop | prop_DiskTemplate_serialisation :: DiskTemplate -> Property |
177 | 5e9deac0 | Iustin Pop | prop_DiskTemplate_serialisation = testSerialisation |
178 | 5e9deac0 | Iustin Pop | |
179 | 5e9deac0 | Iustin Pop | prop_InstanceStatus_serialisation :: InstanceStatus -> Property |
180 | 5e9deac0 | Iustin Pop | prop_InstanceStatus_serialisation = testSerialisation |
181 | 5e9deac0 | Iustin Pop | |
182 | edb5a1c8 | Iustin Pop | -- | Tests building non-negative numbers. |
183 | edb5a1c8 | Iustin Pop | prop_NonNeg_pass :: QuickCheck.NonNegative Int -> Property |
184 | edb5a1c8 | Iustin Pop | prop_NonNeg_pass (QuickCheck.NonNegative i) = |
185 | edb5a1c8 | Iustin Pop | case mkNonNegative i of |
186 | edb5a1c8 | Iustin Pop | Bad msg -> failTest $ "Fail to build non-negative: " ++ msg |
187 | edb5a1c8 | Iustin Pop | Ok nn -> fromNonNegative nn ==? i |
188 | edb5a1c8 | Iustin Pop | |
189 | edb5a1c8 | Iustin Pop | -- | Tests building non-negative numbers. |
190 | edb5a1c8 | Iustin Pop | prop_NonNeg_fail :: QuickCheck.Positive Int -> Property |
191 | edb5a1c8 | Iustin Pop | prop_NonNeg_fail (QuickCheck.Positive i) = |
192 | edb5a1c8 | Iustin Pop | case mkNonNegative (negate i)::Result (Types.NonNegative Int) of |
193 | edb5a1c8 | Iustin Pop | Bad _ -> passTest |
194 | edb5a1c8 | Iustin Pop | Ok nn -> failTest $ "Built non-negative number '" ++ show nn ++ |
195 | edb5a1c8 | Iustin Pop | "' from negative value " ++ show i |
196 | edb5a1c8 | Iustin Pop | |
197 | edb5a1c8 | Iustin Pop | -- | Tests building positive numbers. |
198 | edb5a1c8 | Iustin Pop | prop_Positive_pass :: QuickCheck.Positive Int -> Property |
199 | edb5a1c8 | Iustin Pop | prop_Positive_pass (QuickCheck.Positive i) = |
200 | edb5a1c8 | Iustin Pop | case mkPositive i of |
201 | edb5a1c8 | Iustin Pop | Bad msg -> failTest $ "Fail to build positive: " ++ msg |
202 | edb5a1c8 | Iustin Pop | Ok nn -> fromPositive nn ==? i |
203 | edb5a1c8 | Iustin Pop | |
204 | edb5a1c8 | Iustin Pop | -- | Tests building positive numbers. |
205 | edb5a1c8 | Iustin Pop | prop_Positive_fail :: QuickCheck.NonNegative Int -> Property |
206 | edb5a1c8 | Iustin Pop | prop_Positive_fail (QuickCheck.NonNegative i) = |
207 | edb5a1c8 | Iustin Pop | case mkPositive (negate i)::Result (Types.Positive Int) of |
208 | edb5a1c8 | Iustin Pop | Bad _ -> passTest |
209 | edb5a1c8 | Iustin Pop | Ok nn -> failTest $ "Built positive number '" ++ show nn ++ |
210 | edb5a1c8 | Iustin Pop | "' from negative or zero value " ++ show i |
211 | edb5a1c8 | Iustin Pop | |
212 | c67b908a | Iustin Pop | -- | Tests building negative numbers. |
213 | c67b908a | Iustin Pop | prop_Neg_pass :: QuickCheck.Positive Int -> Property |
214 | c67b908a | Iustin Pop | prop_Neg_pass (QuickCheck.Positive i) = |
215 | c67b908a | Iustin Pop | case mkNegative i' of |
216 | c67b908a | Iustin Pop | Bad msg -> failTest $ "Fail to build negative: " ++ msg |
217 | c67b908a | Iustin Pop | Ok nn -> fromNegative nn ==? i' |
218 | c67b908a | Iustin Pop | where i' = negate i |
219 | c67b908a | Iustin Pop | |
220 | c67b908a | Iustin Pop | -- | Tests building negative numbers. |
221 | c67b908a | Iustin Pop | prop_Neg_fail :: QuickCheck.NonNegative Int -> Property |
222 | c67b908a | Iustin Pop | prop_Neg_fail (QuickCheck.NonNegative i) = |
223 | c67b908a | Iustin Pop | case mkNegative i::Result (Types.Negative Int) of |
224 | c67b908a | Iustin Pop | Bad _ -> passTest |
225 | c67b908a | Iustin Pop | Ok nn -> failTest $ "Built negative number '" ++ show nn ++ |
226 | c67b908a | Iustin Pop | "' from non-negative value " ++ show i |
227 | c67b908a | Iustin Pop | |
228 | edb5a1c8 | Iustin Pop | -- | Tests building non-empty lists. |
229 | 39573352 | Iustin Pop | prop_NonEmpty_pass :: QuickCheck.NonEmptyList String -> Property |
230 | edb5a1c8 | Iustin Pop | prop_NonEmpty_pass (QuickCheck.NonEmpty xs) = |
231 | edb5a1c8 | Iustin Pop | case mkNonEmpty xs of |
232 | edb5a1c8 | Iustin Pop | Bad msg -> failTest $ "Fail to build non-empty list: " ++ msg |
233 | edb5a1c8 | Iustin Pop | Ok nn -> fromNonEmpty nn ==? xs |
234 | edb5a1c8 | Iustin Pop | |
235 | edb5a1c8 | Iustin Pop | -- | Tests building positive numbers. |
236 | edb5a1c8 | Iustin Pop | case_NonEmpty_fail :: Assertion |
237 | 39573352 | Iustin Pop | case_NonEmpty_fail = |
238 | edb5a1c8 | Iustin Pop | assertEqual "building non-empty list from an empty list" |
239 | edb5a1c8 | Iustin Pop | (Bad "Received empty value for non-empty list") (mkNonEmpty ([]::[Int])) |
240 | edb5a1c8 | Iustin Pop | |
241 | d696bbef | Iustin Pop | -- | Tests migration mode serialisation. |
242 | d696bbef | Iustin Pop | prop_MigrationMode_serialisation :: MigrationMode -> Property |
243 | d696bbef | Iustin Pop | prop_MigrationMode_serialisation = testSerialisation |
244 | d696bbef | Iustin Pop | |
245 | d696bbef | Iustin Pop | -- | Tests verify optional checks serialisation. |
246 | d696bbef | Iustin Pop | prop_VerifyOptionalChecks_serialisation :: VerifyOptionalChecks -> Property |
247 | d696bbef | Iustin Pop | prop_VerifyOptionalChecks_serialisation = testSerialisation |
248 | d696bbef | Iustin Pop | |
249 | d696bbef | Iustin Pop | -- | Tests 'DdmSimple' serialisation. |
250 | d696bbef | Iustin Pop | prop_DdmSimple_serialisation :: DdmSimple -> Property |
251 | d696bbef | Iustin Pop | prop_DdmSimple_serialisation = testSerialisation |
252 | d696bbef | Iustin Pop | |
253 | c2d3219b | Iustin Pop | -- | Tests 'DdmFull' serialisation. |
254 | c2d3219b | Iustin Pop | prop_DdmFull_serialisation :: DdmFull -> Property |
255 | c2d3219b | Iustin Pop | prop_DdmFull_serialisation = testSerialisation |
256 | c2d3219b | Iustin Pop | |
257 | d696bbef | Iustin Pop | -- | Tests 'CVErrorCode' serialisation. |
258 | d696bbef | Iustin Pop | prop_CVErrorCode_serialisation :: CVErrorCode -> Property |
259 | d696bbef | Iustin Pop | prop_CVErrorCode_serialisation = testSerialisation |
260 | d696bbef | Iustin Pop | |
261 | d696bbef | Iustin Pop | -- | Tests equivalence with Python, based on Constants.hs code. |
262 | d696bbef | Iustin Pop | case_CVErrorCode_pyequiv :: Assertion |
263 | d696bbef | Iustin Pop | case_CVErrorCode_pyequiv = do |
264 | d696bbef | Iustin Pop | let all_py_codes = sort C.cvAllEcodesStrings |
265 | d696bbef | Iustin Pop | all_hs_codes = sort $ map Types.cVErrorCodeToRaw [minBound..maxBound] |
266 | d696bbef | Iustin Pop | assertEqual "for CVErrorCode equivalence" all_py_codes all_hs_codes |
267 | d696bbef | Iustin Pop | |
268 | 22381768 | Iustin Pop | -- | Test 'Hypervisor' serialisation. |
269 | 22381768 | Iustin Pop | prop_Hypervisor_serialisation :: Hypervisor -> Property |
270 | 22381768 | Iustin Pop | prop_Hypervisor_serialisation = testSerialisation |
271 | 22381768 | Iustin Pop | |
272 | 6a28e02c | Iustin Pop | -- | Test 'OobCommand' serialisation. |
273 | 6a28e02c | Iustin Pop | prop_OobCommand_serialisation :: OobCommand -> Property |
274 | 6a28e02c | Iustin Pop | prop_OobCommand_serialisation = testSerialisation |
275 | 6a28e02c | Iustin Pop | |
276 | 48755fac | Iustin Pop | -- | Test 'StorageType' serialisation. |
277 | 48755fac | Iustin Pop | prop_StorageType_serialisation :: StorageType -> Property |
278 | 48755fac | Iustin Pop | prop_StorageType_serialisation = testSerialisation |
279 | 48755fac | Iustin Pop | |
280 | 6a28e02c | Iustin Pop | -- | Test 'NodeEvacMode' serialisation. |
281 | 6a28e02c | Iustin Pop | prop_NodeEvacMode_serialisation :: NodeEvacMode -> Property |
282 | 6a28e02c | Iustin Pop | prop_NodeEvacMode_serialisation = testSerialisation |
283 | 6a28e02c | Iustin Pop | |
284 | c65621d7 | Iustin Pop | -- | Test 'FileDriver' serialisation. |
285 | c65621d7 | Iustin Pop | prop_FileDriver_serialisation :: FileDriver -> Property |
286 | c65621d7 | Iustin Pop | prop_FileDriver_serialisation = testSerialisation |
287 | c65621d7 | Iustin Pop | |
288 | 6d558717 | Iustin Pop | -- | Test 'InstCreate' serialisation. |
289 | 6d558717 | Iustin Pop | prop_InstCreateMode_serialisation :: InstCreateMode -> Property |
290 | 6d558717 | Iustin Pop | prop_InstCreateMode_serialisation = testSerialisation |
291 | 6d558717 | Iustin Pop | |
292 | c2d3219b | Iustin Pop | -- | Test 'RebootType' serialisation. |
293 | c2d3219b | Iustin Pop | prop_RebootType_serialisation :: RebootType -> Property |
294 | c2d3219b | Iustin Pop | prop_RebootType_serialisation = testSerialisation |
295 | c2d3219b | Iustin Pop | |
296 | 398e9066 | Iustin Pop | -- | Test 'ExportMode' serialisation. |
297 | 398e9066 | Iustin Pop | prop_ExportMode_serialisation :: ExportMode -> Property |
298 | 398e9066 | Iustin Pop | prop_ExportMode_serialisation = testSerialisation |
299 | 398e9066 | Iustin Pop | |
300 | a3f02317 | Iustin Pop | -- | Test 'IAllocatorTestDir' serialisation. |
301 | a3f02317 | Iustin Pop | prop_IAllocatorTestDir_serialisation :: IAllocatorTestDir -> Property |
302 | a3f02317 | Iustin Pop | prop_IAllocatorTestDir_serialisation = testSerialisation |
303 | a3f02317 | Iustin Pop | |
304 | a3f02317 | Iustin Pop | -- | Test 'IAllocatorMode' serialisation. |
305 | a3f02317 | Iustin Pop | prop_IAllocatorMode_serialisation :: IAllocatorMode -> Property |
306 | a3f02317 | Iustin Pop | prop_IAllocatorMode_serialisation = testSerialisation |
307 | a3f02317 | Iustin Pop | |
308 | a3f02317 | Iustin Pop | -- | Tests equivalence with Python, based on Constants.hs code. |
309 | a3f02317 | Iustin Pop | case_IAllocatorMode_pyequiv :: Assertion |
310 | a3f02317 | Iustin Pop | case_IAllocatorMode_pyequiv = do |
311 | a3f02317 | Iustin Pop | let all_py_codes = sort C.validIallocatorModes |
312 | a3f02317 | Iustin Pop | all_hs_codes = sort $ map Types.iAllocatorModeToRaw [minBound..maxBound] |
313 | a3f02317 | Iustin Pop | assertEqual "for IAllocatorMode equivalence" all_py_codes all_hs_codes |
314 | a3f02317 | Iustin Pop | |
315 | 497beee2 | Iustin Pop | -- | Test 'NICMode' serialisation. |
316 | 497beee2 | Iustin Pop | prop_NICMode_serialisation :: NICMode -> Property |
317 | 497beee2 | Iustin Pop | prop_NICMode_serialisation = testSerialisation |
318 | 497beee2 | Iustin Pop | |
319 | 3bdbe4b3 | Dato Simó | -- | Test 'OpStatus' serialisation. |
320 | 3bdbe4b3 | Dato Simó | prop_OpStatus_serialization :: OpStatus -> Property |
321 | 3bdbe4b3 | Dato Simó | prop_OpStatus_serialization = testSerialisation |
322 | 3bdbe4b3 | Dato Simó | |
323 | 3bdbe4b3 | Dato Simó | -- | Test 'JobStatus' serialisation. |
324 | 3bdbe4b3 | Dato Simó | prop_JobStatus_serialization :: JobStatus -> Property |
325 | 3bdbe4b3 | Dato Simó | prop_JobStatus_serialization = testSerialisation |
326 | 3bdbe4b3 | Dato Simó | |
327 | bccb8d20 | Dato Simó | -- | Test 'JobStatus' ordering is as expected. |
328 | bccb8d20 | Dato Simó | case_JobStatus_order :: Assertion |
329 | bccb8d20 | Dato Simó | case_JobStatus_order = |
330 | bccb8d20 | Dato Simó | assertEqual "sort order" [ Types.JOB_STATUS_QUEUED |
331 | bccb8d20 | Dato Simó | , Types.JOB_STATUS_WAITING |
332 | bccb8d20 | Dato Simó | , Types.JOB_STATUS_CANCELING |
333 | bccb8d20 | Dato Simó | , Types.JOB_STATUS_RUNNING |
334 | bccb8d20 | Dato Simó | , Types.JOB_STATUS_CANCELED |
335 | bccb8d20 | Dato Simó | , Types.JOB_STATUS_SUCCESS |
336 | bccb8d20 | Dato Simó | , Types.JOB_STATUS_ERROR |
337 | bccb8d20 | Dato Simó | ] [minBound..maxBound] |
338 | bccb8d20 | Dato Simó | |
339 | 497beee2 | Iustin Pop | -- | Tests equivalence with Python, based on Constants.hs code. |
340 | 497beee2 | Iustin Pop | case_NICMode_pyequiv :: Assertion |
341 | 497beee2 | Iustin Pop | case_NICMode_pyequiv = do |
342 | 497beee2 | Iustin Pop | let all_py_codes = sort C.nicValidModes |
343 | 497beee2 | Iustin Pop | all_hs_codes = sort $ map Types.nICModeToRaw [minBound..maxBound] |
344 | 497beee2 | Iustin Pop | assertEqual "for NICMode equivalence" all_py_codes all_hs_codes |
345 | 497beee2 | Iustin Pop | |
346 | 6903fea0 | Iustin Pop | -- | Test 'FinalizedJobStatus' serialisation. |
347 | 6903fea0 | Iustin Pop | prop_FinalizedJobStatus_serialisation :: FinalizedJobStatus -> Property |
348 | 6903fea0 | Iustin Pop | prop_FinalizedJobStatus_serialisation = testSerialisation |
349 | 6903fea0 | Iustin Pop | |
350 | 6903fea0 | Iustin Pop | -- | Tests equivalence with Python, based on Constants.hs code. |
351 | 6903fea0 | Iustin Pop | case_FinalizedJobStatus_pyequiv :: Assertion |
352 | 6903fea0 | Iustin Pop | case_FinalizedJobStatus_pyequiv = do |
353 | 6903fea0 | Iustin Pop | let all_py_codes = sort C.jobsFinalized |
354 | 6903fea0 | Iustin Pop | all_hs_codes = sort $ map Types.finalizedJobStatusToRaw |
355 | 6903fea0 | Iustin Pop | [minBound..maxBound] |
356 | 6903fea0 | Iustin Pop | assertEqual "for FinalizedJobStatus equivalence" all_py_codes all_hs_codes |
357 | 6903fea0 | Iustin Pop | |
358 | c48711d5 | Iustin Pop | -- | Tests JobId serialisation (both from string and ints). |
359 | c48711d5 | Iustin Pop | prop_JobId_serialisation :: JobId -> Property |
360 | c48711d5 | Iustin Pop | prop_JobId_serialisation jid = |
361 | 90634d95 | Iustin Pop | conjoin [ testSerialisation jid |
362 | 90634d95 | Iustin Pop | , (J.readJSON . J.showJSON . show $ fromJobId jid) ==? J.Ok jid |
363 | 90634d95 | Iustin Pop | , case (fromJVal . J.showJSON . negate $ |
364 | 90634d95 | Iustin Pop | fromJobId jid)::Result JobId of |
365 | 90634d95 | Iustin Pop | Bad _ -> passTest |
366 | 90634d95 | Iustin Pop | Ok jid' -> failTest $ "Parsed negative job id as id " ++ |
367 | 90634d95 | Iustin Pop | show (fromJobId jid') |
368 | 90634d95 | Iustin Pop | ] |
369 | 90634d95 | Iustin Pop | |
370 | 90634d95 | Iustin Pop | -- | Tests that fractional job IDs are not accepted. |
371 | 90634d95 | Iustin Pop | prop_JobId_fractional :: Property |
372 | 90634d95 | Iustin Pop | prop_JobId_fractional = |
373 | 90634d95 | Iustin Pop | forAll (arbitrary `suchThat` |
374 | 90634d95 | Iustin Pop | (\d -> fromIntegral (truncate d::Int) /= d)) $ \d -> |
375 | 90634d95 | Iustin Pop | case J.readJSON (J.showJSON (d::Double)) of |
376 | 90634d95 | Iustin Pop | J.Error _ -> passTest |
377 | 90634d95 | Iustin Pop | J.Ok jid -> failTest $ "Parsed fractional value " ++ show d ++ |
378 | 90634d95 | Iustin Pop | " as job id " ++ show (fromJobId jid) |
379 | 90634d95 | Iustin Pop | |
380 | 90634d95 | Iustin Pop | -- | Tests that a job ID is not parseable from \"bad\" JSON values. |
381 | 90634d95 | Iustin Pop | case_JobId_BadTypes :: Assertion |
382 | 90634d95 | Iustin Pop | case_JobId_BadTypes = do |
383 | 90634d95 | Iustin Pop | let helper jsval = case J.readJSON jsval of |
384 | 90634d95 | Iustin Pop | J.Error _ -> return () |
385 | 90634d95 | Iustin Pop | J.Ok jid -> assertFailure $ "Parsed " ++ show jsval |
386 | 90634d95 | Iustin Pop | ++ " as job id " ++ show (fromJobId jid) |
387 | 90634d95 | Iustin Pop | helper J.JSNull |
388 | 90634d95 | Iustin Pop | helper (J.JSBool True) |
389 | 90634d95 | Iustin Pop | helper (J.JSBool False) |
390 | 90634d95 | Iustin Pop | helper (J.JSArray []) |
391 | c48711d5 | Iustin Pop | |
392 | b46ba79c | Iustin Pop | -- | Test 'JobDependency' serialisation. |
393 | b46ba79c | Iustin Pop | prop_JobDependency_serialisation :: JobDependency -> Property |
394 | b46ba79c | Iustin Pop | prop_JobDependency_serialisation = testSerialisation |
395 | b46ba79c | Iustin Pop | |
396 | b46ba79c | Iustin Pop | -- | Test 'OpSubmitPriority' serialisation. |
397 | b46ba79c | Iustin Pop | prop_OpSubmitPriority_serialisation :: OpSubmitPriority -> Property |
398 | b46ba79c | Iustin Pop | prop_OpSubmitPriority_serialisation = testSerialisation |
399 | b46ba79c | Iustin Pop | |
400 | 37fe56e0 | Iustin Pop | -- | Tests string formatting for 'OpSubmitPriority'. |
401 | 37fe56e0 | Iustin Pop | prop_OpSubmitPriority_string :: OpSubmitPriority -> Property |
402 | 37fe56e0 | Iustin Pop | prop_OpSubmitPriority_string prio = |
403 | 37fe56e0 | Iustin Pop | parseSubmitPriority (fmtSubmitPriority prio) ==? Just prio |
404 | 37fe56e0 | Iustin Pop | |
405 | 5cd95d46 | Iustin Pop | -- | Test 'ELogType' serialisation. |
406 | 5cd95d46 | Iustin Pop | prop_ELogType_serialisation :: ELogType -> Property |
407 | 5cd95d46 | Iustin Pop | prop_ELogType_serialisation = testSerialisation |
408 | 5cd95d46 | Iustin Pop | |
409 | 5e9deac0 | Iustin Pop | testSuite "Types" |
410 | 5e9deac0 | Iustin Pop | [ 'prop_AllocPolicy_serialisation |
411 | bccb8d20 | Dato Simó | , 'case_AllocPolicy_order |
412 | 5e9deac0 | Iustin Pop | , 'prop_DiskTemplate_serialisation |
413 | 5e9deac0 | Iustin Pop | , 'prop_InstanceStatus_serialisation |
414 | edb5a1c8 | Iustin Pop | , 'prop_NonNeg_pass |
415 | edb5a1c8 | Iustin Pop | , 'prop_NonNeg_fail |
416 | edb5a1c8 | Iustin Pop | , 'prop_Positive_pass |
417 | edb5a1c8 | Iustin Pop | , 'prop_Positive_fail |
418 | c67b908a | Iustin Pop | , 'prop_Neg_pass |
419 | c67b908a | Iustin Pop | , 'prop_Neg_fail |
420 | edb5a1c8 | Iustin Pop | , 'prop_NonEmpty_pass |
421 | edb5a1c8 | Iustin Pop | , 'case_NonEmpty_fail |
422 | d696bbef | Iustin Pop | , 'prop_MigrationMode_serialisation |
423 | d696bbef | Iustin Pop | , 'prop_VerifyOptionalChecks_serialisation |
424 | d696bbef | Iustin Pop | , 'prop_DdmSimple_serialisation |
425 | c2d3219b | Iustin Pop | , 'prop_DdmFull_serialisation |
426 | d696bbef | Iustin Pop | , 'prop_CVErrorCode_serialisation |
427 | d696bbef | Iustin Pop | , 'case_CVErrorCode_pyequiv |
428 | 22381768 | Iustin Pop | , 'prop_Hypervisor_serialisation |
429 | 6a28e02c | Iustin Pop | , 'prop_OobCommand_serialisation |
430 | 48755fac | Iustin Pop | , 'prop_StorageType_serialisation |
431 | 6a28e02c | Iustin Pop | , 'prop_NodeEvacMode_serialisation |
432 | c65621d7 | Iustin Pop | , 'prop_FileDriver_serialisation |
433 | 6d558717 | Iustin Pop | , 'prop_InstCreateMode_serialisation |
434 | c2d3219b | Iustin Pop | , 'prop_RebootType_serialisation |
435 | 398e9066 | Iustin Pop | , 'prop_ExportMode_serialisation |
436 | a3f02317 | Iustin Pop | , 'prop_IAllocatorTestDir_serialisation |
437 | a3f02317 | Iustin Pop | , 'prop_IAllocatorMode_serialisation |
438 | a3f02317 | Iustin Pop | , 'case_IAllocatorMode_pyequiv |
439 | 497beee2 | Iustin Pop | , 'prop_NICMode_serialisation |
440 | 3bdbe4b3 | Dato Simó | , 'prop_OpStatus_serialization |
441 | 3bdbe4b3 | Dato Simó | , 'prop_JobStatus_serialization |
442 | bccb8d20 | Dato Simó | , 'case_JobStatus_order |
443 | 497beee2 | Iustin Pop | , 'case_NICMode_pyequiv |
444 | 6903fea0 | Iustin Pop | , 'prop_FinalizedJobStatus_serialisation |
445 | 6903fea0 | Iustin Pop | , 'case_FinalizedJobStatus_pyequiv |
446 | c48711d5 | Iustin Pop | , 'prop_JobId_serialisation |
447 | 90634d95 | Iustin Pop | , 'prop_JobId_fractional |
448 | 90634d95 | Iustin Pop | , 'case_JobId_BadTypes |
449 | b46ba79c | Iustin Pop | , 'prop_JobDependency_serialisation |
450 | b46ba79c | Iustin Pop | , 'prop_OpSubmitPriority_serialisation |
451 | 37fe56e0 | Iustin Pop | , 'prop_OpSubmitPriority_string |
452 | 5cd95d46 | Iustin Pop | , 'prop_ELogType_serialisation |
453 | 5e9deac0 | Iustin Pop | ] |