Split Rpc tests from QC
[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 Ganeti.HTools.QC
33 import Test.Ganeti.Confd.Utils
34 import Test.Ganeti.Objects
35 import Test.Ganeti.Rpc
36
37 -- | Our default test options, overring the built-in test-framework
38 -- ones.
39 fast :: TestOptions
40 fast = TestOptions
41        { topt_seed                               = Nothing
42        , topt_maximum_generated_tests            = Just 500
43        , topt_maximum_unsuitable_generated_tests = Just 5000
44        , topt_maximum_test_size                  = Nothing
45        , topt_maximum_test_depth                 = Nothing
46        , topt_timeout                            = Nothing
47        }
48
49 -- | Our slow test options.
50 slow :: TestOptions
51 slow = fast
52        { topt_maximum_generated_tests            = Just 50
53        , topt_maximum_unsuitable_generated_tests = Just 500
54        }
55
56 -- | All our defined tests.
57 allTests :: [(Bool, (String, [Test]))]
58 allTests =
59   [ (True, testUtils)
60   , (True, testPeerMap)
61   , (True, testContainer)
62   , (True, testInstance)
63   , (True, testNode)
64   , (True, testText)
65   , (True, testSimu)
66   , (True, testOpCodes)
67   , (True, testJobs)
68   , (True, testLoader)
69   , (True, testTypes)
70   , (True, testCLI)
71   , (True, testJSON)
72   , (True, testLuxi)
73   , (True, testSsconf)
74   , (True, testQlang)
75   , (True, testRpc)
76   , (True, testConfdUtils)
77   , (True, testObjects)
78   , (False, testCluster)
79   ]
80
81 -- | Slow a test's max tests, if provided as such.
82 makeSlowOrFast :: Bool -> TestOptions -> TestOptions
83 makeSlowOrFast is_fast opts =
84   let template = if is_fast then fast else slow
85       fn_val v = if is_fast then v else v `div` 10
86   in case topt_maximum_generated_tests opts of
87        -- user didn't override the max_tests, so we'll do it here
88        Nothing -> opts `mappend` template
89        -- user did override, so we ignore the template and just directly
90        -- decrease the max_tests, if needed
91        Just max_tests -> opts { topt_maximum_generated_tests =
92                                   Just (fn_val max_tests)
93                               }
94
95 -- | Main function. Note we don't use defaultMain since we want to
96 -- control explicitly our test sizes (and override the default).
97 main :: IO ()
98 main = do
99   ropts <- getArgs >>= interpretArgsOrExit
100   -- note: we do this overriding here since we need some groups to
101   -- have a smaller test count; so in effect we're basically
102   -- overriding t-f's inheritance here, but only for max_tests
103   let (act_fast, act_slow) =
104        case ropt_test_options ropts of
105          Nothing -> (fast, slow)
106          Just topts -> (makeSlowOrFast True topts, makeSlowOrFast False topts)
107       actual_opts is_fast = if is_fast then act_fast else act_slow
108   let tests = map (\(is_fast, (group_name, group_tests)) ->
109                      plusTestOptions (actual_opts is_fast) $
110                      testGroup group_name group_tests) allTests
111   defaultMainWithOpts tests ropts