root / test / hs / Test / Ganeti / Query / Aliases.hs @ 3fd38382
History | View | Annotate | Download (2.6 kB)
1 |
{-# LANGUAGE TemplateHaskell #-} |
---|---|
2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
3 |
|
4 |
{-| Unittests for query aliases. |
5 |
|
6 |
-} |
7 |
|
8 |
{- |
9 |
|
10 |
Copyright (C) 2013 Google Inc. |
11 |
|
12 |
This program is free software; you can redistribute it and/or modify |
13 |
it under the terms of the GNU General Public License as published by |
14 |
the Free Software Foundation; either version 2 of the License, or |
15 |
(at your option) any later version. |
16 |
|
17 |
This program is distributed in the hope that it will be useful, but |
18 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
19 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 |
General Public License for more details. |
21 |
|
22 |
You should have received a copy of the GNU General Public License |
23 |
along with this program; if not, write to the Free Software |
24 |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25 |
02110-1301, USA. |
26 |
|
27 |
-} |
28 |
|
29 |
module Test.Ganeti.Query.Aliases |
30 |
( testQuery_Aliases |
31 |
) where |
32 |
|
33 |
import Data.List |
34 |
|
35 |
import Test.Ganeti.TestHelper |
36 |
import Test.HUnit |
37 |
|
38 |
import Ganeti.Query.Common () |
39 |
import qualified Ganeti.Query.Instance as I |
40 |
import Ganeti.Query.Language |
41 |
import Ganeti.Query.Types |
42 |
|
43 |
{-# ANN module "HLint: ignore Use camelCase" #-} |
44 |
|
45 |
-- | Converts field list to field name list |
46 |
toFieldNameList :: FieldList a b -> [FieldName] |
47 |
toFieldNameList = map (\(x,_,_) -> fdefName x) |
48 |
|
49 |
-- | Converts alias list to alias name list |
50 |
toAliasNameList :: [(FieldName, FieldName)] -> [FieldName] |
51 |
toAliasNameList = map fst |
52 |
|
53 |
-- | Converts alias list to alias target list |
54 |
toAliasTargetList :: [(FieldName, FieldName)] -> [FieldName] |
55 |
toAliasTargetList = map snd |
56 |
|
57 |
-- | Checks for shadowing |
58 |
checkShadowing :: String |
59 |
-> FieldList a b |
60 |
-> [(FieldName, FieldName)] |
61 |
-> Assertion |
62 |
checkShadowing name fields aliases = |
63 |
assertBool (name ++ " aliases do not shadow fields") . |
64 |
null $ toFieldNameList fields `intersect` toAliasNameList aliases |
65 |
|
66 |
-- | Checks for target existence |
67 |
checkTargets :: String |
68 |
-> FieldList a b |
69 |
-> [(FieldName, FieldName)] |
70 |
-> Assertion |
71 |
checkTargets name fields aliases = |
72 |
assertBool (name ++ " alias targets exist") . |
73 |
null $ toAliasTargetList aliases \\ toFieldNameList fields |
74 |
|
75 |
-- | Check that instance aliases do not shadow existing fields |
76 |
case_instanceAliasesNoShadowing :: Assertion |
77 |
case_instanceAliasesNoShadowing = |
78 |
checkShadowing "Instance" I.instanceFields I.instanceAliases |
79 |
|
80 |
-- | Check that instance alias targets exist |
81 |
case_instanceAliasesTargetsExist :: Assertion |
82 |
case_instanceAliasesTargetsExist = |
83 |
checkTargets "Instance" I.instanceFields I.instanceAliases |
84 |
|
85 |
testSuite "Query/Aliases" |
86 |
[ 'case_instanceAliasesNoShadowing, |
87 |
'case_instanceAliasesTargetsExist |
88 |
] |