LGTM, thanks.
On Mon, Feb 3, 2014 at 8:56 PM, Klaus Aehlig <[email protected]> wrote: > So that objects using AndRestArguments are available for testing. > As the AndRestArguments are intended for passing through additional > parameters passed on the command line, we restrict them to the > values that are allowed at this position: Strings of ASCII characters > and Integers. > > Also, another property guaranteed by the specification is that the > keys in the map are different from all the other fields. To obtain > this property without adding additional complexity to the test > infrastructure, we choose a length for the keys that is longer than > all the valid fields. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > test/hs/Test/Ganeti/TestCommon.hs | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/test/hs/Test/Ganeti/TestCommon.hs > b/test/hs/Test/Ganeti/TestCommon.hs > index 239a3e8..e63e1aa 100644 > --- a/test/hs/Test/Ganeti/TestCommon.hs > +++ b/test/hs/Test/Ganeti/TestCommon.hs > @@ -51,6 +51,7 @@ module Test.Ganeti.TestCommon > , genSetHelper > , genSet > , genListSet > + , genAndRestArguments > , genIPv4Address > , genIPv4Network > , genIp6Addr > @@ -74,6 +75,7 @@ import Control.Exception (catchJust) > import Control.Monad > import Data.Attoparsec.Text (Parser, parseOnly) > import Data.List > +import qualified Data.Map as M > import Data.Text (pack) > import Data.Word > import qualified Data.Set as Set > @@ -293,6 +295,20 @@ genListSet :: (Ord a, Bounded a, Enum a) => Maybe Int > -> Gen (BasicTypes.ListSet a) > genListSet is = BasicTypes.ListSet <$> genSet is > > +-- | Generate an arbitrary element of and AndRestArguments field. > +genAndRestArguments :: Gen (M.Map String J.JSValue) > +genAndRestArguments = do > + n <- choose (0::Int, 10) > + let oneParam _ = do > + name <- choose (15 ::Int, 25) > + >>= flip vectorOf (elements tagChar) > + intvalue <- arbitrary > + value <- oneof [ J.JSString . J.toJSString <$> > genName > + , return $ J.showJSON (intvalue :: > Int) > + ] > + return (name, value) > + M.fromList `liftM` mapM oneParam [1..n] > + > -- | Generate an arbitrary IPv4 address in textual form. > genIPv4 :: Gen String > genIPv4 = do > -- > 1.9.0.rc1.175.g0b1dcb5 > >
