Skip to content
Snippets Groups Projects
Commit fef919b7 authored by Iustin Pop's avatar Iustin Pop
Browse files

Split and extend Confd types tests


Some confd types were not tested for serialisation, so let's move
these (type-related) tests to their own module and extend them.

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 62d5242b
No related branches found
No related tags found
No related merge requests found
......@@ -512,6 +512,7 @@ HS_TEST_SRCS = \
htest/Test/Ganeti/Block/Drbd/Parser.hs \
htest/Test/Ganeti/Block/Drbd/Types.hs \
htest/Test/Ganeti/Common.hs \
htest/Test/Ganeti/Confd/Types.hs \
htest/Test/Ganeti/Confd/Utils.hs \
htest/Test/Ganeti/Daemon.hs \
htest/Test/Ganeti/Errors.hs \
......
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-| Unittests for ganeti-htools.
-}
{-
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
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
{-# ANN module "HLint: ignore Use camelCase" #-}
-- * Arbitrary instances
$(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)
-- * Test cases
-- | Test 'ConfdQuery' serialisation.
prop_ConfdQuery_serialisation :: ConfdQuery -> Property
prop_ConfdQuery_serialisation = testSerialisation
-- | Test bad types deserialisation for 'ConfdQuery'.
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 []
-- | Test 'ConfdReplyStatus' serialisation.
prop_ConfdReplyStatus_serialisation :: ConfdReplyStatus -> Property
prop_ConfdReplyStatus_serialisation = testSerialisation
-- | Test 'ConfdReply' serialisation.
prop_ConfdReply_serialisation :: ConfdReply -> Property
prop_ConfdReply_serialisation = testSerialisation
-- | Test 'ConfdErrorType' serialisation.
prop_ConfdErrorType_serialisation :: ConfdErrorType -> Property
prop_ConfdErrorType_serialisation = testSerialisation
-- | Test 'ConfdNodeRole' serialisation.
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
]
......@@ -28,12 +28,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Test.Ganeti.Confd.Utils (testConfd_Utils) where
import Control.Applicative
import Test.QuickCheck
import qualified Text.JSON as J
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import Test.Ganeti.Confd.Types ()
import qualified Ganeti.BasicTypes as BasicTypes
import qualified Ganeti.Confd.Types as Confd
......@@ -41,20 +41,6 @@ import qualified Ganeti.Confd.Utils as Confd.Utils
import qualified Ganeti.Constants as C
import qualified Ganeti.Hash as Hash
$(genArbitrary ''Confd.ConfdRequestType)
$(genArbitrary ''Confd.ConfdReqField)
$(genArbitrary ''Confd.ConfdReqQ)
instance Arbitrary Confd.ConfdQuery where
arbitrary = oneof [ pure Confd.EmptyQuery
, Confd.PlainQuery <$> genName
, Confd.DictQuery <$> arbitrary
]
$(genArbitrary ''Confd.ConfdRequest)
-- | Test that signing messages and checking signatures is correct. It
-- also tests, indirectly the serialisation of messages so we don't
-- need a separate test for that.
......
......@@ -37,6 +37,7 @@ import Test.Ganeti.Block.Drbd.Parser
import Test.Ganeti.Block.Drbd.Types
import Test.Ganeti.Common
import Test.Ganeti.Confd.Utils
import Test.Ganeti.Confd.Types
import Test.Ganeti.Daemon
import Test.Ganeti.Errors
import Test.Ganeti.HTools.Backend.Simu
......@@ -83,6 +84,7 @@ allTests =
[ testBasicTypes
, testAttoparsec
, testCommon
, testConfd_Types
, testConfd_Utils
, testDaemon
, testBlock_Drbd_Parser
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment