root / htest / Test / Ganeti / Jobs.hs @ b88fcdd0
History | View | Annotate | Download (1.9 kB)
1 |
{-# LANGUAGE TemplateHaskell #-} |
---|---|
2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
3 |
|
4 |
{-| Unittests for ganeti-htools. |
5 |
|
6 |
-} |
7 |
|
8 |
{- |
9 |
|
10 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc. |
11 |
|
12 |
This program is free software; you can redistribute it and/or modify |
13 |
it under the terms of the GNU General Public License as published by |
14 |
the Free Software Foundation; either version 2 of the License, or |
15 |
(at your option) any later version. |
16 |
|
17 |
This program is distributed in the hope that it will be useful, but |
18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 |
General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU General Public License |
23 |
along with this program; if not, write to the Free Software |
24 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25 |
02110-1301, USA. |
26 |
|
27 |
-} |
28 |
|
29 |
module Test.Ganeti.Jobs (testJobs) where |
30 |
|
31 |
import Test.QuickCheck |
32 |
|
33 |
import qualified Text.JSON as J |
34 |
|
35 |
import Test.Ganeti.TestHelper |
36 |
import Test.Ganeti.TestCommon |
37 |
|
38 |
import qualified Ganeti.Jobs as Jobs |
39 |
|
40 |
-- * Arbitrary instances |
41 |
|
42 |
instance Arbitrary Jobs.OpStatus where |
43 |
arbitrary = elements [minBound..maxBound] |
44 |
|
45 |
instance Arbitrary Jobs.JobStatus where |
46 |
arbitrary = elements [minBound..maxBound] |
47 |
|
48 |
-- * Test cases |
49 |
|
50 |
-- | Check that (queued) job\/opcode status serialization is idempotent. |
51 |
prop_Jobs_OpStatus_serialization :: Jobs.OpStatus -> Property |
52 |
prop_Jobs_OpStatus_serialization os = |
53 |
case J.readJSON (J.showJSON os) of |
54 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
55 |
J.Ok os' -> os ==? os' |
56 |
|
57 |
prop_Jobs_JobStatus_serialization :: Jobs.JobStatus -> Property |
58 |
prop_Jobs_JobStatus_serialization js = |
59 |
case J.readJSON (J.showJSON js) of |
60 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
61 |
J.Ok js' -> js ==? js' |
62 |
|
63 |
testSuite "Jobs" |
64 |
[ 'prop_Jobs_OpStatus_serialization |
65 |
, 'prop_Jobs_JobStatus_serialization |
66 |
] |