Revision 8b5a517a
b/htools/Ganeti/HTools/CLI.hs | ||
---|---|---|
8 | 8 |
|
9 | 9 |
{- |
10 | 10 |
|
11 |
Copyright (C) 2009, 2010, 2011 Google Inc. |
|
11 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
|
|
12 | 12 |
|
13 | 13 |
This program is free software; you can redistribute it and/or modify |
14 | 14 |
it under the terms of the GNU General Public License as published by |
... | ... | |
31 | 31 |
( Options(..) |
32 | 32 |
, OptType |
33 | 33 |
, parseOpts |
34 |
, parseISpecString |
|
34 | 35 |
, shTemplate |
35 | 36 |
, defaultLuxiSocket |
36 | 37 |
, maybePrintNodes |
... | ... | |
187 | 188 |
parseISpecString :: String -> String -> Result RSpec |
188 | 189 |
parseISpecString descr inp = do |
189 | 190 |
let sp = sepSplit ',' inp |
191 |
err = Bad ("Invalid " ++ descr ++ " specification: '" ++ inp ++ |
|
192 |
"', expected disk,ram,cpu") |
|
193 |
when (length sp /= 3) err |
|
190 | 194 |
prs <- mapM (\(fn, val) -> fn val) $ |
191 |
zip [ annotateResult (descr ++ " specs memory") . parseUnit
|
|
192 |
, annotateResult (descr ++ " specs disk") . parseUnit
|
|
195 |
zip [ annotateResult (descr ++ " specs disk") . parseUnit
|
|
196 |
, annotateResult (descr ++ " specs memory") . parseUnit
|
|
193 | 197 |
, tryRead (descr ++ " specs cpus") |
194 | 198 |
] sp |
195 | 199 |
case prs of |
196 | 200 |
[dsk, ram, cpu] -> return $ RSpec cpu ram dsk |
197 |
_ -> Bad $ "Invalid " ++ descr ++ " specification: '" ++ inp ++ |
|
198 |
"', expected disk,ram,cpu" |
|
201 |
_ -> err |
|
199 | 202 |
|
200 | 203 |
-- * Command line options |
201 | 204 |
|
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
38 | 38 |
, testCluster |
39 | 39 |
, testLoader |
40 | 40 |
, testTypes |
41 |
, testCLI |
|
41 | 42 |
) where |
42 | 43 |
|
43 | 44 |
import Test.QuickCheck |
... | ... | |
1460 | 1461 |
, 'prop_Types_opToResult |
1461 | 1462 |
, 'prop_Types_eitherToResult |
1462 | 1463 |
] |
1464 |
|
|
1465 |
-- ** CLI tests |
|
1466 |
|
|
1467 |
-- | Test correct parsing. |
|
1468 |
prop_CLI_parseISpec descr dsk mem cpu = |
|
1469 |
let str = printf "%d,%d,%d" dsk mem cpu |
|
1470 |
in CLI.parseISpecString descr str ==? Types.Ok (Types.RSpec cpu mem dsk) |
|
1471 |
|
|
1472 |
-- | Test parsing failure due to wrong section count. |
|
1473 |
prop_CLI_parseISpecFail descr = |
|
1474 |
forAll (choose (0,100) `suchThat` ((/=) 3)) $ \nelems -> |
|
1475 |
forAll (replicateM nelems arbitrary) $ \values -> |
|
1476 |
let str = intercalate "," $ map show (values::[Int]) |
|
1477 |
in case CLI.parseISpecString descr str of |
|
1478 |
Types.Ok v -> failTest $ "Expected failure, got " ++ show v |
|
1479 |
_ -> property True |
|
1480 |
|
|
1481 |
testSuite "CLI" |
|
1482 |
[ 'prop_CLI_parseISpec |
|
1483 |
, 'prop_CLI_parseISpecFail |
|
1484 |
] |
b/htools/test.hs | ||
---|---|---|
120 | 120 |
, (fast, testJobs) |
121 | 121 |
, (fast, testLoader) |
122 | 122 |
, (fast, testTypes) |
123 |
, (fast, testCLI) |
|
123 | 124 |
, (slow, testCluster) |
124 | 125 |
] |
125 | 126 |
|
Also available in: Unified diff