Revision c09359ee test/hs/Test/Ganeti/HTools/Backend/Text.hs
b/test/hs/Test/Ganeti/HTools/Backend/Text.hs | ||
---|---|---|
38 | 38 |
import Test.Ganeti.TestHelper |
39 | 39 |
import Test.Ganeti.TestCommon |
40 | 40 |
import Test.Ganeti.TestHTools |
41 |
import Test.Ganeti.HTools.Instance (genInstanceSmallerThanNode) |
|
42 |
import Test.Ganeti.HTools.Node (genNode, genOnlineNode) |
|
41 |
import Test.Ganeti.HTools.Instance (genInstanceSmallerThanNode, |
|
42 |
genInstanceOnNodeList) |
|
43 |
import Test.Ganeti.HTools.Node (genNode, genOnlineNode, genUniqueNodeList) |
|
43 | 44 |
|
44 | 45 |
import Ganeti.BasicTypes |
45 | 46 |
import qualified Ganeti.HTools.Backend.Text as Text |
... | ... | |
97 | 98 |
|
98 | 99 |
prop_Load_InstanceFail :: [(String, Int)] -> [String] -> Property |
99 | 100 |
prop_Load_InstanceFail ktn fields = |
100 |
length fields /= 10 && length fields /= 11 ==>
|
|
101 |
length fields < 10 || length fields > 12 ==>
|
|
101 | 102 |
case Text.loadInst nl fields of |
102 | 103 |
Ok _ -> failTest "Managed to load instance from invalid data" |
103 | 104 |
Bad msg -> printTestCase ("Unrecognised error message: " ++ msg) $ |
104 | 105 |
"Invalid/incomplete instance data: '" `isPrefixOf` msg |
105 | 106 |
where nl = Map.fromList ktn |
106 | 107 |
|
108 |
genInstanceNodes :: Gen (Instance.Instance, Node.List, Types.NameAssoc) |
|
109 |
genInstanceNodes = do |
|
110 |
(nl, na) <- genUniqueNodeList genOnlineNode |
|
111 |
inst <- genInstanceOnNodeList nl |
|
112 |
return (inst, nl, na) |
|
113 |
|
|
114 |
prop_InstanceLSIdempotent :: Property |
|
115 |
prop_InstanceLSIdempotent = |
|
116 |
forAll genInstanceNodes $ \(inst, nl, assoc) -> |
|
117 |
(Text.loadInst assoc . Utils.sepSplit '|' . Text.serializeInstance nl) |
|
118 |
inst ==? Ok (Instance.name inst, inst) |
|
119 |
|
|
107 | 120 |
prop_Load_Node :: String -> Int -> Int -> Int -> Int -> Int |
108 | 121 |
-> Int -> Bool -> Bool |
109 | 122 |
prop_Load_Node name tm nm fm td fd tc fo = |
... | ... | |
213 | 226 |
testSuite "HTools/Backend/Text" |
214 | 227 |
[ 'prop_Load_Instance |
215 | 228 |
, 'prop_Load_InstanceFail |
229 |
, 'prop_InstanceLSIdempotent |
|
216 | 230 |
, 'prop_Load_Node |
217 | 231 |
, 'prop_Load_NodeFail |
218 | 232 |
, 'prop_NodeLSIdempotent |
Also available in: Unified diff