Commit 5006418e authored by Iustin Pop's avatar Iustin Pop
Browse files

Make QuickCheck generator names more uniform



Due to lack of attention, we have two styles for generators of
arbitrary values: get* and gen* (e.g. getFQDN and genDiskIndices). In
order to make this more obvious that we deal with a function in the
Gen monad, let's rename all get* functions to gen*.

A few other simplifications were done on existing tests, switching to
helpers that were introduced later.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent 9b773665
......@@ -49,7 +49,7 @@ $(genArbitrary ''Confd.ConfdReqQ)
instance Arbitrary Confd.ConfdQuery where
arbitrary = oneof [ pure Confd.EmptyQuery
, Confd.PlainQuery <$> getName
, Confd.PlainQuery <$> genName
, Confd.DictQuery <$> arbitrary
]
......
......@@ -49,7 +49,7 @@ import qualified Ganeti.HTools.Types as Types
-- | Generates a random instance with maximum disk/mem/cpu values.
genInstanceSmallerThan :: Int -> Int -> Int -> Gen Instance.Instance
genInstanceSmallerThan lim_mem lim_dsk lim_cpu = do
name <- getFQDN
name <- genFQDN
mem <- choose (0, lim_mem)
dsk <- choose (0, lim_dsk)
run_st <- arbitrary
......
......@@ -71,7 +71,7 @@ genNode min_multiplier max_multiplier = do
mm * Types.unitDsk,
mm * Types.unitCpu)
Nothing -> (maxMem, maxDsk, maxCpu)
name <- getFQDN
name <- genFQDN
mem_t <- choose (base_mem, top_mem)
mem_f <- choose (base_mem, mem_t)
mem_n <- choose (0, mem_t - mem_f)
......
......@@ -58,25 +58,25 @@ instance Arbitrary Luxi.LuxiOp where
arbitrary = do
lreq <- arbitrary
case lreq of
Luxi.ReqQuery -> Luxi.Query <$> arbitrary <*> getFields <*> genFilter
Luxi.ReqQueryFields -> Luxi.QueryFields <$> arbitrary <*> getFields
Luxi.ReqQueryNodes -> Luxi.QueryNodes <$> listOf getFQDN <*>
getFields <*> arbitrary
Luxi.ReqQuery -> Luxi.Query <$> arbitrary <*> genFields <*> genFilter
Luxi.ReqQueryFields -> Luxi.QueryFields <$> arbitrary <*> genFields
Luxi.ReqQueryNodes -> Luxi.QueryNodes <$> listOf genFQDN <*>
genFields <*> arbitrary
Luxi.ReqQueryGroups -> Luxi.QueryGroups <$> arbitrary <*>
arbitrary <*> arbitrary
Luxi.ReqQueryInstances -> Luxi.QueryInstances <$> listOf getFQDN <*>
getFields <*> arbitrary
Luxi.ReqQueryJobs -> Luxi.QueryJobs <$> arbitrary <*> getFields
Luxi.ReqQueryInstances -> Luxi.QueryInstances <$> listOf genFQDN <*>
genFields <*> arbitrary
Luxi.ReqQueryJobs -> Luxi.QueryJobs <$> arbitrary <*> genFields
Luxi.ReqQueryExports -> Luxi.QueryExports <$>
listOf getFQDN <*> arbitrary
Luxi.ReqQueryConfigValues -> Luxi.QueryConfigValues <$> getFields
listOf genFQDN <*> arbitrary
Luxi.ReqQueryConfigValues -> Luxi.QueryConfigValues <$> genFields
Luxi.ReqQueryClusterInfo -> pure Luxi.QueryClusterInfo
Luxi.ReqQueryTags -> Luxi.QueryTags <$> arbitrary
Luxi.ReqSubmitJob -> Luxi.SubmitJob <$> resize maxOpCodes arbitrary
Luxi.ReqSubmitManyJobs -> Luxi.SubmitManyJobs <$>
resize maxOpCodes arbitrary
Luxi.ReqWaitForJobChange -> Luxi.WaitForJobChange <$> arbitrary <*>
getFields <*> pure J.JSNull <*>
genFields <*> pure J.JSNull <*>
pure J.JSNull <*> arbitrary
Luxi.ReqArchiveJob -> Luxi.ArchiveJob <$> arbitrary
Luxi.ReqAutoArchiveJobs -> Luxi.AutoArchiveJobs <$> arbitrary <*>
......
......@@ -53,10 +53,10 @@ import Ganeti.JSON
$(genArbitrary ''PartialNDParams)
instance Arbitrary Node where
arbitrary = Node <$> getFQDN <*> getFQDN <*> getFQDN
<*> arbitrary <*> arbitrary <*> arbitrary <*> getFQDN
arbitrary = Node <$> genFQDN <*> genFQDN <*> genFQDN
<*> arbitrary <*> arbitrary <*> arbitrary <*> genFQDN
<*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> getFQDN <*> arbitrary
<*> arbitrary <*> arbitrary <*> genFQDN <*> arbitrary
<*> (Set.fromList <$> genTags)
$(genArbitrary ''BlockDriver)
......@@ -65,7 +65,7 @@ $(genArbitrary ''DiskMode)
instance Arbitrary DiskLogicalId where
arbitrary = oneof [ LIDPlain <$> arbitrary <*> arbitrary
, LIDDrbd8 <$> getFQDN <*> getFQDN <*> arbitrary
, LIDDrbd8 <$> genFQDN <*> genFQDN <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
, LIDFile <$> arbitrary <*> arbitrary
, LIDBlockDev <$> arbitrary <*> arbitrary
......@@ -92,7 +92,7 @@ $(genArbitrary ''PartialNic)
instance Arbitrary Instance where
arbitrary =
Instance
<$> getFQDN <*> getFQDN <*> getFQDN -- OS name, but...
<$> genFQDN <*> genFQDN <*> genFQDN -- OS name, but...
<*> arbitrary
-- FIXME: add non-empty hvparams when they're a proper type
<*> pure (GenericContainer Map.empty) <*> arbitrary
......@@ -119,7 +119,7 @@ $(genArbitrary ''PartialIPolicy)
-- | FIXME: This generates completely random data, without normal
-- validation rules.
instance Arbitrary NodeGroup where
arbitrary = NodeGroup <$> getFQDN <*> pure [] <*> arbitrary <*> arbitrary
arbitrary = NodeGroup <$> genFQDN <*> pure [] <*> arbitrary <*> arbitrary
<*> arbitrary <*> pure (GenericContainer Map.empty)
-- ts
<*> arbitrary <*> arbitrary
......
......@@ -56,9 +56,9 @@ import Ganeti.JSON
-- * Arbitrary instances
instance Arbitrary OpCodes.TagObject where
arbitrary = oneof [ OpCodes.TagInstance <$> getFQDN
, OpCodes.TagNode <$> getFQDN
, OpCodes.TagGroup <$> getFQDN
arbitrary = oneof [ OpCodes.TagInstance <$> genFQDN
, OpCodes.TagNode <$> genFQDN
, OpCodes.TagGroup <$> genFQDN
, pure OpCodes.TagCluster
]
......@@ -70,13 +70,13 @@ instance Arbitrary OpCodes.DiskIndex where
arbitrary = choose (0, C.maxDisks - 1) >>= OpCodes.mkDiskIndex
instance Arbitrary INicParams where
arbitrary = INicParams <$> getMaybe genNameNE <*> getMaybe getName <*>
getMaybe genNameNE <*> getMaybe genNameNE
arbitrary = INicParams <$> genMaybe genNameNE <*> genMaybe genName <*>
genMaybe genNameNE <*> genMaybe genNameNE
instance Arbitrary IDiskParams where
arbitrary = IDiskParams <$> arbitrary <*> arbitrary <*>
getMaybe genNameNE <*> getMaybe genNameNE <*>
getMaybe genNameNE
genMaybe genNameNE <*> genMaybe genNameNE <*>
genMaybe genNameNE
instance Arbitrary RecreateDisksInfo where
arbitrary = oneof [ pure RecreateDisksAll
......@@ -108,15 +108,15 @@ instance Arbitrary OpCodes.OpCode where
OpCodes.OpTestDelay <$> arbitrary <*> arbitrary
<*> genNodeNames <*> arbitrary
"OP_INSTANCE_REPLACE_DISKS" ->
OpCodes.OpInstanceReplaceDisks <$> getFQDN <*>
getMaybe genNodeNameNE <*> arbitrary <*> genDiskIndices <*>
getMaybe genNameNE
OpCodes.OpInstanceReplaceDisks <$> genFQDN <*>
genMaybe genNodeNameNE <*> arbitrary <*> genDiskIndices <*>
genMaybe genNameNE
"OP_INSTANCE_FAILOVER" ->
OpCodes.OpInstanceFailover <$> getFQDN <*> arbitrary <*>
getMaybe genNodeNameNE
OpCodes.OpInstanceFailover <$> genFQDN <*> arbitrary <*>
genMaybe genNodeNameNE
"OP_INSTANCE_MIGRATE" ->
OpCodes.OpInstanceMigrate <$> getFQDN <*> arbitrary <*>
arbitrary <*> arbitrary <*> getMaybe genNodeNameNE
OpCodes.OpInstanceMigrate <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary <*> genMaybe genNodeNameNE
"OP_TAGS_GET" ->
OpCodes.OpTagsGet <$> arbitrary <*> arbitrary
"OP_TAGS_SEARCH" ->
......@@ -131,7 +131,7 @@ instance Arbitrary OpCodes.OpCode where
"OP_CLUSTER_VERIFY" ->
OpCodes.OpClusterVerify <$> arbitrary <*> arbitrary <*>
genSet Nothing <*> genSet Nothing <*> arbitrary <*>
getMaybe genNameNE
genMaybe genNameNE
"OP_CLUSTER_VERIFY_CONFIG" ->
OpCodes.OpClusterVerifyConfig <$> arbitrary <*> arbitrary <*>
genSet Nothing <*> arbitrary
......@@ -142,18 +142,17 @@ instance Arbitrary OpCodes.OpCode where
"OP_GROUP_VERIFY_DISKS" ->
OpCodes.OpGroupVerifyDisks <$> genNameNE
"OP_CLUSTER_REPAIR_DISK_SIZES" ->
OpCodes.OpClusterRepairDiskSizes <$>
resize maxNodes (listOf (getFQDN >>= mkNonEmpty))
OpCodes.OpClusterRepairDiskSizes <$> genNodeNamesNE
"OP_CLUSTER_CONFIG_QUERY" ->
OpCodes.OpClusterConfigQuery <$> genFieldsNE
"OP_CLUSTER_RENAME" ->
OpCodes.OpClusterRename <$> (getName >>= mkNonEmpty)
OpCodes.OpClusterRename <$> genNameNE
"OP_CLUSTER_SET_PARAMS" ->
OpCodes.OpClusterSetParams <$> emptyMUD <*> emptyMUD <*>
arbitrary <*> getMaybe (listOf1 arbitrary >>= mkNonEmpty) <*>
getMaybe genEmptyContainer <*> emptyMUD <*>
getMaybe genEmptyContainer <*> getMaybe genEmptyContainer <*>
getMaybe genEmptyContainer <*> getMaybe arbitrary <*>
arbitrary <*> genMaybe (listOf1 arbitrary >>= mkNonEmpty) <*>
genMaybe genEmptyContainer <*> emptyMUD <*>
genMaybe genEmptyContainer <*> genMaybe genEmptyContainer <*>
genMaybe genEmptyContainer <*> genMaybe arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*>
emptyMUD <*> emptyMUD <*> arbitrary <*>
......@@ -171,11 +170,11 @@ instance Arbitrary OpCodes.OpCode where
"OP_OOB_COMMAND" ->
OpCodes.OpOobCommand <$> genNodeNamesNE <*> arbitrary <*>
arbitrary <*> arbitrary <*> (arbitrary `suchThat` (>0))
"OP_NODE_REMOVE" -> OpCodes.OpNodeRemove <$> (getFQDN >>= mkNonEmpty)
"OP_NODE_REMOVE" -> OpCodes.OpNodeRemove <$> genNodeNameNE
"OP_NODE_ADD" ->
OpCodes.OpNodeAdd <$> genNodeNameNE <*> emptyMUD <*> emptyMUD <*>
getMaybe getName <*> getMaybe genNameNE <*> arbitrary <*>
getMaybe genNameNE <*> arbitrary <*> arbitrary <*> emptyMUD
genMaybe genName <*> genMaybe genNameNE <*> arbitrary <*>
genMaybe genNameNE <*> arbitrary <*> arbitrary <*> emptyMUD
"OP_NODE_QUERY" ->
OpCodes.OpNodeQuery <$> genFieldsNE <*> arbitrary <*> genNamesNE
"OP_NODE_QUERYVOLS" ->
......@@ -192,82 +191,82 @@ instance Arbitrary OpCodes.OpCode where
"OP_NODE_SET_PARAMS" ->
OpCodes.OpNodeSetParams <$> genNodeNameNE <*> arbitrary <*>
emptyMUD <*> emptyMUD <*> arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> getMaybe genNameNE <*>
arbitrary <*> arbitrary <*> arbitrary <*> genMaybe genNameNE <*>
emptyMUD
"OP_NODE_POWERCYCLE" ->
OpCodes.OpNodePowercycle <$> genNodeNameNE <*> arbitrary
"OP_NODE_MIGRATE" ->
OpCodes.OpNodeMigrate <$> genNodeNameNE <*> arbitrary <*>
arbitrary <*> getMaybe genNodeNameNE <*> arbitrary <*>
arbitrary <*> getMaybe genNameNE
arbitrary <*> genMaybe genNodeNameNE <*> arbitrary <*>
arbitrary <*> genMaybe genNameNE
"OP_NODE_EVACUATE" ->
OpCodes.OpNodeEvacuate <$> arbitrary <*> genNodeNameNE <*>
getMaybe genNodeNameNE <*> getMaybe genNameNE <*> arbitrary
genMaybe genNodeNameNE <*> genMaybe genNameNE <*> arbitrary
"OP_INSTANCE_CREATE" ->
OpCodes.OpInstanceCreate <$> getFQDN <*> arbitrary <*>
OpCodes.OpInstanceCreate <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> pure emptyJSObject <*>
arbitrary <*> arbitrary <*> arbitrary <*> getMaybe genNameNE <*>
pure emptyJSObject <*> arbitrary <*> getMaybe genNameNE <*>
arbitrary <*> arbitrary <*> arbitrary <*> genMaybe genNameNE <*>
pure emptyJSObject <*> arbitrary <*> genMaybe genNameNE <*>
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*>
arbitrary <*> arbitrary <*> pure emptyJSObject <*>
getMaybe genNameNE <*>
getMaybe genNodeNameNE <*> getMaybe genNodeNameNE <*>
getMaybe (pure []) <*> getMaybe genNodeNameNE <*>
arbitrary <*> getMaybe genNodeNameNE <*>
getMaybe genNodeNameNE <*> getMaybe genNameNE <*>
genMaybe genNameNE <*>
genMaybe genNodeNameNE <*> genMaybe genNodeNameNE <*>
genMaybe (pure []) <*> genMaybe genNodeNameNE <*>
arbitrary <*> genMaybe genNodeNameNE <*>
genMaybe genNodeNameNE <*> genMaybe genNameNE <*>
arbitrary <*> (genTags >>= mapM mkNonEmpty)
"OP_INSTANCE_MULTI_ALLOC" ->
OpCodes.OpInstanceMultiAlloc <$> getMaybe genNameNE <*> pure []
OpCodes.OpInstanceMultiAlloc <$> genMaybe genNameNE <*> pure []
"OP_INSTANCE_REINSTALL" ->
OpCodes.OpInstanceReinstall <$> getFQDN <*> arbitrary <*>
getMaybe genNameNE <*> getMaybe (pure emptyJSObject)
OpCodes.OpInstanceReinstall <$> genFQDN <*> arbitrary <*>
genMaybe genNameNE <*> genMaybe (pure emptyJSObject)
"OP_INSTANCE_REMOVE" ->
OpCodes.OpInstanceRemove <$> getFQDN <*> arbitrary <*> arbitrary
OpCodes.OpInstanceRemove <$> genFQDN <*> arbitrary <*> arbitrary
"OP_INSTANCE_RENAME" ->
OpCodes.OpInstanceRename <$> getFQDN <*> genNodeNameNE <*>
OpCodes.OpInstanceRename <$> genFQDN <*> genNodeNameNE <*>
arbitrary <*> arbitrary
"OP_INSTANCE_STARTUP" ->
OpCodes.OpInstanceStartup <$> getFQDN <*> arbitrary <*> arbitrary <*>
OpCodes.OpInstanceStartup <$> genFQDN <*> arbitrary <*> arbitrary <*>
pure emptyJSObject <*> pure emptyJSObject <*>
arbitrary <*> arbitrary
"OP_INSTANCE_SHUTDOWN" ->
OpCodes.OpInstanceShutdown <$> getFQDN <*> arbitrary <*>
OpCodes.OpInstanceShutdown <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary
"OP_INSTANCE_REBOOT" ->
OpCodes.OpInstanceReboot <$> getFQDN <*> arbitrary <*>
OpCodes.OpInstanceReboot <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary
"OP_INSTANCE_MOVE" ->
OpCodes.OpInstanceMove <$> getFQDN <*> arbitrary <*> arbitrary <*>
OpCodes.OpInstanceMove <$> genFQDN <*> arbitrary <*> arbitrary <*>
genNodeNameNE <*> arbitrary
"OP_INSTANCE_CONSOLE" -> OpCodes.OpInstanceConsole <$> getFQDN
"OP_INSTANCE_CONSOLE" -> OpCodes.OpInstanceConsole <$> genFQDN
"OP_INSTANCE_ACTIVATE_DISKS" ->
OpCodes.OpInstanceActivateDisks <$> getFQDN <*>
OpCodes.OpInstanceActivateDisks <$> genFQDN <*>
arbitrary <*> arbitrary
"OP_INSTANCE_DEACTIVATE_DISKS" ->
OpCodes.OpInstanceDeactivateDisks <$> getFQDN <*> arbitrary
OpCodes.OpInstanceDeactivateDisks <$> genFQDN <*> arbitrary
"OP_INSTANCE_RECREATE_DISKS" ->
OpCodes.OpInstanceRecreateDisks <$> getFQDN <*> arbitrary <*>
genNodeNamesNE <*> getMaybe genNameNE
OpCodes.OpInstanceRecreateDisks <$> genFQDN <*> arbitrary <*>
genNodeNamesNE <*> genMaybe genNameNE
"OP_INSTANCE_QUERY" ->
OpCodes.OpInstanceQuery <$> genFieldsNE <*> genNamesNE <*> arbitrary
"OP_INSTANCE_QUERY_DATA" ->
OpCodes.OpInstanceQueryData <$> arbitrary <*>
genNodeNamesNE <*> arbitrary
"OP_INSTANCE_SET_PARAMS" ->
OpCodes.OpInstanceSetParams <$> getFQDN <*> arbitrary <*>
OpCodes.OpInstanceSetParams <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*>
pure emptyJSObject <*> arbitrary <*> pure emptyJSObject <*>
arbitrary <*> getMaybe genNodeNameNE <*> getMaybe genNameNE <*>
arbitrary <*> genMaybe genNodeNameNE <*> genMaybe genNameNE <*>
pure emptyJSObject <*> arbitrary <*> arbitrary <*> arbitrary
"OP_INSTANCE_GROW_DISK" ->
OpCodes.OpInstanceGrowDisk <$> getFQDN <*> arbitrary <*>
OpCodes.OpInstanceGrowDisk <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary
"OP_INSTANCE_CHANGE_GROUP" ->
OpCodes.OpInstanceChangeGroup <$> getFQDN <*> arbitrary <*>
getMaybe genNameNE <*> getMaybe (resize maxNodes (listOf genNameNE))
OpCodes.OpInstanceChangeGroup <$> genFQDN <*> arbitrary <*>
genMaybe genNameNE <*> genMaybe (resize maxNodes (listOf genNameNE))
"OP_GROUP_ADD" ->
OpCodes.OpGroupAdd <$> genNameNE <*> arbitrary <*>
emptyMUD <*> getMaybe genEmptyContainer <*>
emptyMUD <*> genMaybe genEmptyContainer <*>
emptyMUD <*> emptyMUD <*> emptyMUD
"OP_GROUP_ASSIGN_NODES" ->
OpCodes.OpGroupAssignNodes <$> genNameNE <*> arbitrary <*>
......@@ -276,7 +275,7 @@ instance Arbitrary OpCodes.OpCode where
OpCodes.OpGroupQuery <$> genFieldsNE <*> genNamesNE
"OP_GROUP_SET_PARAMS" ->
OpCodes.OpGroupSetParams <$> genNameNE <*> arbitrary <*>
emptyMUD <*> getMaybe genEmptyContainer <*>
emptyMUD <*> genMaybe genEmptyContainer <*>
emptyMUD <*> emptyMUD <*> emptyMUD
"OP_GROUP_REMOVE" ->
OpCodes.OpGroupRemove <$> genNameNE
......@@ -284,45 +283,45 @@ instance Arbitrary OpCodes.OpCode where
OpCodes.OpGroupRename <$> genNameNE <*> genNameNE
"OP_GROUP_EVACUATE" ->
OpCodes.OpGroupEvacuate <$> genNameNE <*> arbitrary <*>
getMaybe genNameNE <*> getMaybe genNamesNE
genMaybe genNameNE <*> genMaybe genNamesNE
"OP_OS_DIAGNOSE" ->
OpCodes.OpOsDiagnose <$> genFieldsNE <*> genNamesNE
"OP_BACKUP_QUERY" ->
OpCodes.OpBackupQuery <$> arbitrary <*> genNodeNamesNE
"OP_BACKUP_PREPARE" ->
OpCodes.OpBackupPrepare <$> getFQDN <*> arbitrary
OpCodes.OpBackupPrepare <$> genFQDN <*> arbitrary
"OP_BACKUP_EXPORT" ->
OpCodes.OpBackupExport <$> getFQDN <*> arbitrary <*>
OpCodes.OpBackupExport <$> genFQDN <*> arbitrary <*>
arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*>
getMaybe (pure []) <*> getMaybe genNameNE
genMaybe (pure []) <*> genMaybe genNameNE
"OP_BACKUP_REMOVE" ->
OpCodes.OpBackupRemove <$> getFQDN
OpCodes.OpBackupRemove <$> genFQDN
"OP_TEST_ALLOCATOR" ->
OpCodes.OpTestAllocator <$> arbitrary <*> arbitrary <*>
genNameNE <*> pure [] <*> pure [] <*>
arbitrary <*> getMaybe genNameNE <*>
arbitrary <*> genMaybe genNameNE <*>
(genTags >>= mapM mkNonEmpty) <*>
arbitrary <*> arbitrary <*> getMaybe genNameNE <*>
arbitrary <*> getMaybe genNodeNamesNE <*> arbitrary <*>
getMaybe genNamesNE <*> arbitrary <*> arbitrary
arbitrary <*> arbitrary <*> genMaybe genNameNE <*>
arbitrary <*> genMaybe genNodeNamesNE <*> arbitrary <*>
genMaybe genNamesNE <*> arbitrary <*> arbitrary
"OP_TEST_JQUEUE" ->
OpCodes.OpTestJqueue <$> arbitrary <*> arbitrary <*>
resize 20 (listOf getFQDN) <*> arbitrary
resize 20 (listOf genFQDN) <*> arbitrary
"OP_TEST_DUMMY" ->
OpCodes.OpTestDummy <$> pure J.JSNull <*> pure J.JSNull <*>
pure J.JSNull <*> pure J.JSNull
"OP_NETWORK_ADD" ->
OpCodes.OpNetworkAdd <$> genNameNE <*> arbitrary <*> genIp4Net <*>
getMaybe genIp4Addr <*> pure Nothing <*> pure Nothing <*>
getMaybe genMacPrefix <*> getMaybe (listOf genIp4Addr) <*>
genMaybe genIp4Addr <*> pure Nothing <*> pure Nothing <*>
genMaybe genMacPrefix <*> genMaybe (listOf genIp4Addr) <*>
(genTags >>= mapM mkNonEmpty)
"OP_NETWORK_REMOVE" ->
OpCodes.OpNetworkRemove <$> genNameNE <*> arbitrary
"OP_NETWORK_SET_PARAMS" ->
OpCodes.OpNetworkSetParams <$> genNameNE <*> arbitrary <*>
getMaybe genIp4Addr <*> pure Nothing <*> pure Nothing <*>
getMaybe genMacPrefix <*> getMaybe (listOf genIp4Addr) <*>
getMaybe (listOf genIp4Addr)
genMaybe genIp4Addr <*> pure Nothing <*> pure Nothing <*>
genMaybe genMacPrefix <*> genMaybe (listOf genIp4Addr) <*>
genMaybe (listOf genIp4Addr)
"OP_NETWORK_CONNECT" ->
OpCodes.OpNetworkConnect <$> genNameNE <*> genNameNE <*>
arbitrary <*> genNameNE <*> arbitrary
......@@ -343,7 +342,7 @@ emptyJSObject = J.toJSObject []
-- | Empty maybe unchecked dictionary.
emptyMUD :: Gen (Maybe (J.JSObject J.JSValue))
emptyMUD = getMaybe $ pure emptyJSObject
emptyMUD = genMaybe $ pure emptyJSObject
-- | Generates an empty container.
genEmptyContainer :: (Ord a) => Gen (GenericContainer a b)
......@@ -357,7 +356,7 @@ genDiskIndices = do
-- | Generates a list of node names.
genNodeNames :: Gen [String]
genNodeNames = resize maxNodes (listOf getFQDN)
genNodeNames = resize maxNodes (listOf genFQDN)
-- | Generates a list of node names in non-empty string type.
genNodeNamesNE :: Gen [NonEmptyString]
......@@ -365,11 +364,11 @@ genNodeNamesNE = genNodeNames >>= mapM mkNonEmpty
-- | Gets a node name in non-empty type.
genNodeNameNE :: Gen NonEmptyString
genNodeNameNE = getFQDN >>= mkNonEmpty
genNodeNameNE = genFQDN >>= mkNonEmpty
-- | Gets a name (non-fqdn) in non-empty type.
genNameNE :: Gen NonEmptyString
genNameNE = getName >>= mkNonEmpty
genNameNE = genName >>= mkNonEmpty
-- | Gets a list of names (non-fqdn) in non-empty type.
genNamesNE :: Gen [NonEmptyString]
......@@ -377,7 +376,7 @@ genNamesNE = resize maxNodes (listOf genNameNE)
-- | Returns a list of non-empty fields.
genFieldsNE :: Gen [NonEmptyString]
genFieldsNE = getFields >>= mapM mkNonEmpty
genFieldsNE = genFields >>= mapM mkNonEmpty
-- | Generate an arbitrary IPv4 address in textual form.
genIp4Addr :: Gen NonEmptyString
......
......@@ -180,8 +180,8 @@ prop_node_bad_filter rndname rndint =
-- | Tests make simple filter.
prop_makeSimpleFilter :: Property
prop_makeSimpleFilter =
forAll (resize 10 $ listOf1 getName) $ \names ->
forAll getName $ \namefield ->
forAll (resize 10 $ listOf1 genName) $ \names ->
forAll genName $ \namefield ->
conjoin [ printTestCase "test expected names" $
makeSimpleFilter namefield names ==?
OrFilter (map (EQFilter namefield . QuotedString) names)
......
......@@ -53,16 +53,16 @@ genFilter = choose (0, 10) >>= genFilter'
genFilter' :: Int -> Gen (Filter FilterField)
genFilter' 0 =
oneof [ pure EmptyFilter
, TrueFilter <$> getName
, EQFilter <$> getName <*> value
, LTFilter <$> getName <*> value
, GTFilter <$> getName <*> value
, LEFilter <$> getName <*> value
, GEFilter <$> getName <*> value
, RegexpFilter <$> getName <*> arbitrary
, ContainsFilter <$> getName <*> value
, TrueFilter <$> genName
, EQFilter <$> genName <*> value
, LTFilter <$> genName <*> value
, GTFilter <$> genName <*> value
, LEFilter <$> genName <*> value
, GEFilter <$> genName <*> value
, RegexpFilter <$> genName <*> arbitrary
, ContainsFilter <$> genName <*> value
]
where value = oneof [ QuotedString <$> getName
where value = oneof [ QuotedString <$> genName
, NumericValue <$> arbitrary
]
genFilter' n =
......@@ -81,7 +81,7 @@ $(genArbitrary ''QueryTypeLuxi)
$(genArbitrary ''ItemType)
instance Arbitrary FilterRegex where
arbitrary = getName >>= mkRegex -- a name should be a good regex
arbitrary = genName >>= mkRegex -- a name should be a good regex
$(genArbitrary ''ResultStatus)
......
......@@ -235,7 +235,7 @@ case_queryGroup_allfields = do
-- | Tests that requested names checking behaves as expected.
prop_getRequestedNames :: Property
prop_getRequestedNames =
forAll getName $ \node1 ->
forAll genName $ \node1 ->
let chk = getRequestedNames . Query (ItemTypeOpCode QRNode) []
q_node1 = QuotedString node1
eq_name = EQFilter "name"
......
......@@ -132,22 +132,22 @@ instance Show DNSChar where
show = show . dnsGetChar
-- | Generates a single name component.
getName :: Gen String
getName = do
genName :: Gen String
genName = do
n <- choose (1, 64)
dn <- vector n
return (map dnsGetChar dn)
-- | Generates an entire FQDN.
getFQDN :: Gen String
getFQDN = do
genFQDN :: Gen String
genFQDN = do
ncomps <- choose (1, 4)
names <- vectorOf ncomps getName
names <- vectorOf ncomps genName
return $ intercalate "." names
-- | Combinator that generates a 'Maybe' using a sub-combinator.
getMaybe :: Gen a -> Gen (Maybe a)
getMaybe subgen = oneof [ pure Nothing, liftM Just subgen ]
genMaybe :: Gen a -> Gen (Maybe a)
genMaybe subgen = oneof [ pure Nothing, liftM Just subgen ]
-- | Defines a tag type.
newtype TagChar = TagChar { tagGetChar :: Char }
......@@ -181,10 +181,10 @@ genTags = do
-- | Generates a fields list. This uses the same character set as a
-- DNS name (just for simplicity).
getFields :: Gen [String]
getFields = do
genFields :: Gen [String]
genFields = do
n <- choose (1, 32)
vectorOf n getName
vectorOf n genName
-- | Generates a list of a given size with non-duplicate elements.
genUniquesList :: (Eq a, Arbitrary a) => Int -> Gen [a]
......
......@@ -161,7 +161,7 @@ case_niceSort_static = do
-- itself, etc.).
prop_niceSort_single :: Property
prop_niceSort_single =
forAll getName $ \name ->
forAll genName $ \name ->
conjoin
[ printTestCase "single string" $ [name] ==? niceSort [name]
, printTestCase "single plus empty" $ ["", name] ==? niceSort [name, ""]
......
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