Revision b3d17f52

b/htest/Test/Ganeti/Query/Filter.hs
42 42
import Ganeti.BasicTypes
43 43
import Ganeti.JSON
44 44
import Ganeti.Objects
45
import Ganeti.Query.Filter
45 46
import Ganeti.Query.Language
46 47
import Ganeti.Query.Query
47 48
import Ganeti.Utils (niceSort)
......
159 160
             "numeric value in non-list field"
160 161
           ]
161 162

  
163
-- | Tests make simple filter.
164
prop_makeSimpleFilter :: Property
165
prop_makeSimpleFilter =
166
  forAll (resize 10 $ listOf1 getName) $ \names ->
167
  forAll getName $ \namefield ->
168
  conjoin [ printTestCase "test expected names" $
169
              makeSimpleFilter namefield names ==?
170
              OrFilter (map (EQFilter namefield . QuotedString) names)
171
          , printTestCase "test empty names" $
172
              makeSimpleFilter namefield [] ==? EmptyFilter
173
          ]
174

  
162 175
testSuite "Query/Filter"
163 176
  [ 'prop_node_single_filter
164 177
  , 'prop_node_many_filter
165 178
  , 'prop_node_regex_filter
166 179
  , 'prop_node_bad_filter
180
  , 'prop_makeSimpleFilter
167 181
  ]
b/htools/Ganeti/Query/Filter.hs
48 48
  ( compileFilter
49 49
  , evaluateFilter
50 50
  , requestedNames
51
  , makeSimpleFilter
51 52
  ) where
52 53

  
53 54
import Control.Applicative
......
185 186
    then Just [val]
186 187
    else Nothing
187 188
requestedNames _ _ = Nothing
189

  
190
-- | Builds a simple filter from a list of names.
191
makeSimpleFilter :: String -> [String] -> Filter FilterField
192
makeSimpleFilter _ [] = EmptyFilter
193
makeSimpleFilter namefield vals =
194
  OrFilter $ map (EQFilter namefield . QuotedString) vals

Also available in: Unified diff