| 1 |
{-# LANGUAGE TemplateHaskell #-} |
| 2 |
{-# OPTIONS_GHC -fno-warn-orphans #-} |
| 3 |
|
| 4 |
{-| Unittests for ganeti-htools. |
| 5 |
|
| 6 |
-} |
| 7 |
|
| 8 |
{- |
| 9 |
|
| 10 |
Copyright (C) 2009, 2010, 2011, 2012 Google Inc. |
| 11 |
All rights reserved. |
| 12 |
|
| 13 |
Redistribution and use in source and binary forms, with or without |
| 14 |
modification, are permitted provided that the following conditions are |
| 15 |
met: |
| 16 |
|
| 17 |
1. Redistributions of source code must retain the above copyright notice, |
| 18 |
this list of conditions and the following disclaimer. |
| 19 |
|
| 20 |
2. Redistributions in binary form must reproduce the above copyright |
| 21 |
notice, this list of conditions and the following disclaimer in the |
| 22 |
documentation and/or other materials provided with the distribution. |
| 23 |
|
| 24 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 25 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 26 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 27 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 28 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 29 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 30 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 31 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 32 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 33 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 |
|
| 36 |
-} |
| 37 |
|
| 38 |
module Test.Ganeti.Daemon (testDaemon) where |
| 39 |
|
| 40 |
import Test.QuickCheck hiding (Result) |
| 41 |
import Test.HUnit |
| 42 |
|
| 43 |
import Test.Ganeti.TestHelper |
| 44 |
import Test.Ganeti.TestCommon |
| 45 |
import Test.Ganeti.Common |
| 46 |
|
| 47 |
import Ganeti.Common |
| 48 |
import Ganeti.Daemon as Daemon |
| 49 |
|
| 50 |
{-# ANN module "HLint: ignore Use camelCase" #-} |
| 51 |
|
| 52 |
-- | Test a few string arguments. |
| 53 |
prop_string_arg :: String -> Property |
| 54 |
prop_string_arg argument = |
| 55 |
let args = [ (argument, oBindAddress, optBindAddress) |
| 56 |
] |
| 57 |
in conjoin $ |
| 58 |
map (checkOpt Just defaultOptions failTest (const (==?)) Just) args |
| 59 |
|
| 60 |
-- | Test a few integer arguments (only one for now). |
| 61 |
prop_numeric_arg :: Int -> Property |
| 62 |
prop_numeric_arg argument = |
| 63 |
checkOpt (Just . show) defaultOptions |
| 64 |
failTest (const (==?)) (Just . fromIntegral) |
| 65 |
(argument, oPort 0, optPort) |
| 66 |
|
| 67 |
-- | Test a few boolean arguments. |
| 68 |
case_bool_arg :: Assertion |
| 69 |
case_bool_arg = |
| 70 |
mapM_ (checkOpt (const Nothing) defaultOptions assertFailure |
| 71 |
assertEqual id) |
| 72 |
[ (False, oNoDaemonize, optDaemonize) |
| 73 |
, (True, oDebug, optDebug) |
| 74 |
, (True, oNoUserChecks, optNoUserChecks) |
| 75 |
] |
| 76 |
|
| 77 |
-- | Tests a few invalid arguments. |
| 78 |
case_wrong_arg :: Assertion |
| 79 |
case_wrong_arg = |
| 80 |
mapM_ (passFailOpt defaultOptions assertFailure (return ())) |
| 81 |
[ (oSyslogUsage, "foo", "yes") |
| 82 |
, (oPort 0, "x", "10") |
| 83 |
] |
| 84 |
|
| 85 |
-- | Test that the option list supports some common options. |
| 86 |
case_stdopts :: Assertion |
| 87 |
case_stdopts = |
| 88 |
checkEarlyExit defaultOptions "prog" [oShowHelp, oShowVer] [] |
| 89 |
|
| 90 |
testSuite "Daemon" |
| 91 |
[ 'prop_string_arg |
| 92 |
, 'prop_numeric_arg |
| 93 |
, 'case_bool_arg |
| 94 |
, 'case_wrong_arg |
| 95 |
, 'case_stdopts |
| 96 |
] |