| 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 |
All rights reserved. |
| 12 |
|
| 13 |
Redistribution and use in source and binary forms, with or without |
| 14 |
modification, are permitted provided that the following conditions are |
| 15 |
met: |
| 16 |
|
| 17 |
1. Redistributions of source code must retain the above copyright notice, |
| 18 |
this list of conditions and the following disclaimer. |
| 19 |
|
| 20 |
2. Redistributions in binary form must reproduce the above copyright |
| 21 |
notice, this list of conditions and the following disclaimer in the |
| 22 |
documentation and/or other materials provided with the distribution. |
| 23 |
|
| 24 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 25 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 26 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 27 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 28 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 31 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 32 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 33 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 |
|
| 36 |
-} |
| 37 |
|
| 38 |
module Test.Ganeti.Ssconf (testSsconf) where |
| 39 |
|
| 40 |
import Test.QuickCheck |
| 41 |
import qualified Test.HUnit as HUnit |
| 42 |
|
| 43 |
import Data.List |
| 44 |
import qualified Data.Map as M |
| 45 |
|
| 46 |
import Test.Ganeti.TestHelper |
| 47 |
import Test.Ganeti.TestCommon |
| 48 |
|
| 49 |
import qualified Ganeti.Ssconf as Ssconf |
| 50 |
import qualified Ganeti.Types as Types |
| 51 |
|
| 52 |
-- * Ssconf tests |
| 53 |
|
| 54 |
$(genArbitrary ''Ssconf.SSKey) |
| 55 |
|
| 56 |
instance Arbitrary Ssconf.SSConf where |
| 57 |
arbitrary = fmap (Ssconf.SSConf . M.fromList) arbitrary |
| 58 |
|
| 59 |
-- * Reading SSConf |
| 60 |
|
| 61 |
prop_filename :: Ssconf.SSKey -> Property |
| 62 |
prop_filename key = |
| 63 |
counterexample "Key doesn't start with correct prefix" $ |
| 64 |
Ssconf.sSFilePrefix `isPrefixOf` Ssconf.keyToFilename "" key |
| 65 |
|
| 66 |
caseParseNodesVmCapable :: HUnit.Assertion |
| 67 |
caseParseNodesVmCapable = do |
| 68 |
let str = "node1.example.com=True\nnode2.example.com=False" |
| 69 |
result = Ssconf.parseNodesVmCapable str |
| 70 |
expected = return |
| 71 |
[ ("node1.example.com", True) |
| 72 |
, ("node2.example.com", False) |
| 73 |
] |
| 74 |
HUnit.assertEqual "Mismatch in parsed and expected result" expected result |
| 75 |
|
| 76 |
caseParseHypervisorList :: HUnit.Assertion |
| 77 |
caseParseHypervisorList = do |
| 78 |
let result = Ssconf.parseHypervisorList "kvm\nxen-pvm\nxen-hvm" |
| 79 |
expected = return [Types.Kvm, Types.XenPvm, Types.XenHvm] |
| 80 |
HUnit.assertEqual "Mismatch in parsed and expected result" expected result |
| 81 |
|
| 82 |
caseParseEnabledUserShutdown :: HUnit.Assertion |
| 83 |
caseParseEnabledUserShutdown = do |
| 84 |
let result1 = Ssconf.parseEnabledUserShutdown "True" |
| 85 |
result2 = Ssconf.parseEnabledUserShutdown "False" |
| 86 |
HUnit.assertEqual "Mismatch in parsed and expected result" |
| 87 |
(return True) result1 |
| 88 |
HUnit.assertEqual "Mismatch in parsed and expected result" |
| 89 |
(return False) result2 |
| 90 |
|
| 91 |
-- * Creating and writing SSConf |
| 92 |
|
| 93 |
-- | Verify that for SSConf we have readJSON . showJSON = Ok. |
| 94 |
prop_ReadShow :: Ssconf.SSConf -> Property |
| 95 |
prop_ReadShow = testSerialisation |
| 96 |
|
| 97 |
testSuite "Ssconf" |
| 98 |
[ 'prop_filename |
| 99 |
, 'caseParseNodesVmCapable |
| 100 |
, 'caseParseHypervisorList |
| 101 |
, 'caseParseEnabledUserShutdown |
| 102 |
, 'prop_ReadShow |
| 103 |
] |