Statistics
| Branch: | Tag: | Revision:

root / test / hs / Test / Ganeti / Confd / Types.hs @ 83846468

History | View | Annotate | Download (3.2 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.Confd.Types
30
  ( testConfd_Types
31
  , ConfdRequestType(..)
32
  , ConfdReqField(..)
33
  , ConfdReqQ(..)
34
  ) where
35

    
36
import Control.Applicative
37
import Test.QuickCheck
38
import Test.HUnit
39
import qualified Text.JSON as J
40

    
41
import Test.Ganeti.TestHelper
42
import Test.Ganeti.TestCommon
43

    
44
import Ganeti.Confd.Types as Confd
45

    
46
{-# ANN module "HLint: ignore Use camelCase" #-}
47

    
48
-- * Arbitrary instances
49

    
50
$(genArbitrary ''ConfdRequestType)
51

    
52
$(genArbitrary ''ConfdReqField)
53

    
54
$(genArbitrary ''ConfdReqQ)
55

    
56
instance Arbitrary ConfdQuery where
57
  arbitrary = oneof [ pure EmptyQuery
58
                    , PlainQuery <$> genName
59
                    , DictQuery <$> arbitrary
60
                    ]
61

    
62
$(genArbitrary ''ConfdRequest)
63

    
64
$(genArbitrary ''ConfdReplyStatus)
65

    
66
instance Arbitrary ConfdReply where
67
  arbitrary = ConfdReply <$> arbitrary <*> arbitrary <*>
68
                pure J.JSNull <*> arbitrary
69

    
70
$(genArbitrary ''ConfdErrorType)
71

    
72
$(genArbitrary ''ConfdNodeRole)
73

    
74
-- * Test cases
75

    
76
-- | Test 'ConfdQuery' serialisation.
77
prop_ConfdQuery_serialisation :: ConfdQuery -> Property
78
prop_ConfdQuery_serialisation = testSerialisation
79

    
80
-- | Test bad types deserialisation for 'ConfdQuery'.
81
case_ConfdQuery_BadTypes :: Assertion
82
case_ConfdQuery_BadTypes = do
83
  let helper jsval = case J.readJSON jsval of
84
                       J.Error _ -> return ()
85
                       J.Ok cq -> assertFailure $ "Parsed " ++ show jsval
86
                                   ++ " as query " ++ show (cq::ConfdQuery)
87
  helper $ J.showJSON (1::Int)
88
  helper $ J.JSBool True
89
  helper $ J.JSBool False
90
  helper $ J.JSArray []
91

    
92

    
93
-- | Test 'ConfdReplyStatus' serialisation.
94
prop_ConfdReplyStatus_serialisation :: ConfdReplyStatus -> Property
95
prop_ConfdReplyStatus_serialisation = testSerialisation
96

    
97
-- | Test 'ConfdReply' serialisation.
98
prop_ConfdReply_serialisation :: ConfdReply -> Property
99
prop_ConfdReply_serialisation = testSerialisation
100

    
101
-- | Test 'ConfdErrorType' serialisation.
102
prop_ConfdErrorType_serialisation :: ConfdErrorType -> Property
103
prop_ConfdErrorType_serialisation = testSerialisation
104

    
105
-- | Test 'ConfdNodeRole' serialisation.
106
prop_ConfdNodeRole_serialisation :: ConfdNodeRole -> Property
107
prop_ConfdNodeRole_serialisation = testSerialisation
108

    
109
testSuite "Confd/Types"
110
  [ 'prop_ConfdQuery_serialisation
111
  , 'case_ConfdQuery_BadTypes
112
  , 'prop_ConfdReplyStatus_serialisation
113
  , 'prop_ConfdReply_serialisation
114
  , 'prop_ConfdErrorType_serialisation
115
  , 'prop_ConfdNodeRole_serialisation
116
  ]