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