Revision 20bc5360 htest/Test/Ganeti/HTools/Text.hs
b/htest/Test/Ganeti/HTools/Text.hs | ||
---|---|---|
52 | 52 |
|
53 | 53 |
-- * Instance text loader tests |
54 | 54 |
|
55 |
prop_Text_Load_Instance :: String -> Int -> Int -> Int -> Types.InstanceStatus
|
|
56 |
-> NonEmptyList Char -> [Char]
|
|
57 |
-> NonNegative Int -> NonNegative Int -> Bool
|
|
58 |
-> Types.DiskTemplate -> Int -> Property
|
|
59 |
prop_Text_Load_Instance name mem dsk vcpus status
|
|
60 |
(NonEmpty pnode) snode
|
|
61 |
(NonNegative pdx) (NonNegative sdx) autobal dt su =
|
|
55 |
prop_Load_Instance :: String -> Int -> Int -> Int -> Types.InstanceStatus |
|
56 |
-> NonEmptyList Char -> [Char] |
|
57 |
-> NonNegative Int -> NonNegative Int -> Bool |
|
58 |
-> Types.DiskTemplate -> Int -> Property |
|
59 |
prop_Load_Instance name mem dsk vcpus status |
|
60 |
(NonEmpty pnode) snode |
|
61 |
(NonNegative pdx) (NonNegative sdx) autobal dt su = |
|
62 | 62 |
pnode /= snode && pdx /= sdx ==> |
63 | 63 |
let vcpus_s = show vcpus |
64 | 64 |
dsk_s = show dsk |
... | ... | |
93 | 93 |
Instance.spindleUse i == su && |
94 | 94 |
Types.isBad fail1 |
95 | 95 |
|
96 |
prop_Text_Load_InstanceFail :: [(String, Int)] -> [String] -> Property
|
|
97 |
prop_Text_Load_InstanceFail ktn fields =
|
|
96 |
prop_Load_InstanceFail :: [(String, Int)] -> [String] -> Property |
|
97 |
prop_Load_InstanceFail ktn fields = |
|
98 | 98 |
length fields /= 10 && length fields /= 11 ==> |
99 | 99 |
case Text.loadInst nl fields of |
100 | 100 |
Types.Ok _ -> failTest "Managed to load instance from invalid data" |
... | ... | |
102 | 102 |
"Invalid/incomplete instance data: '" `isPrefixOf` msg |
103 | 103 |
where nl = Map.fromList ktn |
104 | 104 |
|
105 |
prop_Text_Load_Node :: String -> Int -> Int -> Int -> Int -> Int
|
|
106 |
-> Int -> Bool -> Bool
|
|
107 |
prop_Text_Load_Node name tm nm fm td fd tc fo =
|
|
105 |
prop_Load_Node :: String -> Int -> Int -> Int -> Int -> Int |
|
106 |
-> Int -> Bool -> Bool |
|
107 |
prop_Load_Node name tm nm fm td fd tc fo = |
|
108 | 108 |
let conv v = if v < 0 |
109 | 109 |
then "?" |
110 | 110 |
else show v |
... | ... | |
134 | 134 |
Node.fDsk node == fd && |
135 | 135 |
Node.tCpu node == fromIntegral tc |
136 | 136 |
|
137 |
prop_Text_Load_NodeFail :: [String] -> Property
|
|
138 |
prop_Text_Load_NodeFail fields =
|
|
137 |
prop_Load_NodeFail :: [String] -> Property |
|
138 |
prop_Load_NodeFail fields = |
|
139 | 139 |
length fields /= 8 ==> isNothing $ Text.loadNode Map.empty fields |
140 | 140 |
|
141 |
prop_Text_NodeLSIdempotent :: Property
|
|
142 |
prop_Text_NodeLSIdempotent =
|
|
141 |
prop_NodeLSIdempotent :: Property |
|
142 |
prop_NodeLSIdempotent = |
|
143 | 143 |
forAll (genNode (Just 1) Nothing) $ \node -> |
144 | 144 |
-- override failN1 to what loadNode returns by default |
145 | 145 |
let n = Node.setPolicy Types.defIPolicy $ |
... | ... | |
149 | 149 |
Utils.sepSplit '|' . Text.serializeNode defGroupList) n ==? |
150 | 150 |
Just (Node.name n, n) |
151 | 151 |
|
152 |
prop_Text_ISpecIdempotent :: Types.ISpec -> Property
|
|
153 |
prop_Text_ISpecIdempotent ispec =
|
|
152 |
prop_ISpecIdempotent :: Types.ISpec -> Property |
|
153 |
prop_ISpecIdempotent ispec = |
|
154 | 154 |
case Text.loadISpec "dummy" . Utils.sepSplit ',' . |
155 | 155 |
Text.serializeISpec $ ispec of |
156 | 156 |
Types.Bad msg -> failTest $ "Failed to load ispec: " ++ msg |
157 | 157 |
Types.Ok ispec' -> ispec ==? ispec' |
158 | 158 |
|
159 |
prop_Text_IPolicyIdempotent :: Types.IPolicy -> Property
|
|
160 |
prop_Text_IPolicyIdempotent ipol =
|
|
159 |
prop_IPolicyIdempotent :: Types.IPolicy -> Property |
|
160 |
prop_IPolicyIdempotent ipol = |
|
161 | 161 |
case Text.loadIPolicy . Utils.sepSplit '|' $ |
162 | 162 |
Text.serializeIPolicy owner ipol of |
163 | 163 |
Types.Bad msg -> failTest $ "Failed to load ispec: " ++ msg |
... | ... | |
171 | 171 |
-- allocations, not for the business logic). As such, it's a quite |
172 | 172 |
-- complex and slow test, and that's the reason we restrict it to |
173 | 173 |
-- small cluster sizes. |
174 |
prop_Text_CreateSerialise :: Property
|
|
175 |
prop_Text_CreateSerialise =
|
|
174 |
prop_CreateSerialise :: Property |
|
175 |
prop_CreateSerialise = |
|
176 | 176 |
forAll genTags $ \ctags -> |
177 | 177 |
forAll (choose (1, 20)) $ \maxiter -> |
178 | 178 |
forAll (choose (2, 10)) $ \count -> |
... | ... | |
200 | 200 |
nl' ==? nl2 |
201 | 201 |
|
202 | 202 |
testSuite "Text" |
203 |
[ 'prop_Text_Load_Instance
|
|
204 |
, 'prop_Text_Load_InstanceFail
|
|
205 |
, 'prop_Text_Load_Node
|
|
206 |
, 'prop_Text_Load_NodeFail
|
|
207 |
, 'prop_Text_NodeLSIdempotent
|
|
208 |
, 'prop_Text_ISpecIdempotent
|
|
209 |
, 'prop_Text_IPolicyIdempotent
|
|
210 |
, 'prop_Text_CreateSerialise
|
|
203 |
[ 'prop_Load_Instance |
|
204 |
, 'prop_Load_InstanceFail |
|
205 |
, 'prop_Load_Node |
|
206 |
, 'prop_Load_NodeFail |
|
207 |
, 'prop_NodeLSIdempotent |
|
208 |
, 'prop_ISpecIdempotent |
|
209 |
, 'prop_IPolicyIdempotent |
|
210 |
, 'prop_CreateSerialise |
|
211 | 211 |
] |
Also available in: Unified diff