Add query filter tests
[ganeti-local] / htest / test.hs
1 {-| Unittest runner for ganeti-htools.
2
3 -}
4
5 {-
6
7 Copyright (C) 2009, 2011, 2012 Google Inc.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 02110-1301, USA.
23
24 -}
25
26 module Main(main) where
27
28 import Data.Monoid (mappend)
29 import Test.Framework
30 import System.Environment (getArgs)
31
32 import Test.Ganeti.TestImports ()
33 import Test.Ganeti.BasicTypes
34 import Test.Ganeti.Confd.Utils
35 import Test.Ganeti.HTools.CLI
36 import Test.Ganeti.HTools.Cluster
37 import Test.Ganeti.HTools.Container
38 import Test.Ganeti.HTools.Loader
39 import Test.Ganeti.HTools.Instance
40 import Test.Ganeti.HTools.Node
41 import Test.Ganeti.HTools.PeerMap
42 import Test.Ganeti.HTools.Simu
43 import Test.Ganeti.HTools.Text
44 import Test.Ganeti.HTools.Types
45 import Test.Ganeti.HTools.Utils
46 import Test.Ganeti.Jobs
47 import Test.Ganeti.JSON
48 import Test.Ganeti.Luxi
49 import Test.Ganeti.Objects
50 import Test.Ganeti.OpCodes
51 import Test.Ganeti.Query.Filter
52 import Test.Ganeti.Query.Language
53 import Test.Ganeti.Query.Query
54 import Test.Ganeti.Rpc
55 import Test.Ganeti.Ssconf
56
57 -- | Our default test options, overring the built-in test-framework
58 -- ones.
59 fast :: TestOptions
60 fast = TestOptions
61        { topt_seed                               = Nothing
62        , topt_maximum_generated_tests            = Just 500
63        , topt_maximum_unsuitable_generated_tests = Just 5000
64        , topt_maximum_test_size                  = Nothing
65        , topt_maximum_test_depth                 = Nothing
66        , topt_timeout                            = Nothing
67        }
68
69 -- | Our slow test options.
70 slow :: TestOptions
71 slow = fast
72        { topt_maximum_generated_tests            = Just 50
73        , topt_maximum_unsuitable_generated_tests = Just 500
74        }
75
76 -- | All our defined tests.
77 allTests :: [(Bool, (String, [Test]))]
78 allTests =
79   [ (True, testBasicTypes)
80   , (True, testConfd_Utils)
81   , (True, testHTools_CLI)
82   , (True, testHTools_Container)
83   , (True, testHTools_Instance)
84   , (True, testHTools_Loader)
85   , (True, testHTools_Node)
86   , (True, testHTools_PeerMap)
87   , (True, testHTools_Simu)
88   , (True, testHTools_Text)
89   , (True, testHTools_Types)
90   , (True, testHTools_Utils)
91   , (True, testJSON)
92   , (True, testJobs)
93   , (True, testLuxi)
94   , (True, testObjects)
95   , (True, testOpCodes)
96   , (True, testQuery_Filter)
97   , (True, testQuery_Language)
98   , (True, testQuery_Query)
99   , (True, testRpc)
100   , (True, testSsconf)
101   , (False, testHTools_Cluster)
102   , (False, testSlowObjects)
103   ]
104
105 -- | Slow a test's max tests, if provided as such.
106 makeSlowOrFast :: Bool -> TestOptions -> TestOptions
107 makeSlowOrFast is_fast opts =
108   let template = if is_fast then fast else slow
109       fn_val v = if is_fast then v else v `div` 10
110   in case topt_maximum_generated_tests opts of
111        -- user didn't override the max_tests, so we'll do it here
112        Nothing -> opts `mappend` template
113        -- user did override, so we ignore the template and just directly
114        -- decrease the max_tests, if needed
115        Just max_tests -> opts { topt_maximum_generated_tests =
116                                   Just (fn_val max_tests)
117                               }
118
119 -- | Main function. Note we don't use defaultMain since we want to
120 -- control explicitly our test sizes (and override the default).
121 main :: IO ()
122 main = do
123   ropts <- getArgs >>= interpretArgsOrExit
124   -- note: we do this overriding here since we need some groups to
125   -- have a smaller test count; so in effect we're basically
126   -- overriding t-f's inheritance here, but only for max_tests
127   let (act_fast, act_slow) =
128        case ropt_test_options ropts of
129          Nothing -> (fast, slow)
130          Just topts -> (makeSlowOrFast True topts, makeSlowOrFast False topts)
131       actual_opts is_fast = if is_fast then act_fast else act_slow
132   let tests = map (\(is_fast, (group_name, group_tests)) ->
133                      plusTestOptions (actual_opts is_fast) $
134                      testGroup group_name group_tests) allTests
135   defaultMainWithOpts tests ropts