diff --git a/Makefile.am b/Makefile.am index 601da2b8361483e7a5a09601d03e50643caef85a..49dd1e0f00ed768a6c3f9a421c13f41a8f5bad5b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/htest/Test/Ganeti/Confd/Types.hs b/htest/Test/Ganeti/Confd/Types.hs new file mode 100644 index 0000000000000000000000000000000000000000..0c5b40cea39d377bf47fff15ce91e1e2c0e5c586 --- /dev/null +++ b/htest/Test/Ganeti/Confd/Types.hs @@ -0,0 +1,116 @@ +{-# 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 + ] diff --git a/htest/Test/Ganeti/Confd/Utils.hs b/htest/Test/Ganeti/Confd/Utils.hs index 81818a6e23cee99180038cac4b91a9db8aa1e5a7..128a78ed28072b3fa1346f68a62cf39db19ce4ee 100644 --- a/htest/Test/Ganeti/Confd/Utils.hs +++ b/htest/Test/Ganeti/Confd/Utils.hs @@ -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. diff --git a/htest/test.hs b/htest/test.hs index 8d71c247cc8a86e009595cdae33398ae4af5e1db..3bb1294c6ef0f0337c8cf3b2f3cb079c6fe6ca76 100644 --- a/htest/test.hs +++ b/htest/test.hs @@ -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