Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -42,6 +42,7 @@ import Test.Ganeti.Objects (genEmptyCluster) ...@@ -42,6 +42,7 @@ import Test.Ganeti.Objects (genEmptyCluster)
import Ganeti.BasicTypes import Ganeti.BasicTypes
import Ganeti.JSON import Ganeti.JSON
import Ganeti.Objects import Ganeti.Objects
import Ganeti.Query.Filter
import Ganeti.Query.Language import Ganeti.Query.Language
import Ganeti.Query.Query import Ganeti.Query.Query
import Ganeti.Utils (niceSort) import Ganeti.Utils (niceSort)
...@@ -159,9 +160,22 @@ prop_node_bad_filter rndname rndint = ...@@ -159,9 +160,22 @@ prop_node_bad_filter rndname rndint =
"numeric value in non-list field" "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" testSuite "Query/Filter"
[ 'prop_node_single_filter [ 'prop_node_single_filter
, 'prop_node_many_filter , 'prop_node_many_filter
, 'prop_node_regex_filter , 'prop_node_regex_filter
, 'prop_node_bad_filter , 'prop_node_bad_filter
, 'prop_makeSimpleFilter
] ]
...@@ -48,6 +48,7 @@ module Ganeti.Query.Filter ...@@ -48,6 +48,7 @@ module Ganeti.Query.Filter
( compileFilter ( compileFilter
, evaluateFilter , evaluateFilter
, requestedNames , requestedNames
, makeSimpleFilter
) where ) where
import Control.Applicative import Control.Applicative
...@@ -185,3 +186,9 @@ requestedNames namefield (EQFilter fld val) = ...@@ -185,3 +186,9 @@ requestedNames namefield (EQFilter fld val) =
then Just [val] then Just [val]
else Nothing else Nothing
requestedNames _ _ = 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment