Commit e8127e66 authored by Petr Pudlak's avatar Petr Pudlak

Add basic serialization tests for TempRes's data types

In particular, test serialization of IPv4Reservation, which is used
on the Python part as well.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarKlaus Aehlig <aehlig@google.com>
parent eb84f8ae
......@@ -160,7 +160,8 @@ HS_DIRS = \
test/hs/Test/Ganeti/Objects \
test/hs/Test/Ganeti/Query \
test/hs/Test/Ganeti/THH \
test/hs/Test/Ganeti/Utils
test/hs/Test/Ganeti/Utils \
test/hs/Test/Ganeti/WConfd
# Haskell directories without the roots (src, test/hs)
HS_DIRS_NOROOT = $(filter-out src,$(filter-out test/hs,$(HS_DIRS)))
......@@ -944,7 +945,7 @@ HS_TEST_SRCS = \
test/hs/Test/Ganeti/Types.hs \
test/hs/Test/Ganeti/Utils.hs \
test/hs/Test/Ganeti/Utils/MultiMap.hs \
test/hs/Test/Ganeti/Utils/Statistics.hs
test/hs/Test/Ganeti/WConfd/TempRes.hs
HS_LIBTEST_SRCS = $(HS_LIB_SRCS) $(HS_TEST_SRCS)
......
......@@ -29,7 +29,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-}
module Ganeti.WConfd.TempRes
( TempResState(..)
( TempRes
, mkTempRes
, TempResState(..)
, emptyTempResState
, NodeUUID
, InstanceUUID
......@@ -152,6 +154,10 @@ instance (J.JSON j, Ord j, J.JSON a, Ord a) => J.JSON (TempRes j a) where
showJSON = J.showJSON . getTempRes
readJSON = liftM TempRes . J.readJSON
-- | Create a temporary reservations from a given multi-map.
mkTempRes :: MM.MultiMap j a -> TempRes j a
mkTempRes = TempRes
-- | The state of the temporary reservations
$(buildObject "TempResState" "trs"
[ simpleField "dRBD" [t| DRBDMap |]
......
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-| Tests for temporary configuration resources allocation
-}
{-
Copyright (C) 2014 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.WConfd.TempRes (testWConfd_TempRes) where
import Control.Applicative
import Test.QuickCheck
import Test.Ganeti.Objects ()
import Test.Ganeti.TestCommon
import Test.Ganeti.TestHelper
import Test.Ganeti.Locking.Locks () -- the JSON ClientId instance
import Test.Ganeti.Utils.MultiMap ()
import Ganeti.WConfd.TempRes
-- * Instances
instance Arbitrary IPv4ResAction where
arbitrary = elements [minBound..maxBound]
instance Arbitrary IPv4Reservation where
arbitrary = IPv4Res <$> arbitrary <*> arbitrary <*> arbitrary
instance (Arbitrary k, Ord k, Arbitrary v, Ord v)
=> Arbitrary (TempRes k v) where
arbitrary = mkTempRes <$> arbitrary
instance Arbitrary TempResState where
arbitrary = TempResState <$> genMap arbitrary (genMap arbitrary arbitrary)
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
-- * Tests
prop_IPv4Reservation_serialisation :: IPv4Reservation -> Property
prop_IPv4Reservation_serialisation = testSerialisation
prop_TempRes_serialisation :: TempRes Int Int -> Property
prop_TempRes_serialisation = testSerialisation
-- * The tests combined
testSuite "WConfd/TempRes"
[ 'prop_IPv4Reservation_serialisation
, 'prop_TempRes_serialisation
]
......@@ -83,6 +83,7 @@ import Test.Ganeti.Types
import Test.Ganeti.Utils
import Test.Ganeti.Utils.MultiMap
import Test.Ganeti.Utils.Statistics
import Test.Ganeti.WConfd.TempRes
-- | Our default test options, overring the built-in test-framework
-- ones (but not the supplied command line parameters).
......@@ -151,6 +152,7 @@ allTests =
, testUtils
, testUtils_MultiMap
, testUtils_Statistics
, testWConfd_TempRes
]
-- | Main function. Note we don't use defaultMain since we want to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment