module Test.Ganeti.Ssconf (testSsconf) where
import Test.QuickCheck
import qualified Test.HUnit as HUnit
import Data.List
import qualified Data.Map as M
import Test.Ganeti.TestHelper
import Test.Ganeti.TestCommon
import qualified Ganeti.Ssconf as Ssconf
import qualified Ganeti.Types as Types
$(genArbitrary ''Ssconf.SSKey)
instance Arbitrary Ssconf.SSConf where
arbitrary = fmap (Ssconf.SSConf . M.fromList) arbitrary
prop_filename :: Ssconf.SSKey -> Property
prop_filename key =
counterexample "Key doesn't start with correct prefix" $
Ssconf.sSFilePrefix `isPrefixOf` Ssconf.keyToFilename "" key
caseParseNodesVmCapable :: HUnit.Assertion
caseParseNodesVmCapable = do
let str = "node1.example.com=True\nnode2.example.com=False"
result = Ssconf.parseNodesVmCapable str
expected = return
[ ("node1.example.com", True)
, ("node2.example.com", False)
]
HUnit.assertEqual "Mismatch in parsed and expected result" expected result
caseParseHypervisorList :: HUnit.Assertion
caseParseHypervisorList = do
let result = Ssconf.parseHypervisorList "kvm\nxen-pvm\nxen-hvm"
expected = return [Types.Kvm, Types.XenPvm, Types.XenHvm]
HUnit.assertEqual "Mismatch in parsed and expected result" expected result
caseParseEnabledUserShutdown :: HUnit.Assertion
caseParseEnabledUserShutdown = do
let result1 = Ssconf.parseEnabledUserShutdown "True"
result2 = Ssconf.parseEnabledUserShutdown "False"
HUnit.assertEqual "Mismatch in parsed and expected result"
(return True) result1
HUnit.assertEqual "Mismatch in parsed and expected result"
(return False) result2
prop_ReadShow :: Ssconf.SSConf -> Property
prop_ReadShow = testSerialisation
testSuite "Ssconf"
[ 'prop_filename
, 'caseParseNodesVmCapable
, 'caseParseHypervisorList
, 'caseParseEnabledUserShutdown
, 'prop_ReadShow
]