Revision 63b068c1
b/htest/Test/Ganeti/HTools/Types.hs | ||
---|---|---|
41 | 41 |
import Test.QuickCheck |
42 | 42 |
|
43 | 43 |
import Control.Applicative |
44 |
import qualified Text.JSON as J |
|
45 | 44 |
|
46 | 45 |
import Test.Ganeti.TestHelper |
47 | 46 |
import Test.Ganeti.TestCommon |
... | ... | |
128 | 127 |
-- * Test cases |
129 | 128 |
|
130 | 129 |
prop_AllocPolicy_serialisation :: Types.AllocPolicy -> Property |
131 |
prop_AllocPolicy_serialisation apol = |
|
132 |
case J.readJSON (J.showJSON apol) of |
|
133 |
J.Ok p -> p ==? apol |
|
134 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
|
130 |
prop_AllocPolicy_serialisation = testSerialisation |
|
135 | 131 |
|
136 | 132 |
prop_DiskTemplate_serialisation :: Types.DiskTemplate -> Property |
137 |
prop_DiskTemplate_serialisation dt = |
|
138 |
case J.readJSON (J.showJSON dt) of |
|
139 |
J.Ok p -> p ==? dt |
|
140 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
|
133 |
prop_DiskTemplate_serialisation = testSerialisation |
|
141 | 134 |
|
142 | 135 |
prop_ISpec_serialisation :: Types.ISpec -> Property |
143 |
prop_ISpec_serialisation ispec = |
|
144 |
case J.readJSON (J.showJSON ispec) of |
|
145 |
J.Ok p -> p ==? ispec |
|
146 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
|
136 |
prop_ISpec_serialisation = testSerialisation |
|
147 | 137 |
|
148 | 138 |
prop_IPolicy_serialisation :: Types.IPolicy -> Property |
149 |
prop_IPolicy_serialisation ipol = |
|
150 |
case J.readJSON (J.showJSON ipol) of |
|
151 |
J.Ok p -> p ==? ipol |
|
152 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
|
139 |
prop_IPolicy_serialisation = testSerialisation |
|
153 | 140 |
|
154 | 141 |
prop_EvacMode_serialisation :: Types.EvacMode -> Property |
155 |
prop_EvacMode_serialisation em = |
|
156 |
case J.readJSON (J.showJSON em) of |
|
157 |
J.Ok p -> p ==? em |
|
158 |
J.Error s -> failTest $ "Failed to deserialise: " ++ s |
|
142 |
prop_EvacMode_serialisation = testSerialisation |
|
159 | 143 |
|
160 | 144 |
prop_opToResult :: Types.OpResult Int -> Bool |
161 | 145 |
prop_opToResult op = |
b/htest/Test/Ganeti/Jobs.hs | ||
---|---|---|
30 | 30 |
|
31 | 31 |
import Test.QuickCheck |
32 | 32 |
|
33 |
import qualified Text.JSON as J |
|
34 |
|
|
35 | 33 |
import Test.Ganeti.TestHelper |
36 | 34 |
import Test.Ganeti.TestCommon |
37 | 35 |
|
... | ... | |
49 | 47 |
|
50 | 48 |
-- | Check that (queued) job\/opcode status serialization is idempotent. |
51 | 49 |
prop_OpStatus_serialization :: Jobs.OpStatus -> Property |
52 |
prop_OpStatus_serialization os = |
|
53 |
case J.readJSON (J.showJSON os) of |
|
54 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
|
55 |
J.Ok os' -> os ==? os' |
|
50 |
prop_OpStatus_serialization = testSerialisation |
|
56 | 51 |
|
57 | 52 |
prop_JobStatus_serialization :: Jobs.JobStatus -> Property |
58 |
prop_JobStatus_serialization js = |
|
59 |
case J.readJSON (J.showJSON js) of |
|
60 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
|
61 |
J.Ok js' -> js ==? js' |
|
53 |
prop_JobStatus_serialization = testSerialisation |
|
62 | 54 |
|
63 | 55 |
testSuite "Jobs" |
64 | 56 |
[ 'prop_OpStatus_serialization |
b/htest/Test/Ganeti/Objects.hs | ||
---|---|---|
37 | 37 |
import Control.Applicative |
38 | 38 |
import qualified Data.Map as Map |
39 | 39 |
import qualified Data.Set as Set |
40 |
import qualified Text.JSON as J |
|
41 | 40 |
|
42 | 41 |
import Test.Ganeti.TestHelper |
43 | 42 |
import Test.Ganeti.TestCommon |
... | ... | |
106 | 105 |
-- testing entire Disk serialisations. So this tests two things at |
107 | 106 |
-- once, basically. |
108 | 107 |
prop_Disk_serialisation :: Disk -> Property |
109 |
prop_Disk_serialisation disk = |
|
110 |
J.readJSON (J.showJSON disk) ==? J.Ok disk |
|
108 |
prop_Disk_serialisation = testSerialisation |
|
111 | 109 |
|
112 | 110 |
-- | Check that node serialisation is idempotent. |
113 | 111 |
prop_Node_serialisation :: Node -> Property |
114 |
prop_Node_serialisation node = |
|
115 |
J.readJSON (J.showJSON node) ==? J.Ok node |
|
112 |
prop_Node_serialisation = testSerialisation |
|
116 | 113 |
|
117 | 114 |
testSuite "Objects" |
118 | 115 |
[ 'prop_fillDict |
b/htest/Test/Ganeti/OpCodes.hs | ||
---|---|---|
74 | 74 |
|
75 | 75 |
-- | Check that opcode serialization is idempotent. |
76 | 76 |
prop_serialization :: OpCodes.OpCode -> Property |
77 |
prop_serialization op = |
|
78 |
case J.readJSON (J.showJSON op) of |
|
79 |
J.Error e -> failTest $ "Cannot deserialise: " ++ e |
|
80 |
J.Ok op' -> op ==? op' |
|
77 |
prop_serialization = testSerialisation |
|
81 | 78 |
|
82 | 79 |
-- | Check that Python and Haskell defined the same opcode list. |
83 | 80 |
case_AllDefined :: HUnit.Assertion |
b/htest/Test/Ganeti/Query/Language.hs | ||
---|---|---|
34 | 34 |
import Test.QuickCheck |
35 | 35 |
|
36 | 36 |
import Control.Applicative |
37 |
import qualified Text.JSON as J |
|
38 | 37 |
|
39 | 38 |
import Test.Ganeti.TestHelper |
40 | 39 |
import Test.Ganeti.TestCommon |
... | ... | |
83 | 82 |
-- idempotent. |
84 | 83 |
prop_Serialisation :: Property |
85 | 84 |
prop_Serialisation = |
86 |
forAll genFilter $ \flt -> |
|
87 |
J.readJSON (J.showJSON flt) ==? J.Ok flt |
|
85 |
forAll genFilter testSerialisation |
|
88 | 86 |
|
89 | 87 |
prop_FilterRegex_instances :: Qlang.FilterRegex -> Property |
90 | 88 |
prop_FilterRegex_instances rex = |
91 |
printTestCase "failed JSON encoding" |
|
92 |
(J.readJSON (J.showJSON rex) ==? J.Ok rex) .&&. |
|
89 |
printTestCase "failed JSON encoding" (testSerialisation rex) .&&. |
|
93 | 90 |
printTestCase "failed read/show instances" (read (show rex) ==? rex) |
94 | 91 |
|
95 | 92 |
testSuite "Query/Language" |
b/htest/Test/Ganeti/TestCommon.hs | ||
---|---|---|
31 | 31 |
import Data.List |
32 | 32 |
import qualified Test.HUnit as HUnit |
33 | 33 |
import Test.QuickCheck |
34 |
import qualified Text.JSON as J |
|
34 | 35 |
import System.Environment (getEnv) |
35 | 36 |
import System.Exit (ExitCode(..)) |
36 | 37 |
import System.IO.Error (isDoesNotExistError) |
... | ... | |
187 | 188 |
arbitrary = do |
188 | 189 |
v <- choose (0, 1) |
189 | 190 |
return $ SmallRatio v |
191 |
|
|
192 |
-- | Checks for serialisation idempotence. |
|
193 |
testSerialisation :: (Eq a, Show a, J.JSON a) => a -> Property |
|
194 |
testSerialisation a = |
|
195 |
case J.readJSON (J.showJSON a) of |
|
196 |
J.Error msg -> failTest $ "Failed to deserialise: " ++ msg |
|
197 |
J.Ok a' -> a ==? a' |
Also available in: Unified diff