| 1 |
{-| Unittests for 'Ganeti.JQueue.Objects'. |
| 2 |
|
| 3 |
-} |
| 4 |
|
| 5 |
{- |
| 6 |
|
| 7 |
Copyright (C) 2012, 2013 Google Inc. |
| 8 |
All rights reserved. |
| 9 |
|
| 10 |
Redistribution and use in source and binary forms, with or without |
| 11 |
modification, are permitted provided that the following conditions are |
| 12 |
met: |
| 13 |
|
| 14 |
1. Redistributions of source code must retain the above copyright notice, |
| 15 |
this list of conditions and the following disclaimer. |
| 16 |
|
| 17 |
2. Redistributions in binary form must reproduce the above copyright |
| 18 |
notice, this list of conditions and the following disclaimer in the |
| 19 |
documentation and/or other materials provided with the distribution. |
| 20 |
|
| 21 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 22 |
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 23 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 24 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
| 25 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 26 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 28 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 |
|
| 33 |
-} |
| 34 |
|
| 35 |
module Test.Ganeti.JQueue.Objects |
| 36 |
( justNoTs |
| 37 |
, genQueuedOpCode |
| 38 |
, emptyJob |
| 39 |
, genJobId |
| 40 |
) where |
| 41 |
|
| 42 |
import Control.Monad.Fail (MonadFail) |
| 43 |
import Test.QuickCheck as QuickCheck |
| 44 |
import Text.JSON |
| 45 |
|
| 46 |
import Test.Ganeti.Types () |
| 47 |
import Test.Ganeti.OpCodes () |
| 48 |
|
| 49 |
import qualified Ganeti.Constants as C |
| 50 |
import Ganeti.JQueue |
| 51 |
import Ganeti.Types as Types |
| 52 |
|
| 53 |
-- | noTimestamp in Just form. |
| 54 |
justNoTs :: Maybe Timestamp |
| 55 |
justNoTs = Just noTimestamp |
| 56 |
|
| 57 |
-- | Generates a simple queued opcode. |
| 58 |
genQueuedOpCode :: Gen QueuedOpCode |
| 59 |
genQueuedOpCode = |
| 60 |
QueuedOpCode <$> (ValidOpCode <$> arbitrary) <*> |
| 61 |
arbitrary <*> pure JSNull <*> pure [] <*> |
| 62 |
choose (C.opPrioLowest, C.opPrioHighest) <*> |
| 63 |
pure justNoTs <*> pure justNoTs <*> pure justNoTs |
| 64 |
|
| 65 |
-- | Generates an static, empty job. |
| 66 |
emptyJob :: (MonadFail m) => m QueuedJob |
| 67 |
emptyJob = do |
| 68 |
jid0 <- makeJobId 0 |
| 69 |
return $ QueuedJob jid0 [] justNoTs justNoTs justNoTs Nothing Nothing |
| 70 |
|
| 71 |
-- | Generates a job ID. |
| 72 |
genJobId :: Gen JobId |
| 73 |
genJobId = do |
| 74 |
p <- arbitrary::Gen (Types.NonNegative Int) |
| 75 |
makeJobId $ fromNonNegative p |