module Test.Ganeti.Confd.Types
( testConfd_Types
, ConfdRequestType(..)
, ConfdReqField(..)
, ConfdReqQ(..)
) where
import Control.Applicative
import Test.QuickCheck
import Test.HUnit
import qualified Text.JSON as J
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import Ganeti.Confd.Types as Confd
$(genArbitrary ''ConfdRequestType)
$(genArbitrary ''ConfdReqField)
$(genArbitrary ''ConfdReqQ)
instance Arbitrary ConfdQuery where
arbitrary = oneof [ pure EmptyQuery
, PlainQuery <$> genName
, DictQuery <$> arbitrary
]
$(genArbitrary ''ConfdRequest)
$(genArbitrary ''ConfdReplyStatus)
instance Arbitrary ConfdReply where
arbitrary = ConfdReply <$> arbitrary <*> arbitrary <*>
pure J.JSNull <*> arbitrary
$(genArbitrary ''ConfdErrorType)
$(genArbitrary ''ConfdNodeRole)
prop_ConfdQuery_serialisation :: ConfdQuery -> Property
prop_ConfdQuery_serialisation = testSerialisation
case_ConfdQuery_BadTypes :: Assertion
case_ConfdQuery_BadTypes = do
let helper jsval = case J.readJSON jsval of
J.Error _ -> return ()
J.Ok cq -> assertFailure $ "Parsed " ++ show jsval
++ " as query " ++ show (cq::ConfdQuery)
helper $ J.showJSON (1::Int)
helper $ J.JSBool True
helper $ J.JSBool False
helper $ J.JSArray []
prop_ConfdReplyStatus_serialisation :: ConfdReplyStatus -> Property
prop_ConfdReplyStatus_serialisation = testSerialisation
prop_ConfdReply_serialisation :: ConfdReply -> Property
prop_ConfdReply_serialisation = testSerialisation
prop_ConfdErrorType_serialisation :: ConfdErrorType -> Property
prop_ConfdErrorType_serialisation = testSerialisation
prop_ConfdNodeRole_serialisation :: ConfdNodeRole -> Property
prop_ConfdNodeRole_serialisation = testSerialisation
testSuite "Confd/Types"
[ 'prop_ConfdQuery_serialisation
, 'case_ConfdQuery_BadTypes
, 'prop_ConfdReplyStatus_serialisation
, 'prop_ConfdReply_serialisation
, 'prop_ConfdErrorType_serialisation
, 'prop_ConfdNodeRole_serialisation
]