Commit db9583f2 authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add genAndRestArguments :: Gen (Map String JSValue)



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: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent c2442429
...@@ -51,6 +51,7 @@ module Test.Ganeti.TestCommon ...@@ -51,6 +51,7 @@ module Test.Ganeti.TestCommon
, genSetHelper , genSetHelper
, genSet , genSet
, genListSet , genListSet
, genAndRestArguments
, genIPv4Address , genIPv4Address
, genIPv4Network , genIPv4Network
, genIp6Addr , genIp6Addr
...@@ -74,6 +75,7 @@ import Control.Exception (catchJust) ...@@ -74,6 +75,7 @@ import Control.Exception (catchJust)
import Control.Monad import Control.Monad
import Data.Attoparsec.Text (Parser, parseOnly) import Data.Attoparsec.Text (Parser, parseOnly)
import Data.List import Data.List
import qualified Data.Map as M
import Data.Text (pack) import Data.Text (pack)
import Data.Word import Data.Word
import qualified Data.Set as Set import qualified Data.Set as Set
...@@ -293,6 +295,20 @@ genListSet :: (Ord a, Bounded a, Enum a) => Maybe Int ...@@ -293,6 +295,20 @@ genListSet :: (Ord a, Bounded a, Enum a) => Maybe Int
-> Gen (BasicTypes.ListSet a) -> Gen (BasicTypes.ListSet a)
genListSet is = BasicTypes.ListSet <$> genSet is 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. -- | Generate an arbitrary IPv4 address in textual form.
genIPv4 :: Gen String genIPv4 :: Gen String
genIPv4 = do genIPv4 = do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment