Revision a9d6f4e0 htest/Test/Ganeti/Query/Query.hs

b/htest/Test/Ganeti/Query/Query.hs
43 43
import Test.Ganeti.Objects (genEmptyCluster)
44 44

  
45 45
import Ganeti.BasicTypes
46
import Ganeti.Query.Group
46 47
import Ganeti.Query.Language
47 48
import Ganeti.Query.Node
48 49
import Ganeti.Query.Query
......
147 148
     (sortBy field_sort . map fst $ Map.elems nodeFieldsMap)
148 149
     (sortBy field_sort fdefs)
149 150

  
151
-- * Same as above, but for group
152

  
153
prop_queryGroup_noUnknown :: Property
154
prop_queryGroup_noUnknown =
155
  forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
156
   forAll (elements (Map.keys groupFieldsMap)) $ \field -> monadicIO $ do
157
   QueryResult fdefs fdata <-
158
     run (query cluster (Query QRGroup [field] EmptyFilter)) >>= resultProp
159
   QueryFieldsResult fdefs' <-
160
     resultProp $ queryFields (QueryFields QRGroup [field])
161
   stop $ printTestCase ("Got unknown fields via query (" ++ show fdefs ++ ")")
162
         (hasUnknownFields fdefs) .&&.
163
          printTestCase ("Got unknown result status via query (" ++
164
                         show fdata ++ ")")
165
           (all (all ((/= RSUnknown) . rentryStatus)) fdata) .&&.
166
          printTestCase ("Got unknown fields via query fields (" ++ show fdefs'
167
                        ++ ")") (hasUnknownFields fdefs')
168

  
169
prop_queryGroup_Unknown :: Property
170
prop_queryGroup_Unknown =
171
  forAll (choose (0, maxNodes) >>= genEmptyCluster) $ \cluster ->
172
  forAll (arbitrary `suchThat` (`notElem` Map.keys groupFieldsMap))
173
    $ \field -> monadicIO $ do
174
  QueryResult fdefs fdata <-
175
    run (query cluster (Query QRGroup [field] EmptyFilter)) >>= resultProp
176
  QueryFieldsResult fdefs' <-
177
    resultProp $ queryFields (QueryFields QRGroup [field])
178
  stop $ printTestCase ("Got known fields via query (" ++ show fdefs ++ ")")
179
         (not $ hasUnknownFields fdefs) .&&.
180
         printTestCase ("Got /= ResultUnknown result status via query (" ++
181
                        show fdata ++ ")")
182
           (all (all ((== RSUnknown) . rentryStatus)) fdata) .&&.
183
         printTestCase ("Got a Just in a result value (" ++
184
                        show fdata ++ ")")
185
           (all (all (isNothing . rentryValue)) fdata) .&&.
186
         printTestCase ("Got known fields via query fields (" ++ show fdefs'
187
                        ++ ")") (not $ hasUnknownFields fdefs')
188

  
189
prop_queryGroup_types :: Property
190
prop_queryGroup_types =
191
  forAll (choose (0, maxNodes)) $ \numnodes ->
192
  forAll (genEmptyCluster numnodes) $ \cfg ->
193
  forAll (elements (Map.keys groupFieldsMap)) $ \field -> monadicIO $ do
194
  QueryResult fdefs fdata <-
195
    run (query cfg (Query QRGroup [field] EmptyFilter)) >>= resultProp
196
  stop $ printTestCase ("Inconsistent result entries (" ++ show fdata ++ ")")
197
         (conjoin $ map (conjoin . zipWith checkResultType fdefs) fdata) .&&.
198
         printTestCase "Wrong field definitions length"
199
           (length fdefs ==? 1) .&&.
200
         printTestCase "Wrong field result rows length"
201
           (all ((== 1) . length) fdata)
202

  
203
case_queryGroup_allfields :: Assertion
204
case_queryGroup_allfields = do
205
   fdefs <- case queryFields (QueryFields QRGroup []) of
206
              Bad msg -> fail $ "Error in query all fields: " ++ msg
207
              Ok (QueryFieldsResult v) -> return v
208
   let field_sort = compare `on` fdefName
209
   assertEqual "Mismatch in all fields list"
210
     (sortBy field_sort . map fst $ Map.elems groupFieldsMap)
211
     (sortBy field_sort fdefs)
212

  
150 213
testSuite "Query/Query"
151 214
  [ 'prop_queryNode_noUnknown
152 215
  , 'prop_queryNode_Unknown
153 216
  , 'prop_queryNode_types
154 217
  , 'case_queryNode_allfields
218
  , 'prop_queryGroup_noUnknown
219
  , 'prop_queryGroup_Unknown
220
  , 'prop_queryGroup_types
221
  , 'case_queryGroup_allfields
155 222
  ]

Also available in: Unified diff