Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-ganeti
Commits
88f25dd0
Commit
88f25dd0
authored
May 27, 2010
by
Iustin Pop
Browse files
Introduce OpCode unittests
parent
f36a8028
Changes
3
Hide whitespace changes
Inline
Side-by-side
Ganeti/HTools/QC.hs
View file @
88f25dd0
...
@@ -29,14 +29,18 @@ module Ganeti.HTools.QC
...
@@ -29,14 +29,18 @@ module Ganeti.HTools.QC
,
testInstance
,
testInstance
,
testNode
,
testNode
,
testText
,
testText
,
testOpCodes
,
testCluster
,
testCluster
)
where
)
where
import
Test.QuickCheck
import
Test.QuickCheck
import
Test.QuickCheck.Batch
import
Test.QuickCheck.Batch
import
Data.Maybe
import
Data.Maybe
import
Control.Monad
import
qualified
Text.JSON
as
J
import
qualified
Data.Map
import
qualified
Data.Map
import
qualified
Data.IntMap
as
IntMap
import
qualified
Data.IntMap
as
IntMap
import
qualified
Ganeti.OpCodes
as
OpCodes
import
qualified
Ganeti.HTools.CLI
as
CLI
import
qualified
Ganeti.HTools.CLI
as
CLI
import
qualified
Ganeti.HTools.Cluster
as
Cluster
import
qualified
Ganeti.HTools.Cluster
as
Cluster
import
qualified
Ganeti.HTools.Container
as
Container
import
qualified
Ganeti.HTools.Container
as
Container
...
@@ -140,6 +144,33 @@ instance Arbitrary Node.Node where
...
@@ -140,6 +144,33 @@ instance Arbitrary Node.Node where
n'
=
Node
.
buildPeers
n
Container
.
empty
n'
=
Node
.
buildPeers
n
Container
.
empty
return
n'
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
-- * Actual tests
-- | Make sure add is idempotent
-- | Make sure add is idempotent
...
@@ -619,3 +650,15 @@ testCluster =
...
@@ -619,3 +650,15 @@ testCluster =
,
run
prop_ClusterAllocEvac
,
run
prop_ClusterAllocEvac
,
run
prop_ClusterAllocBalance
,
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
]
Ganeti/OpCodes.hs
View file @
88f25dd0
...
@@ -40,7 +40,7 @@ data ReplaceDisksMode = ReplaceOnPrimary
...
@@ -40,7 +40,7 @@ data ReplaceDisksMode = ReplaceOnPrimary
|
ReplaceOnSecondary
|
ReplaceOnSecondary
|
ReplaceNewSecondary
|
ReplaceNewSecondary
|
ReplaceAuto
|
ReplaceAuto
deriving
Show
deriving
(
Show
,
Eq
)
instance
JSON
ReplaceDisksMode
where
instance
JSON
ReplaceDisksMode
where
showJSON
m
=
case
m
of
showJSON
m
=
case
m
of
...
@@ -60,7 +60,7 @@ data OpCode = OpTestDelay Double Bool [String]
...
@@ -60,7 +60,7 @@ data OpCode = OpTestDelay Double Bool [String]
[
Int
]
(
Maybe
String
)
[
Int
]
(
Maybe
String
)
|
OpFailoverInstance
String
Bool
|
OpFailoverInstance
String
Bool
|
OpMigrateInstance
String
Bool
Bool
|
OpMigrateInstance
String
Bool
Bool
deriving
Show
deriving
(
Show
,
Eq
)
opID
::
OpCode
->
String
opID
::
OpCode
->
String
...
...
test.hs
View file @
88f25dd0
...
@@ -68,6 +68,7 @@ main = do
...
@@ -68,6 +68,7 @@ main = do
runTests
"Instance"
fastOptions
$
wrap
testInstance
runTests
"Instance"
fastOptions
$
wrap
testInstance
runTests
"Node"
fastOptions
$
wrap
testNode
runTests
"Node"
fastOptions
$
wrap
testNode
runTests
"Text"
fastOptions
$
wrap
testText
runTests
"Text"
fastOptions
$
wrap
testText
runTests
"OpCodes"
fastOptions
$
wrap
testOpCodes
runTests
"Cluster"
slowOptions
$
wrap
testCluster
runTests
"Cluster"
slowOptions
$
wrap
testCluster
terr
<-
readIORef
errs
terr
<-
readIORef
errs
(
if
terr
>
0
(
if
terr
>
0
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment