Commit b3d17f52 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a makeSimpleFilter function



And associated unittests. This will be needed for classic-style
queries.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 5227de56
......@@ -42,6 +42,7 @@ import Test.Ganeti.Objects (genEmptyCluster)
import Ganeti.BasicTypes
import Ganeti.JSON
import Ganeti.Objects
import Ganeti.Query.Filter
import Ganeti.Query.Language
import Ganeti.Query.Query
import Ganeti.Utils (niceSort)
......@@ -159,9 +160,22 @@ prop_node_bad_filter rndname rndint =
"numeric value in non-list field"
]
-- | Tests make simple filter.
prop_makeSimpleFilter :: Property
prop_makeSimpleFilter =
forAll (resize 10 $ listOf1 getName) $ \names ->
forAll getName $ \namefield ->
conjoin [ printTestCase "test expected names" $
makeSimpleFilter namefield names ==?
OrFilter (map (EQFilter namefield . QuotedString) names)
, printTestCase "test empty names" $
makeSimpleFilter namefield [] ==? EmptyFilter
]
testSuite "Query/Filter"
[ 'prop_node_single_filter
, 'prop_node_many_filter
, 'prop_node_regex_filter
, 'prop_node_bad_filter
, 'prop_makeSimpleFilter
]
......@@ -48,6 +48,7 @@ module Ganeti.Query.Filter
( compileFilter
, evaluateFilter
, requestedNames
, makeSimpleFilter
) where
import Control.Applicative
......@@ -185,3 +186,9 @@ requestedNames namefield (EQFilter fld val) =
then Just [val]
else Nothing
requestedNames _ _ = Nothing
-- | Builds a simple filter from a list of names.
makeSimpleFilter :: String -> [String] -> Filter FilterField
makeSimpleFilter _ [] = EmptyFilter
makeSimpleFilter namefield vals =
OrFilter $ map (EQFilter namefield . QuotedString) vals
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