Commit 88f25dd0 authored by Iustin Pop's avatar Iustin Pop
Browse files

Introduce OpCode unittests

parent f36a8028
......@@ -29,14 +29,18 @@ module Ganeti.HTools.QC
, testInstance
, testNode
, testText
, testOpCodes
, testCluster
) where
import Test.QuickCheck
import Test.QuickCheck.Batch
import Data.Maybe
import Control.Monad
import qualified Text.JSON as J
import qualified Data.Map
import qualified Data.IntMap as IntMap
import qualified Ganeti.OpCodes as OpCodes
import qualified Ganeti.HTools.CLI as CLI
import qualified Ganeti.HTools.Cluster as Cluster
import qualified Ganeti.HTools.Container as Container
......@@ -140,6 +144,33 @@ instance Arbitrary Node.Node where
n' = Node.buildPeers n Container.empty
return n'
-- replace disks
instance Arbitrary OpCodes.ReplaceDisksMode where
arbitrary = elements [ OpCodes.ReplaceOnPrimary
, OpCodes.ReplaceOnSecondary
, OpCodes.ReplaceNewSecondary
, OpCodes.ReplaceAuto
]
instance Arbitrary OpCodes.OpCode where
arbitrary = do
op_id <- elements [ "OP_TEST_DELAY"
, "OP_INSTANCE_REPLACE_DISKS"
, "OP_INSTANCE_FAILOVER"
, "OP_INSTANCE_MIGRATE"
]
(case op_id of
"OP_TEST_DELAY" ->
liftM3 OpCodes.OpTestDelay arbitrary arbitrary arbitrary
"OP_INSTANCE_REPLACE_DISKS" ->
liftM5 OpCodes.OpReplaceDisks arbitrary arbitrary
arbitrary arbitrary arbitrary
"OP_INSTANCE_FAILOVER" ->
liftM2 OpCodes.OpFailoverInstance arbitrary arbitrary
"OP_INSTANCE_MIGRATE" ->
liftM3 OpCodes.OpMigrateInstance arbitrary arbitrary arbitrary
_ -> fail "Wrong opcode")
-- * Actual tests
-- | Make sure add is idempotent
......@@ -619,3 +650,15 @@ testCluster =
, run prop_ClusterAllocEvac
, run prop_ClusterAllocBalance
]
-- | Check that opcode serialization is idempotent
prop_OpCodes_serialization op =
case J.readJSON (J.showJSON op) of
J.Error _ -> False
J.Ok op' -> op == op'
where _types = (op::OpCodes.OpCode)
testOpCodes =
[ run prop_OpCodes_serialization
]
......@@ -40,7 +40,7 @@ data ReplaceDisksMode = ReplaceOnPrimary
| ReplaceOnSecondary
| ReplaceNewSecondary
| ReplaceAuto
deriving Show
deriving (Show, Eq)
instance JSON ReplaceDisksMode where
showJSON m = case m of
......@@ -60,7 +60,7 @@ data OpCode = OpTestDelay Double Bool [String]
[Int] (Maybe String)
| OpFailoverInstance String Bool
| OpMigrateInstance String Bool Bool
deriving Show
deriving (Show, Eq)
opID :: OpCode -> String
......
......@@ -68,6 +68,7 @@ main = do
runTests "Instance" fastOptions $ wrap testInstance
runTests "Node" fastOptions $ wrap testNode
runTests "Text" fastOptions $ wrap testText
runTests "OpCodes" fastOptions $ wrap testOpCodes
runTests "Cluster" slowOptions $ wrap testCluster
terr <- readIORef errs
(if terr > 0
......
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